In this project, you will turn the Arduino into a thermometer! Use a temperature sensor to measure your skin temperature, and register the output with three LEDs. Even though the Arduino is a digital tool, it can interpret signals from an analog input, like the TMP36 temperature sensor, using the built in Analog-to-Digital (ADC) converter, accessed through the analog pins A0-A5, which you may have learned about in a previous lesson about analog input.
Explore the sample circuit embedded here by starting the simulation, clicking on the sensor, then dragging its temperature slider to adjust the simulated input and observe the resulting LED patterns.
In this lesson, you'll build this simulated circuit yourself along the sample side. To optionally build the physical circuit, gather up your Arduino Uno board, USB cable, solderless breadboard, three LEDs, three alike resistors (any value from 100-1K, 220 ohms preferred), a TMP36 temperature sensor, and breadboard wires.
Just as you’ve learned from the introductory lessons, start by wiring up your Arduino and breadboard with power and ground next to the example circuit, then add the three red LEDs to the breadboard, as shown. These will be the indicator or "bar graph" lights for the project.
Drag an Arduino Uno and breadboard from the components panel to the workplane, next to the existing circuit.
Connect the 5 volt and ground pins on the Arduino to the power (+) and ground (-) rails on the breadboard with wires. You can change the wire colors if you want to! Either use the inspector dropdown or the number keys on your keyboard.
Drag three LEDs on the breadboard in row E, spaced 2 breadboard sockets apart. You can change the LED color using the inspector that pops up when you click on each one.
Use a 220 Ohm resistor to connect each LED's cathode (left leg) to the ground rail (black) of the breadboard. In Tinkercad Circutis, you can change a resistor's value by highlighting it and using the dropdown menu in the inspector
.Connect the LED anodes (right, longer legs) to digital pins 4, 3, and 2 on the Arduino. The LED anode (+) is the terminal that current flows into.
The cathode (-) is the terminal that current flows from. This connects to the ground rail.
A temperature sensor creates a changing voltage signal depending on the temperature it senses. It has three pins: one that connects to ground, another that connects to 5 volts, and a third that outputs a variable voltage to your Arduino, similar to the analog signal from a potentiometer.
There are several different models of temperature sensor. This model, the TMP36, is convenient because its output voltage is directly proportional to temperature in degrees Celsius.
In the circuits editor, find the temperature sensor in the components drawer.
Place the temperature sensor (TMP36) on the breadboard with the rounded part facing away from the Arduino, as shown in the figure (this is the default orientation).
Place the temperature sensor on the breadboard in row E, as shown.
Wire up the temperature sensor so the left pin connects to the 5V voltage rail, the center pin connects to A0 on the Arduino, and the right pin connects to the GND rail.
In the circuit schematic, you can see that the temperature sensor is connected to power (5 volts) and ground (0 volts) and the analog pin A0. As temperature rises, the pin connected to A0 increases its voltage. You can also see that three LEDs are each connected to their own digital pin.
Even though the Arduino is a digital tool, it’s possible for it to get information from analog sensors to measure things like temperature or light. To do this, you’ll take advantage of the Arduino’s built-in Analog-to-Digital Converter (ADC).
Analog-in pins A0 to A5 can interpret voltages between 0 and 5V, and translate that voltage to a value between 0 and 1023 for the Arduino sketch to use. The analog pins are primarily used to read information from sensors (but can also be used as digital outputs 14-19, unrelatedly).
Let's use the code blocks editor to listen to the state of the sensor, then make decisions about which LEDs to light up based on the sensor's value.
Click the "Code" button to open the code editor. The gray Notation blocks are comments for making a note of what you intend for your code to do, but this text is not required or executed as part of the program.
Click on the Variables category in the code editor. Create a new variable called baselineTemp and use a "set" block to set it to 40 (degrees C).
To store the sensor value, create a variable named "celsius".
Drag out a “set” block and adjust the dropdown to our new variable celsius.
In the Math category, drag out a “map” block, and nest two arithmetic blocks (“1 + 1”) within its first field.
Adjust the range from -40 to 125.
Click on the Input category and drag out an “analog read pin” block, and place it into the first ic field inside the "map" block.
Adjust the arithmetic blocks to "(read analog pin A0 - 20) x 3.04".
Optionally create a new variable for converting the temperature to Fahrenheit with a set block and some arithmetic blocks to read "set fahrenheit to (celsius x 9)/5 + 32".
Add some serial monitoring blocks to print out the temperature in one or both C or F.
Click the Control category and drag out an if then block, then navigate to Math and drag a comparator block onto the if block.
In the Variables category, grab the celsius variable and the baselineTemp variable and drag them into the comparator block, adjusting the dropdown so it reads “if celsius < baselineTemp then”.
Add three digital output blocks inside the if statement to set pins 2, 3, and 4 LOW.
Duplicate this if statement four times and add arithmetic blocks and/or blocks to create five total state detection if statements. The first state is “the temperature is below our target baseline” so no LEDs light up. When the temperature is greater than or equal to the baselineTemp and less than baselineTemp+10, light up only pin 2's LED. When the temperature is between baselineTemp+10 and baselineTemp+20, light up two LEDs. And so on to account for all the desired states.
In this project, you will turn the Arduino into a thermometer! Use a temperature sensor to measure your skin temperature, and register the output with three LEDs. Even though the Arduino is a digital tool, it can interpret signals from an analog input, like the TMP36 temperature sensor, using the built in Analog-to-Digital (ADC) converter, accessed through the analog pins A0-A5, which you may have learned about in a previous lesson about analog input.
Explore the sample circuit embedded here by starting the simulation, clicking on the sensor, then dragging its temperature slider to adjust the simulated input and observe the resulting LED patterns.
In this lesson, you'll build this simulated circuit yourself along the sample side. To optionally build the physical circuit, gather up your Arduino Uno board, USB cable, solderless breadboard, three LEDs, three alike resistors (any value from 100-1K, 220 ohms preferred), a TMP36 temperature sensor, and breadboard wires.
Just as you’ve learned from the introductory lessons, start by wiring up your Arduino and breadboard with power and ground next to the example circuit, then add the three red LEDs to the breadboard, as shown. These will be the indicator or "bar graph" lights for the project.
Drag an Arduino Uno and breadboard from the components panel to the workplane, next to the existing circuit.
Connect the 5 volt and ground pins on the Arduino to the power (+) and ground (-) rails on the breadboard with wires. You can change the wire colors if you want to! Either use the inspector dropdown or the number keys on your keyboard.
Drag three LEDs on the breadboard in row E, spaced 2 breadboard sockets apart. You can change the LED color using the inspector that pops up when you click on each one.
Use a 220 Ohm resistor to connect each LED's cathode (left leg) to the ground rail (black) of the breadboard. In Tinkercad Circutis, you can change a resistor's value by highlighting it and using the dropdown menu in the inspector
.Connect the LED anodes (right, longer legs) to digital pins 4, 3, and 2 on the Arduino. The LED anode (+) is the terminal that current flows into.
The cathode (-) is the terminal that current flows from. This connects to the ground rail.
A temperature sensor creates a changing voltage signal depending on the temperature it senses. It has three pins: one that connects to ground, another that connects to 5 volts, and a third that outputs a variable voltage to your Arduino, similar to the analog signal from a potentiometer.
There are several different models of temperature sensor. This model, the TMP36, is convenient because its output voltage is directly proportional to temperature in degrees Celsius.
In the circuits editor, find the temperature sensor in the components drawer.
Place the temperature sensor (TMP36) on the breadboard with the rounded part facing away from the Arduino, as shown in the figure (this is the default orientation).
Place the temperature sensor on the breadboard in row E, as shown.
Wire up the temperature sensor so the left pin connects to the 5V voltage rail, the center pin connects to A0 on the Arduino, and the right pin connects to the GND rail.
In the circuit schematic, you can see that the temperature sensor is connected to power (5 volts) and ground (0 volts) and the analog pin A0. As temperature rises, the pin connected to A0 increases its voltage. You can also see that three LEDs are each connected to their own digital pin.
Even though the Arduino is a digital tool, it’s possible for it to get information from analog sensors to measure things like temperature or light. To do this, you’ll take advantage of the Arduino’s built-in Analog-to-Digital Converter (ADC).
Analog-in pins A0 to A5 can interpret voltages between 0 and 5V, and translate that voltage to a value between 0 and 1023 for the Arduino sketch to use. The analog pins are primarily used to read information from sensors (but can also be used as digital outputs 14-19, unrelatedly).
Let's use the code blocks editor to listen to the state of the sensor, then make decisions about which LEDs to light up based on the sensor's value.
Click the "Code" button to open the code editor. The gray Notation blocks are comments for making a note of what you intend for your code to do, but this text is not required or executed as part of the program.
Click on the Variables category in the code editor. Create a new variable called baselineTemp and use a "set" block to set it to 40 (degrees C).
To store the sensor value, create a variable named "celsius".
Drag out a “set” block and adjust the dropdown to our new variable celsius.
In the Math category, drag out a “map” block, and nest two arithmetic blocks (“1 + 1”) within its first field.
Adjust the range from -40 to 125.
Click on the Input category and drag out an “analog read pin” block, and place it into the first ic field inside the "map" block.
Adjust the arithmetic blocks to "(read analog pin A0 - 20) x 3.04".
Optionally create a new variable for converting the temperature to Fahrenheit with a set block and some arithmetic blocks to read "set fahrenheit to (celsius x 9)/5 + 32".
Add some serial monitoring blocks to print out the temperature in one or both C or F.
Click the Control category and drag out an if then block, then navigate to Math and drag a comparator block onto the if block.
In the Variables category, grab the celsius variable and the baselineTemp variable and drag them into the comparator block, adjusting the dropdown so it reads “if celsius < baselineTemp then”.
Add three digital output blocks inside the if statement to set pins 2, 3, and 4 LOW.
Duplicate this if statement four times and add arithmetic blocks and/or blocks to create five total state detection if statements. The first state is “the temperature is below our target baseline” so no LEDs light up. When the temperature is greater than or equal to the baselineTemp and less than baselineTemp+10, light up only pin 2's LED. When the temperature is between baselineTemp+10 and baselineTemp+20, light up two LEDs. And so on to account for all the desired states.
No comments:
Post a Comment