Difference between revisions of "BMD Sensors Guide"
(43 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
== Gas Sensor == | == Gas Sensor == | ||
EG1004 provides an Adafruit Gas Sensor. When a gas is detected, the analog voltage will increase in proportion to the gas. This sensor is sensitive to multiple gases, but cannot tell you which gas it detects. | |||
[[Image:bmdsg1.jpeg|600px|thumb|center]] | |||
=== Wiring === | === Wiring === | ||
Note: the LED used in the circuit is not required, but could be helpful in regard to testing. | Note: the LED used in the circuit is not required, but could be helpful in regard to testing. | ||
VCC: 5V | [[Image:bmdsg2.png|600px|thumb|center]] | ||
Signal: A0 (or any analog pin) | |||
GND: ground | === Pins === | ||
* VCC: 5V | |||
* Signal: A0 (or any analog pin) | |||
* GND: ground | |||
=== Code === | === Code === | ||
As the Adafruit Gas Sensor is an analog sensor, analogRead() will be used to get the analog voltage reading from the sensor. | As the Adafruit Gas Sensor is an analog sensor, analogRead() will be used to get the analog voltage reading from the sensor. | ||
To see the value read by the sensor, use a print statement in the loop area of your code. Make sure to initialize the serial monitor by including Serial.begin(9600) in the setup area of your code. | [[Image:bmdsg3.png|600px|thumb|center]] | ||
To see the value read by the sensor, use a print statement in the loop area of your code. Make sure to initialize the serial monitor by including Serial.begin(9600) in the setup area of your code. | |||
[[Image:bmdsg4.png|600px|thumb|center]] | |||
== UV Sensor (GUVA-S12SD) == | == UV Sensor (GUVA-S12SD) == | ||
EG1004 provides a GUVA-S12SD UV Light Sensor Breakout. This sensor uses an UV photodiode to provide an analog voltage output that can then be converted to UV Index. The UV Index scale is published by the EPA, and is used to give guidance on sun exposure. Figure 1 shows the UV index scale, and Figure 2 shows the correlation between voltage, analog value, and UV Index. | |||
Figure 1: Source | [[Image:bmdsg5.png|600px|thumb|center]] | ||
[[Image:bmdsg6.1.png|600px|thumb|center|Figure 1: Source]] | |||
[[Image:bmdsg7.png|600px|thumb|center|Figure 2: Source]] | |||
Spectral Detection Range: 240nm to 370nm | Spectral Detection Range: 240nm to 370nm | ||
Power Supply: 2.7V to 5.5V | Power Supply: 2.7V to 5.5V | ||
Line 30: | Line 40: | ||
=== Wiring === | === Wiring === | ||
Note: the sensor can be connected to either the 5V or 3.3V power supply. | Note: the sensor can be connected to either the 5V or 3.3V power supply. | ||
[[Image:bmdsg8.png|600px|thumb|center]] | |||
=== Pins === | === Pins === | ||
+: 5V (or 3.3V) | * +: 5V (or 3.3V) | ||
OUT: A0 (or other analog pin) | * OUT: A0 (or other analog pin) | ||
-: Ground | * -: Ground | ||
=== Code === | === Code === | ||
As the GUVA-S12SD is an analog sensor, analogRead() will be used to get the voltage reading from the sensor. | As the GUVA-S12SD is an analog sensor, analogRead() will be used to get the voltage reading from the sensor. | ||
[[Image:bmdsg9.png|600px|thumb|center]] | |||
Line 43: | Line 56: | ||
* 3.3V formula → Voltage(V) = reading * (3.3/1024.0) | * 3.3V formula → Voltage(V) = reading * (3.3/1024.0) | ||
* 5V formula → Voltage(V) = reading * (5.0/1024.0) | * 5V formula → Voltage(V) = reading * (5.0/1024.0) | ||
Below is an example of coding this formula for a 5V power supply. Note that the numbers are in decimal form, this is required in order to get correct voltage values. | Below is an example of coding this formula for a 5V power supply. Note that the numbers are in <b>decimal form</b>, this is required in order to get correct voltage values. | ||
[[Image:bmdsg10.png|600px|thumb|center]] | |||
Lastly, this voltage value can be converted to an approximate UV Index using the following formula: | |||
<math>UV Index = Voltage(V)/0.1</math> | |||
UV | For example, a voltage reading of 0.5V indicates a UV index of about 5. | ||
== Temperature Sensor (TMP36) == | |||
EG1004 provides an Analog TMP36 temperature sensor. These sensors use the change in voltage to produce an analog signal that is proportional to temperature. TMP36s have a temperature range between -40oC and 150oF. Power supply: 2.7V to 5.5V | |||
[[Image:bmdsg12.png|600px|thumb|center]] | |||
=== Wiring === | === Wiring === | ||
Note: the sensor can be connected to either the 5V or 3.3V power pins. | Note: the sensor can be connected to either the 5V or 3.3V power pins. | ||
[[Image:bmdsg13.png|600px|thumb|center]] | |||
=== Pins === | === Pins === | ||
VCC: 3.3V or 5V | * VCC: 3.3V or 5V | ||
Signal: A0 (or any analog pin) | * Signal: A0 (or any analog pin) | ||
GND: ground | * GND: ground | ||
=== Code === | === Code === | ||
As the TMP36 is an analog sensor, analogRead() will be used to get the voltage reading from the sensor. | As the TMP36 is an analog sensor, analogRead() will be used to get the voltage reading from the sensor. | ||
[[Image:bmdsg9.png|600px|thumb|center]] | |||
This initial reading must then be converted to Voltage. The formula will differ depending on if you are using the 3.3V or 5V power supply. | This initial reading must then be converted to Voltage. The formula will differ depending on if you are using the 3.3V or 5V power supply. | ||
Line 75: | Line 92: | ||
Below is an example of coding this formula for a 5V power supply. Note that the numbers are in decimal form, this is required in order to get correct temperature values. | Below is an example of coding this formula for a 5V power supply. Note that the numbers are in decimal form, this is required in order to get correct temperature values. | ||
[[Image:bmdsg15.png|600px|thumb|center]] | |||
Lastly, this voltage value needs to be converted to Celsius using the following formula: | Lastly, this voltage value needs to be converted to Celsius using the following formula: | ||
Line 82: | Line 99: | ||
Below is an example of coding this formula. Once again, note the use of the decimal format for the numbers. | Below is an example of coding this formula. Once again, note the use of the decimal format for the numbers. | ||
[[Image:bmdsg16.png|600px|thumb|center]] | |||
== Pulse Sensor == | == Pulse Sensor == | ||
EG1004 provides an ANMBEST Pulse Sensor. This is an optical heart rate sensor (PPG) designed for Arduino. The sensor uses an ambient light sensor to watch for a change in reflected light that occurs when blood pumps through tissue. By setting a standard threshold value, an Arduino can watch the analog signal from the sensor. | |||
[[Image:bmdsg17.png|600px|thumb|center]] | |||
[[Image:bmdsg18.png|600px|thumb|center]] | |||
When the signal passes the threshold, this means a heartbeat has been detected. Once the signal drops below the threshold, the Arduino will wait for the signal to pass the threshold again, indicating another heartbeat. | When the signal passes the threshold, this means a heartbeat has been detected. Once the signal drops below the threshold, the Arduino will wait for the signal to pass the threshold again, indicating another heartbeat. | ||
Line 93: | Line 114: | ||
=== Wiring === | === Wiring === | ||
[[Image:bmdsg19.png|600px|thumb|center]] | |||
=== Pins === | === Pins === | ||
GND (black wire): Ground | * GND (black wire): Ground | ||
VCC (red wire): 5V | * VCC (red wire): 5V | ||
Signal (purple/pink wire): A0 (or other analog pin) | * Signal (purple/pink wire): A0 (or other analog pin) | ||
=== Code === | === Code === | ||
==== Installing the Library ==== | ==== Installing the Library ==== | ||
The PulseSensorPlayground Library must be installed to the Arduino IDE in order to use the sensor. To download the library: | The PulseSensorPlayground Library must be installed to the Arduino IDE in order to use the sensor. To download the library: | ||
Line 109: | Line 133: | ||
==== Including the Library ==== | ==== Including the Library ==== | ||
The PulseSensor Playground library provides all the functions/methods needed to interface with the sensor. In order to use these functions, the library itself must be included at the very beginning of the Arduino file. This can be done using the following code: | The PulseSensor Playground library provides all the functions/methods needed to interface with the sensor. In order to use these functions, the library itself must be included at the very beginning of the Arduino file. This can be done using the following code: | ||
[[Image:bmdsg20.png|600px|thumb|center]] | |||
==== Using the Library ==== | ==== Using the Library ==== | ||
In order to use the library, a PulseSensor Playground object must be created. The following code creates an object with the name pulseSensor. | In order to use the library, a PulseSensor Playground object must be created. The following code creates an object with the name pulseSensor. | ||
[[Image:bmdsg21.png|600px|thumb|center]] | |||
Next, the sensor object must be configured and initialized. This should be done in the setup() function. In the following code, PulseWire corresponds to the analog pin the sensor is connected to and Threshold corresponds to an integer value used for detecting the heartbeat (a good default threshold value is 550). | Next, the sensor object must be configured and initialized. This should be done in the setup() function. In the following code, PulseWire corresponds to the analog pin the sensor is connected to and Threshold corresponds to an integer value used for detecting the heartbeat (a good default threshold value is 550). | ||
[[Image:bmdsg22.png|600px|thumb|center]] | |||
Now that the sensor object has been started, data can now be obtained. The method <i>getBeatsPerMinute()</i> will return the BPM value read by the sensor. | Now that the sensor object has been started, data can now be obtained. The method <i>getBeatsPerMinute()</i> will return the BPM value read by the sensor. | ||
[[Image:bmdsg23.png|600px|thumb|center]] | |||
Another useful method is <i>sawStartOfBeat()</i>. This will return a boolean value depending on whether the sensor detected a new heartbeat. In the following example, <i>sawStartOfBeat()</i> is used to print out a message followed by the current BPM every time the sensor registers a heartbeat. | Another useful method is <i>sawStartOfBeat()</i>. This will return a boolean value depending on whether the sensor detected a new heartbeat. In the following example, <i>sawStartOfBeat()</i> is used to print out a message followed by the current BPM every time the sensor registers a heartbeat. | ||
[[Image:bmdsg24.png|600px|thumb|center]] | |||
The PulseSensor Playground Library also comes with many example codes and tutorials. These can be found on the [https://pulsesensor.com/pages/installing-our-playground-for-pulsesensor-arduino Pulse Sensor Website]. | The PulseSensor Playground Library also comes with many example codes and tutorials. These can be found on the [https://pulsesensor.com/pages/installing-our-playground-for-pulsesensor-arduino Pulse Sensor Website]. | ||
== Real Time Clock (RTC) Module == | == Real Time Clock (RTC) Module == | ||
EG1004 provides a DS3231 Real Time Clock Module. As an Arduino does not keep time, RTC modules use separate batteries to keep consistent time-keeping functions | |||
[[Image:bmdsg25.png|600px|thumb|center]] | |||
=== Wiring === | === Wiring === | ||
Note: In order to keep time without being consistently connected to power, you must install a coin battery into the module. They do not come included with the RTC module, but | Note: In order to keep time without being consistently connected to power, you must install a coin battery into the module. They do not come included with the RTC module, but EG1004 does provide CR2032 coin batteries. | ||
[[Image:bmdsg26.png|600px|thumb|center]] | |||
=== Pins === | === Pins === | ||
SCL: A5 (or SCL pin) | * SCL: A5 (or SCL pin) | ||
SDA: A4 (or SDA pin) | * SDA: A4 (or SDA pin) | ||
VCC: 5V | * VCC: 5V | ||
GND: Ground | * GND: Ground | ||
=== Code === | === Code === | ||
==== Installing the Library ==== | ==== Installing the Library ==== | ||
The library | The library EG1004 recommends the Adafruit’s RTClib library to interface with an RTC module. The library must be installed to the Arduino IDE in order to use the module. To download the library: | ||
Open the Arduino IDE | * Open the Arduino IDE | ||
Go to Tools >> Manage Libraries | * Go to Tools >> Manage Libraries | ||
Search for “RTClib” | * Search for “RTClib” | ||
Click “Install” | * Click “Install” [[Image:bmdsg27.png|600px|thumb|center]] | ||
* The IDE may ask if you wish to install “all missing dependencies”. In the case this window appears, click “Install All” | |||
==== Including the Library ==== | |||
Including the Library | |||
The RTClib library provides all the functions/methods needed to interface with the sensor. In order to use these functions, the library itself must be included at the very beginning of the Arduino file. This can be done using the following code: | The RTClib library provides all the functions/methods needed to interface with the sensor. In order to use these functions, the library itself must be included at the very beginning of the Arduino file. This can be done using the following code: | ||
[[Image:bmdsg30.png|600px|thumb|center]] | |||
==== Using the Library ==== | ==== Using the Library ==== | ||
In order to use the library, a RTC_DS3231 object must be created. The following code creates an object with the name rtc. | In order to use the library, a RTC_DS3231 object must be created. The following code creates an object with the name rtc. | ||
[[Image:bmdsg29.png|600px|thumb|center]] | |||
Next, the module object must be initialized and configured. This should be done in the setup() function. To initialize the module, use the begin() method as shown below. | Next, the module object must be initialized and configured. This should be done in the setup() function. To initialize the module, use the begin() method as shown below. | ||
[[Image:bmdsg28.png|600px|thumb|center]] | |||
Now that the module object has been started, it needs to be configured in order to set the date and time. We only need to configure the time if the RTC has lost power (i.e. been disconnected from a power source or from it’s battery). To configure the module with the current time, use the following code: | Now that the module object has been started, it needs to be configured in order to set the date and time. We only need to configure the time if the RTC has lost power (i.e. been disconnected from a power source or from it’s battery). To configure the module with the current time, use the following code: | ||
[[Image:bmdsg31.png|600px|thumb|center]] | |||
If you would like to set the module to a specific date and time, you can explicitly state these values in the adjust method. The code below will set the RTC to January 21, 2014 at 3am. | If you would like to set the module to a specific date and time, you can explicitly state these values in the adjust method. The code below will set the RTC to January 21, 2014 at 3am. | ||
[[Image:bmdsg32.png|600px|thumb|center]] | |||
Now that the RTC object has been started, data can now be obtained. The method now() will return the current date and time as a DateTime object. The following code creates a DateTime object called currentDT. | Now that the RTC object has been started, data can now be obtained. The method now() will return the current date and time as a DateTime object. The following code creates a DateTime object called currentDT. | ||
[[Image:bmdsg33.png|600px|thumb|center]] | |||
This DateTime object can now be used to obtain the current year, month, day, day of the week, hour, minute, and second as set by the module. This code prints out this data using the format year/month/day (dayoftheweek) hour:minute:second (eg. 2021/2/14 (0) 14:13:30) | This DateTime object can now be used to obtain the current year, month, day, day of the week, hour, minute, and second as set by the module. This code prints out this data using the format year/month/day (dayoftheweek) hour:minute:second (eg. 2021/2/14 (0) 14:13:30) | ||
[[Image:bmdsg34.png|600px|thumb|center]] | |||
The RTClib Library also comes with many example codes. These can be found on the Arduino IDE, under File >> Examples >> RTClib. | The RTClib Library also comes with many example codes. These can be found on the Arduino IDE, under File >> Examples >> RTClib. | ||
== Force Sensor == | == Force Sensor == | ||
EG1004 provides an Adafruit Round Force-Sensitive Resistor (FSR). These specialized resistors rely on electrical shorts for which the resistance changes depending on the pressure. | |||
[[Image:bmdsg35.jpeg|600px|thumb|center]] | |||
Figure 3: Source | [[Image:bmdsg36.png|600px|thumb|center|Figure 3: Source]] | ||
This resistance can then be correlated to force. Figure 4 shows the resistance vs force curve. Please note the logarithmic scale, however, the relationship is generally linear above 50g. | This resistance can then be correlated to force. Figure 4 shows the resistance vs force curve. Please note the logarithmic scale, however, the relationship is generally linear above 50g. | ||
[[Image:bmdsg37.png|600px|thumb|center|Figure 4: Source]] | |||
Figure 4: Source | |||
=== Wiring === | === Wiring === | ||
Note: The 10kresistor is essential for using the FSR. Do not leave it out of the circuit, | Note: The 10kresistor is essential for using the FSR. Do not leave it out of the circuit, | ||
[[Image:bmdsg38.png|600px|thumb|center]] | |||
=== Code === | === Code === | ||
As the FSR provides an analog signal, analogRead() will be used to get the voltage reading from the resistor. | As the FSR provides an analog signal, analogRead() will be used to get the voltage reading from the resistor. | ||
[[Image:bmdsg9.png|600px|thumb|center]] | |||
This voltage reading can then be correlated to various levels of pressure. Here are the threshold values for the below example code. | This voltage reading can then be correlated to various levels of pressure. Here are the threshold values for the below example code. | ||
Threshold Value | ::{| class="wikitable" | ||
Pressure Reading | !'''Threshold Value'''!!'''Pressure Reading''' | ||
<10 | |- | ||
No pressure | | <10||style="text-align: right;"|No pressure | ||
Between 10 and 200 | |- | ||
Light touch | | Between 10 and 200||style="text-align: right;"|Light touch | ||
Between 200 and 500 | |- | ||
Light squeeze | | Between 200 and 500||style="text-align: right;"|Light squeeze | ||
Between 500 and 800 | |- | ||
Medium squeeze | | Between 500 and 800||style="text-align: right;"|Medium squeeze | ||
Above 800 | |- | ||
Big squeeze | | Above 800||style="text-align: right;"|Big squeeze | ||
|- | |||
|} | |||
It’s recommended to test the sensor in order to determine the correct threshold for your FSR. | It’s recommended to test the sensor in order to determine the correct threshold for your FSR. | ||
[[Image:bmdsg39.png|600px|thumb|center]] | |||
The above code works for general correlations of resistance and pressure. If you would like to measure exact values of force, [https://learn.sparkfun.com/tutorials/force-sensitive-resistor-hookup-guide/all#example-arduino-sketch SparkFun] provides a good sample code for converting the FSR reading into exact values. | |||
The above code works for general correlations of resistance and pressure. If you would like to measure exact values of force, SparkFun provides a good sample code for converting the FSR reading into exact values. | |||
== Muscle Sensor == | == Muscle Sensor == | ||
EG1004 provides a Myoware muscle sensor which uses electromyography (EMG) to measure muscle activity. This electrical activity is then converted into a varying voltage which can be read using an Arduino. | |||
[[Image:bmdsg40.png|600px|thumb|center]] | |||
=== Downloads === | === Downloads === | ||
Fritzing files for the muscle sensor are not publicly available. | Fritzing files for the muscle sensor are not publicly available. EG1004 provides a Fritzing file [https://drive.google.com/file/d/1TF58D27Xl8S6yEPhBApPfmFI6O_Z-Msr/view?usp=sharing here]. | ||
=== Wiring === | === Wiring === | ||
Note: In order to use the muscle sensor, you must also connect electrodes to the snap connectors on the sensor board. Electrodes are electrical conductors through which electricity can enter or leave a nonmetallic object or part of a circuit. They do not come included with the muscle sensor, but | Note: In order to use the muscle sensor, you must also connect electrodes to the snap connectors on the sensor board. Electrodes are electrical conductors through which electricity can enter or leave a nonmetallic object or part of a circuit. They do not come included with the muscle sensor, but EG1004 does provide the Muscle Sensor electrodes. | ||
[[Image:bmdsg41.png|600px|thumb|center]] | |||
=== Pins === | === Pins === | ||
+: 5V | * +: 5V | ||
-: Ground | * -: Ground | ||
Sig: A0 (or any analog pin) | * Sig: A0 (or any analog pin) | ||
=== Code === | === Code === | ||
As the Myoware Muscle Sensor is an analog sensor, analogRead() will be used to get the analog voltage reading from the sensor. | As the Myoware Muscle Sensor is an analog sensor, analogRead() will be used to get the analog voltage reading from the sensor. | ||
[[Image:bmdsg3.png|600px|thumb|center]] | |||
To see the value read by the sensor, use a print statement in the loop area of your code. Make sure to initialize the serial monitor by including Serial.begin(9600) in the setup area of your code. | To see the value read by the sensor, use a print statement in the loop area of your code. Make sure to initialize the serial monitor by including Serial.begin(9600) in the setup area of your code. | ||
[[Image:bmdsg4.png|600px|thumb|center]] | |||
Sensor values will differ depending on the placement of the electrodes (more information on electrode placement can be found [https://cdn-shop.adafruit.com/product-files/2699/AT-04-001.pdf here]). It’s recommended to test the sensor multiple times to determine the different muscle values for your sensor. | |||
Sensor values will differ depending on the placement of the electrodes (more information on electrode placement can be found here). It’s recommended to test the sensor multiple times to determine the different muscle values for your sensor. | |||
== Ultrasonic Sensor == | == Ultrasonic Sensor == | ||
EG1004 provides an HC-SR04 Ultrasonic sensor. This sensor uses a process similar to echolocation in order to determine how far away an object is. The sensor transmits a high frequency signal, then it receives the signal after it gets reflected by the object. The sensor determines the time elapsed between transmission and reception. This can be used to calculate the distance from the sensor to the object using the speed of sound (343m/s) | |||
[[Image:bmdsg42.png|600px|thumb|center]] | |||
[[Image:vex_Library_21.png|600px|thumb|center|Figure 5: Source: Random Nerd Tutorials]] | |||
* <b>Ranging Distance: 2cm to 400cm | |||
<b> | |||
* Measuring Angle: 15o | * Measuring Angle: 15o | ||
* Power Supply: 5V</b> | * Power Supply: 5V</b> | ||
=== Wiring === | === Wiring === | ||
[[Image:vex_Library_22.png|600px|thumb|center]] | |||
=== Pins === | === Pins === | ||
VCC: 5V | * VCC: 5V | ||
Trig: 11 (or any digital pin) | * Trig: 11 (or any digital pin) | ||
Echo: 12 (or any digital pin) | * Echo: 12 (or any digital pin) | ||
GND: Ground | * GND: Ground | ||
=== Code === | === Code === | ||
The first step in using an HC-SR04 is to set up the trigger and echo pins. In the setup() function, The trigger pin should be set to OUTPUT, and the echo pin should be set to INPUT as shown below. Here trigPin corresponds to the digital pin for the Trigger, while echoPin corresponds to the digital pin for the Echo. | The first step in using an HC-SR04 is to set up the trigger and echo pins. In the setup() function, The trigger pin should be set to OUTPUT, and the echo pin should be set to INPUT as shown below. Here trigPin corresponds to the digital pin for the Trigger, while echoPin corresponds to the digital pin for the Echo. | ||
[[Image:bmdsg47.png|600px|thumb|center]] | |||
Code can now be written in the loop() function to collect data. The ultrasonic sensor first needs to send a HIGH pulse of 10 or more microseconds using the trigger pin. One LOW pulse is used before to ensure a clean HIGH pulse, and another LOW after stops the HIGH pulse. | Code can now be written in the loop() function to collect data. The ultrasonic sensor first needs to send a HIGH pulse of 10 or more microseconds using the trigger pin. One LOW pulse is used before to ensure a clean HIGH pulse, and another LOW after stops the HIGH pulse. | ||
[[Image:bmdsg48.png|600px|thumb|center]] | |||
After the initial pulse has been sent out, the echo pin is then used to read the signal from the sensor. The method pulseIn() will return the time (in microseconds) from when the Trigger pin sends the ping, to when it is received by the Echo pin. | After the initial pulse has been sent out, the echo pin is then used to read the signal from the sensor. The method pulseIn() will return the time (in microseconds) from when the Trigger pin sends the ping, to when it is received by the Echo pin. | ||
[[Image:bmdsg49.png|600px|thumb|center]] | |||
Line 267: | Line 306: | ||
Below is an example of coding this formula, in order to get the distance between the sensor and a detected object. | Below is an example of coding this formula, in order to get the distance between the sensor and a detected object. | ||
[[Image:bmdsg50.png|600px|thumb|center]] |
Latest revision as of 15:45, 22 August 2022
The purpose of this guide is to provide useful information on common sensors used in the BMD SLDP. Note that sensors made by different brands may differ slightly from the ones mentioned in this guide, but documentation for all sensors are available online. For more information on coding with Arduino, please reference the Arduino Coding Guide.
Gas Sensor
EG1004 provides an Adafruit Gas Sensor. When a gas is detected, the analog voltage will increase in proportion to the gas. This sensor is sensitive to multiple gases, but cannot tell you which gas it detects.
Wiring
Note: the LED used in the circuit is not required, but could be helpful in regard to testing.
Pins
- VCC: 5V
- Signal: A0 (or any analog pin)
- GND: ground
Code
As the Adafruit Gas Sensor is an analog sensor, analogRead() will be used to get the analog voltage reading from the sensor.
To see the value read by the sensor, use a print statement in the loop area of your code. Make sure to initialize the serial monitor by including Serial.begin(9600) in the setup area of your code.
UV Sensor (GUVA-S12SD)
EG1004 provides a GUVA-S12SD UV Light Sensor Breakout. This sensor uses an UV photodiode to provide an analog voltage output that can then be converted to UV Index. The UV Index scale is published by the EPA, and is used to give guidance on sun exposure. Figure 1 shows the UV index scale, and Figure 2 shows the correlation between voltage, analog value, and UV Index.
Spectral Detection Range: 240nm to 370nm Power Supply: 2.7V to 5.5V
Wiring
Note: the sensor can be connected to either the 5V or 3.3V power supply.
Pins
- +: 5V (or 3.3V)
- OUT: A0 (or other analog pin)
- -: Ground
Code
As the GUVA-S12SD is an analog sensor, analogRead() will be used to get the voltage reading from the sensor.
This initial reading must then be converted to voltage. The formula will differ depending on if you are using the 3.3V or 5V power supply.
- 3.3V formula → Voltage(V) = reading * (3.3/1024.0)
- 5V formula → Voltage(V) = reading * (5.0/1024.0)
Below is an example of coding this formula for a 5V power supply. Note that the numbers are in decimal form, this is required in order to get correct voltage values.
Lastly, this voltage value can be converted to an approximate UV Index using the following formula:
For example, a voltage reading of 0.5V indicates a UV index of about 5.
Temperature Sensor (TMP36)
EG1004 provides an Analog TMP36 temperature sensor. These sensors use the change in voltage to produce an analog signal that is proportional to temperature. TMP36s have a temperature range between -40oC and 150oF. Power supply: 2.7V to 5.5V
Wiring
Note: the sensor can be connected to either the 5V or 3.3V power pins.
Pins
- VCC: 3.3V or 5V
- Signal: A0 (or any analog pin)
- GND: ground
Code
As the TMP36 is an analog sensor, analogRead() will be used to get the voltage reading from the sensor.
This initial reading must then be converted to Voltage. The formula will differ depending on if you are using the 3.3V or 5V power supply.
- 3.3V formula → Voltage(mV) = reading * (3300.0/1024.0)
- 5V formula → Voltage(mV) = reading * (5000.0/1024.0)
Below is an example of coding this formula for a 5V power supply. Note that the numbers are in decimal form, this is required in order to get correct temperature values.
Lastly, this voltage value needs to be converted to Celsius using the following formula:
Temperature (C) = (Voltage(mV) - 500.0) / 10.0
Below is an example of coding this formula. Once again, note the use of the decimal format for the numbers.
Pulse Sensor
EG1004 provides an ANMBEST Pulse Sensor. This is an optical heart rate sensor (PPG) designed for Arduino. The sensor uses an ambient light sensor to watch for a change in reflected light that occurs when blood pumps through tissue. By setting a standard threshold value, an Arduino can watch the analog signal from the sensor.
When the signal passes the threshold, this means a heartbeat has been detected. Once the signal drops below the threshold, the Arduino will wait for the signal to pass the threshold again, indicating another heartbeat.
Power Supply: 3V to 5V
Wiring
Pins
- GND (black wire): Ground
- VCC (red wire): 5V
- Signal (purple/pink wire): A0 (or other analog pin)
Code
Installing the Library
The PulseSensorPlayground Library must be installed to the Arduino IDE in order to use the sensor. To download the library:
- Open the Arduino IDE
- Go to Tools >> Manage Libraries
- Search for “PulseSensor Playground”
- Click “Install”
Including the Library
The PulseSensor Playground library provides all the functions/methods needed to interface with the sensor. In order to use these functions, the library itself must be included at the very beginning of the Arduino file. This can be done using the following code:
Using the Library
In order to use the library, a PulseSensor Playground object must be created. The following code creates an object with the name pulseSensor.
Next, the sensor object must be configured and initialized. This should be done in the setup() function. In the following code, PulseWire corresponds to the analog pin the sensor is connected to and Threshold corresponds to an integer value used for detecting the heartbeat (a good default threshold value is 550).
Now that the sensor object has been started, data can now be obtained. The method getBeatsPerMinute() will return the BPM value read by the sensor.
Another useful method is sawStartOfBeat(). This will return a boolean value depending on whether the sensor detected a new heartbeat. In the following example, sawStartOfBeat() is used to print out a message followed by the current BPM every time the sensor registers a heartbeat.
The PulseSensor Playground Library also comes with many example codes and tutorials. These can be found on the Pulse Sensor Website.
Real Time Clock (RTC) Module
EG1004 provides a DS3231 Real Time Clock Module. As an Arduino does not keep time, RTC modules use separate batteries to keep consistent time-keeping functions
Wiring
Note: In order to keep time without being consistently connected to power, you must install a coin battery into the module. They do not come included with the RTC module, but EG1004 does provide CR2032 coin batteries.
Pins
- SCL: A5 (or SCL pin)
- SDA: A4 (or SDA pin)
- VCC: 5V
- GND: Ground
Code
Installing the Library
The library EG1004 recommends the Adafruit’s RTClib library to interface with an RTC module. The library must be installed to the Arduino IDE in order to use the module. To download the library:
- Open the Arduino IDE
- Go to Tools >> Manage Libraries
- Search for “RTClib”
- Click “Install”
- The IDE may ask if you wish to install “all missing dependencies”. In the case this window appears, click “Install All”
Including the Library
The RTClib library provides all the functions/methods needed to interface with the sensor. In order to use these functions, the library itself must be included at the very beginning of the Arduino file. This can be done using the following code:
Using the Library
In order to use the library, a RTC_DS3231 object must be created. The following code creates an object with the name rtc.
Next, the module object must be initialized and configured. This should be done in the setup() function. To initialize the module, use the begin() method as shown below.
Now that the module object has been started, it needs to be configured in order to set the date and time. We only need to configure the time if the RTC has lost power (i.e. been disconnected from a power source or from it’s battery). To configure the module with the current time, use the following code:
If you would like to set the module to a specific date and time, you can explicitly state these values in the adjust method. The code below will set the RTC to January 21, 2014 at 3am.
Now that the RTC object has been started, data can now be obtained. The method now() will return the current date and time as a DateTime object. The following code creates a DateTime object called currentDT.
This DateTime object can now be used to obtain the current year, month, day, day of the week, hour, minute, and second as set by the module. This code prints out this data using the format year/month/day (dayoftheweek) hour:minute:second (eg. 2021/2/14 (0) 14:13:30)
The RTClib Library also comes with many example codes. These can be found on the Arduino IDE, under File >> Examples >> RTClib.
Force Sensor
EG1004 provides an Adafruit Round Force-Sensitive Resistor (FSR). These specialized resistors rely on electrical shorts for which the resistance changes depending on the pressure.
This resistance can then be correlated to force. Figure 4 shows the resistance vs force curve. Please note the logarithmic scale, however, the relationship is generally linear above 50g.
Wiring
Note: The 10kresistor is essential for using the FSR. Do not leave it out of the circuit,
Code
As the FSR provides an analog signal, analogRead() will be used to get the voltage reading from the resistor.
This voltage reading can then be correlated to various levels of pressure. Here are the threshold values for the below example code.
Threshold Value Pressure Reading <10 No pressure Between 10 and 200 Light touch Between 200 and 500 Light squeeze Between 500 and 800 Medium squeeze Above 800 Big squeeze
It’s recommended to test the sensor in order to determine the correct threshold for your FSR.
The above code works for general correlations of resistance and pressure. If you would like to measure exact values of force, SparkFun provides a good sample code for converting the FSR reading into exact values.
Muscle Sensor
EG1004 provides a Myoware muscle sensor which uses electromyography (EMG) to measure muscle activity. This electrical activity is then converted into a varying voltage which can be read using an Arduino.
Downloads
Fritzing files for the muscle sensor are not publicly available. EG1004 provides a Fritzing file here.
Wiring
Note: In order to use the muscle sensor, you must also connect electrodes to the snap connectors on the sensor board. Electrodes are electrical conductors through which electricity can enter or leave a nonmetallic object or part of a circuit. They do not come included with the muscle sensor, but EG1004 does provide the Muscle Sensor electrodes.
Pins
- +: 5V
- -: Ground
- Sig: A0 (or any analog pin)
Code
As the Myoware Muscle Sensor is an analog sensor, analogRead() will be used to get the analog voltage reading from the sensor.
To see the value read by the sensor, use a print statement in the loop area of your code. Make sure to initialize the serial monitor by including Serial.begin(9600) in the setup area of your code.
Sensor values will differ depending on the placement of the electrodes (more information on electrode placement can be found here). It’s recommended to test the sensor multiple times to determine the different muscle values for your sensor.
Ultrasonic Sensor
EG1004 provides an HC-SR04 Ultrasonic sensor. This sensor uses a process similar to echolocation in order to determine how far away an object is. The sensor transmits a high frequency signal, then it receives the signal after it gets reflected by the object. The sensor determines the time elapsed between transmission and reception. This can be used to calculate the distance from the sensor to the object using the speed of sound (343m/s)
- Ranging Distance: 2cm to 400cm
- Measuring Angle: 15o
- Power Supply: 5V
Wiring
Pins
- VCC: 5V
- Trig: 11 (or any digital pin)
- Echo: 12 (or any digital pin)
- GND: Ground
Code
The first step in using an HC-SR04 is to set up the trigger and echo pins. In the setup() function, The trigger pin should be set to OUTPUT, and the echo pin should be set to INPUT as shown below. Here trigPin corresponds to the digital pin for the Trigger, while echoPin corresponds to the digital pin for the Echo.
Code can now be written in the loop() function to collect data. The ultrasonic sensor first needs to send a HIGH pulse of 10 or more microseconds using the trigger pin. One LOW pulse is used before to ensure a clean HIGH pulse, and another LOW after stops the HIGH pulse.
After the initial pulse has been sent out, the echo pin is then used to read the signal from the sensor. The method pulseIn() will return the time (in microseconds) from when the Trigger pin sends the ping, to when it is received by the Echo pin.
After reading the duration, the last step needed is to convert this to distance. Duration can be converted to centimeters using the following formula:
Distance (cm) = (Duration (microseconds) /2) / 29.1
Below is an example of coding this formula, in order to get the distance between the sensor and a detected object.