Your Arduino cannot feel the room. But it can read a tiny sensor that changes its voltage with temperature—and your code can turn that voltage into a number a person understands.
Today you will build a temperature detective station. It will report Celsius and Fahrenheit in the Serial Monitor, then light a status LED when the temperature crosses a boundary you choose. This is a useful new kind of problem: a sensor gives the Arduino a raw number, and your math gives that number meaning.
At a glance
| Age range | 10–13 |
|---|---|
| Estimated time | 60–85 minutes |
| Difficulty | Beginner-plus |
| Parent involvement | Medium for the three-pin sensor orientation check; light afterward |
| Major concepts | TMP36 temperature sensor, analog voltage, variables, floating-point numbers, formula, constants, comparison, calibration evidence |
What you will learn
- How a three-pin TMP36 sensor sends an analog voltage that changes with temperature.
- How
analogRead()becomes a voltage, then a temperature in Celsius and Fahrenheit. - Why a calculation is more believable when each step has a named variable.
- How to select and test a temperature boundary instead of copying a magic number.
- How
if/elseconnects a temperature decision to LEDs. - Why a small sensor is useful for experiments but is not a medical or precision weather instrument.
Before you begin
Complete Lesson 6: Build an Arduino Smart Night-Light first. You will again read a changing analog value on A0, inspect it in the Serial Monitor, and create a condition from evidence. This time, the sensor gives a voltage that needs a formula before it becomes a useful temperature.
Use the small three-legged TMP36 temperature sensor from the Arduino Student Kit. It is not an LED and it is not a transistor. With its flat face toward you and its legs pointing down, its connections are left: 5V, middle: A0 output, right: ground. The orientation matters.
Do not simulate this project first. Tinkercad can model a temperature slider, but a real sensor in a real room teaches the important part: readings vary a little, hands warm the sensor slowly, and a useful threshold needs a test. Build physically. If your family already has a Tinkercad account and current browser, it can be used afterward to rehearse the pinout—not to replace the physical investigation.
Read Arduino’s official Read Analog Voltage example before or after building. For the sensor’s voltage behavior, use the Analog Devices TMP36 data sheet. The TMP36 has a 10 mV-per-degree-Celsius output scale and typically outputs 750 mV at 25 °C; your code uses that relationship.
What you need
Required components
| Quantity | Item | Compatible substitute |
|---|---|---|
| 1 | Arduino Uno from the Arduino Student Kit | Genuine Uno R3 or Uno R3 SMD |
| 1 | Solderless breadboard | Standard half-size breadboard |
| 1 | TMP36 temperature sensor from the Student Kit | TMP36 in TO-92 package; do not substitute LM35 or other look-alikes without changing the code and pinout |
| 1 | Green LED | Any ordinary 3–5 mm LED |
| 1 | Red LED | Any ordinary 3–5 mm LED |
| 2 | 220 Ω resistors | 330 Ω or 560 Ω resistors; one for each LED |
| 8–12 | Male-to-male jumper wires | Solid-core breadboard wires |
| 1 | USB-A to USB-B data cable | Arduino-branded USB-A-to-B data cable |
Optional components
- One blue LED and one more 220 Ω resistor for the required three-zone challenge.
- Piezo buzzer from Lesson 4 as an alternate warm-zone signal.
- Maker notebook, pencil, and a nearby household thermometer for a comparison only—not as an answer key.
Tools
None. This project is solderless.
Computer/software requirements
- Arduino IDE 2 with Arduino Uno and its port selected.
- Serial Monitor set to 9600 baud.
- A Mac running macOS 10.15 or later, or Windows 10 64-bit or newer.
Safety and setup notes
- Unplug USB before moving wires; connect it only after you have checked the TMP36 orientation together.
- This is a low-voltage, USB-powered project. Do not connect it to wall power, a 9V battery, liquids, flame, a stove, a hair dryer, or hot water.
- To test temperature changes, cup the plastic body of the sensor lightly between fingers for 15–30 seconds. Do not bend its legs repeatedly or press them into your skin.
- Place the TMP36 so all three legs are in different, unconnected breadboard rows—ideally straddling the center trench. With its flat face toward you: left → 5V; middle → A0; right → GND.
- The sensor needs no resistor. The LEDs each do need their own 220 Ω resistor.
- The adult should inspect sensor orientation and the 5V/GND paths before power-up. Let the student read values, do the formula, select boundaries, and investigate normal variation. Step in if the sensor becomes warm by itself, wires may connect 5V directly to ground, the board resets, or an output is wildly impossible after the orientation check.
Build overview
The TMP36 does not send the word “72 degrees.” It sends a small voltage. The Uno measures that voltage with A0, then code converts it into temperature.
Room temperature → TMP36 produces voltage → A0 reads 0–1023
→ code converts reading → volts → °C → °F
→ code compares temperature with your boundary → LEDs show status
The calculation happens in small, readable steps. That is deliberate engineering: if a final answer looks strange, you can inspect the raw reading, the voltage, and the temperature separately rather than hoping one giant formula is right.
Step-by-step build instructions
Step 1: Set up ground and the two LEDs
- Place the breadboard with its center trench running left to right.
- Connect Arduino GND to a breadboard ground rail using a black jumper.
- Place the green LED so its legs are in separate connected rows. Connect its short or flat-side leg to ground.
- Put one end of a 220 Ω resistor in the green LED’s long-leg row. Connect the resistor’s free end to Arduino D9.
- Build the red LED the same way on a separate part of the breadboard: short leg to ground; long leg through its own 220 Ω resistor to Arduino D10.
Checkpoint: trace each complete output separately: D9 → resistor → green LED → ground and D10 → resistor → red LED → ground. Each LED needs its own resistor.
Step 2: Wire the TMP36 temperature sensor
- Hold the TMP36 so its flat face is toward you and its three legs point down. Identify left, middle, and right before putting it in the breadboard.
- Insert the sensor with each leg in a different, unconnected breadboard row. Straddling the center trench is a reliable way to keep the legs isolated.
- Connect the left leg (+Vs) to Arduino 5V.
- Connect the middle leg (Vout) to Arduino A0.
- Connect the right leg (GND) to the ground rail.
| TMP36 leg with flat face toward you | Arduino connection | Job |
|---|---|---|
Left: +Vs | 5V | Powers the sensor |
Middle: Vout | A0 | Sends the changing temperature voltage |
Right: GND | GND rail | Completes the circuit |
Checkpoint: before plugging in USB, point to the flat face and say the three connections in order: “5V, A0, ground.” Have the parent confirm this one orientation check.
Step 3: Upload the temperature detective program
- Plug the Uno into the computer using the USB data cable.
- In Arduino IDE, select Arduino Uno and the correct port.
- Create a new sketch, replace the starter text with the complete code in the next section, and click Verify.
- Change
WARM_THRESHOLD_Fto a testable value after your first reading. For a first test, choose a value about 3–5°F above the current room-temperature reading—not a permanent idea of what room comfort should be. - Upload the code. Open Tools → Serial Monitor and set it to 9600 baud.
Checkpoint: once each second, the Serial Monitor should print a raw number, voltage, Celsius, Fahrenheit, and a status word. In a typical indoor room, the temperature should look plausible, not like 300°F or −100°F.
Step 4: Investigate a real temperature change
- Record the first three temperature readings in your notebook. They may vary by a small amount; that is normal.
- Gently hold the plastic top of the TMP36 between two fingers for 15–30 seconds. Watch the value rise gradually.
- Remove your fingers and wait. Predict what will happen, then observe the cooling trend.
- When the temperature crosses your test boundary, the red LED should turn on and the green LED should turn off. Below it, the green LED should be on.
Checkpoint: write one sentence that connects the real world to the code: “When I warmed the sensor, the ___ value changed, so the if condition became ___.”
Step 5: Compare evidence, not perfection
If you have a nearby thermometer, compare it loosely with the TMP36 after both have sat in the same spot for a few minutes. A small difference is not automatically a wiring failure. The sensor has its own accuracy limits, your hand can warm it, and the Uno’s 5V supply is an estimate in this simple calculation.
Checkpoint: decide whether your evidence shows a circuit or formula problem or ordinary sensor variation. Do not “fix” a small difference by secretly changing the formula.
Code
const int TEMP_PIN = A0;
const int COOL_LED_PIN = 9;
const int WARM_LED_PIN = 10;
// Replace this after you record your room’s actual Fahrenheit value.
const float WARM_THRESHOLD_F = 75.0;
void setup() {
pinMode(COOL_LED_PIN, OUTPUT);
pinMode(WARM_LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorReading = analogRead(TEMP_PIN);
float voltage = sensorReading * (5.0 / 1024.0);
float temperatureC = (voltage - 0.5) * 100.0;
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print("Raw: ");
Serial.print(sensorReading);
Serial.print(" | Volts: ");
Serial.print(voltage, 2);
Serial.print(" | C: ");
Serial.print(temperatureC, 1);
Serial.print(" | F: ");
Serial.print(temperatureF, 1);
Serial.print(" | ");
if (temperatureF >= WARM_THRESHOLD_F) {
digitalWrite(COOL_LED_PIN, LOW);
digitalWrite(WARM_LED_PIN, HIGH);
Serial.println("WARM");
} else {
digitalWrite(COOL_LED_PIN, HIGH);
digitalWrite(WARM_LED_PIN, LOW);
Serial.println("COOLER");
}
delay(1000);
}
What the important code means
- Variables and constants: the pin constants name physical connections.
WARM_THRESHOLD_Fis a named boundary you choose.sensorReading,voltage,temperatureC, andtemperatureFeach save one step of the detective work. setup(): this runs once. It prepares D9 and D10 as outputs and opens the Serial Monitor connection.loop(): this repeats every second: read the sensor, do the conversion math, show evidence, compare it with your rule, and update the LEDs.- Inputs and outputs:
analogRead(TEMP_PIN)is the input. The green and red LEDdigitalWrite()calls are outputs. Serial Monitor is also an output for people. - New number type:
floatmeans a number can have a decimal part. Temperature and voltage are not always whole numbers, sofloatis useful here. - The formula: the Uno turns 0–5V into readings from 0–1023. The first formula turns the reading into volts. TMP36 has a 0.5V offset and rises by 0.01V per °C, so
(voltage - 0.5) * 100gives Celsius. The final line converts Celsius to Fahrenheit. - The condition: when the Fahrenheit value is at or above your boundary, red turns on; otherwise green turns on. The exact number should come from your test, not from the example.
Arduino’s official Read Analog Voltage example explains the reading-to-voltage step. The TMP36 data sheet describes its 10 mV/°C output scale and 750 mV typical output at 25°C.
Make it work
The first version works when all of these are true:
- Arduino IDE says Done uploading.
- The Serial Monitor prints a new line about once each second at 9600 baud.
- The reported room temperature is plausible for your house.
- Gently warming the sensor makes the reported temperature rise gradually.
- Green is on below your test boundary; red is on at or above it.
- You can explain the path: TMP36 → A0 raw number → voltage → temperature →
ifrule → LEDs.
Understand it
- What does the TMP36 measure directly: a Fahrenheit number or a voltage?
- Why does the code use several named steps instead of one extra-long temperature formula?
- Predict what happens to
temperatureFifsensorReadinggets a little larger. - What job does
WARM_THRESHOLD_Fdo, and why is its name better than using75.0directly inside theifline? - Why is gently holding the sensor a better test than using a flame or hair dryer?
Required “change it” challenge
Desired outcome: turn the two-state detector into a three-zone comfort station: TOO COOL, COMFORTABLE, and TOO WARM. Use three LEDs—blue, green, and red—or use two LEDs plus the Lesson 4 piezo for one zone.
Constraints: use two named const float thresholds such as COOL_THRESHOLD_F and WARM_THRESHOLD_F; write your three rules in plain English before coding; use if, else if, and else; test your code with actual displayed temperatures; put one comment beside the thresholds explaining how you chose them. Keep the TMP36 on A0 and preserve the original working sketch first.
Hints:
- Pick a lower boundary and a higher boundary. For example: below lower is TOO COOL; between them is COMFORTABLE; at or above higher is TOO WARM. Your numbers should be values you can explain, not a copied answer.
- Add the blue LED using the same safe pattern as the other LEDs: D11 → 220 Ω resistor → blue LED long leg → short leg → ground.
- Make a paper table before you write code. It needs three rows: temperature range, status word, and which output should be on.
- In code, the cold test must come first or the warm test can come first; either order works if the middle
else ifhas the correct range. Test one LED rule at a time before decorating the project.
Parent guidance: have the student state the three plain-English rules and show the two chosen threshold values before looking at code. A productive struggle is 10–15 minutes of deciding whether a boundary belongs in the first or second comparison and using the Serial Monitor to test it. Ask, “Which readings should land in this zone?” Do not turn the challenge into a debate over the perfect household comfort temperature. Step in for sensor orientation, possible 5V/GND mistakes, an impossible reading after a careful physical check, or 15–20 minutes without a new diagnostic test. Save the two-LED version before custom work.
Optional enhancements
Try this
Add a status sound for TOO WARM using the Lesson 4 piezo on D8. Hint: use tone() only inside the warm branch, and stop the sound in the other branches with noTone(). Decide first whether a continuous sound would be annoying.
Challenge
Create a ten-reading temperature log. Record the time, °F, °C, and status in your notebook over a day. Look for patterns such as direct sun, air-conditioning cycles, or people using the room. Do not expect all readings to be identical.
Stretch
Build a cardboard “data detective station” with a sensor window, LED labels, and a small explanation for a visitor: “The sensor measures voltage. The code converts it. The lights show the rule.” Test whether the enclosure accidentally traps warm air around the sensor.
Debugging guide
| What you notice | Likely cause | Smallest next diagnostic step |
|---|---|---|
| The Uno does not upload or is not detected | Computer, cable, board, or port issue—not the temperature formula | Unplug breadboard wires and run Lesson 1’s built-in Blink check. Then use the Debugging Ladder. |
| Serial Monitor is blank or unreadable | It is closed, baud rate is wrong, or Serial.begin(9600) is missing | Open Serial Monitor; set it to 9600; compare the code’s setup() line. |
| Temperature is wildly impossible, such as hundreds of degrees | TMP36 is reversed, legs share a breadboard row, or wrong sensor type | Unplug USB. Face the flat side toward you and verify left → 5V, middle → A0, right → GND, each in a separate row. |
| Raw reading or temperature never changes | Middle output leg is not actually on A0, or the sensor is not being warmed | Print only sensorReading, trace the middle leg to A0, then cup the sensor body in fingers for 30 seconds. |
| The LEDs do not change even though the temperature does | Threshold is too far away or output wiring is wrong | First choose a test threshold 3–5°F above current reading. Then trace each LED path separately. |
| Green and red are both off or both on | LED polarity or pin wiring is wrong, or the code no longer has opposite output instructions | Run the original code and check D9 → green and D10 → red, with separate resistors and common ground. |
| Temperature is a little different from another thermometer | Sensor tolerance, location, hand warmth, or supply estimate | Leave both instruments in the same place for several minutes; record the difference rather than editing the formula. |
| A formula compilation error appears | Missing semicolon, parenthesis, or variable name mismatch | Read the first error message, then compare only the four conversion lines to the published code. |
If the smallest check does not answer the question, use the Debugging Ladder in order: power, data cable, board/port, loose wires, component direction, pin numbers, upload, then code logic. For outside troubleshooting, collect an overhead wiring photo, board model, operating system, selected port, exact error text, full code, Serial Monitor readings, and expected versus actual behavior.
Recap
You used a real sensor to make a chain of meaning: electrical voltage became an Arduino reading, then a voltage, then Celsius, then Fahrenheit, then a decision. You also learned that measured data can be useful without being perfect. Good makers record evidence, test a claim, and distinguish ordinary variation from a broken circuit.
Show what you learned
In your maker notebook, answer these in complete sentences or draw-and-label answers:
- What did the TMP36 measure directly, and what math turned it into Fahrenheit?
- What temperature did you record before and after warming the sensor?
- What did you change in the project?
- What failed, and how did you diagnose it?
- What would you improve next time? Explain one variable, formula line, sensor wire, or decision rule in your own words.
What’s next
Next is Lesson 8: Choose and Plan Your Arduino Invention. You will choose the problem your final project solves, map its inputs and outputs, write a rule in plain English, and prove one subsystem before building everything. The temperature sensor can become an input for a pet-care reminder or another capstone—but only if it makes the project more useful, not merely more complicated.
NEXT · LESSON 08Lesson 8: Choose and Plan Your Arduino Invention
Parent guide
What to prepare in advance
- Verify that Arduino IDE can upload a simple sketch to the Uno.
- Put out one TMP36, two LEDs, two 220 Ω resistors, breadboard, USB data cable, jumpers, and notebook. Keep the optional blue LED and piezo aside until the child earns the main build.
- Open the Components guide, Debugging Ladder, and Serial Monitor set to 9600 baud.
- Compare the actual TMP36 with the labeled flat-face visual. Confirm the left, middle, and right orientation before the child connects USB.
Where the child should work independently
Let the child place the LEDs, trace both outputs, insert the sensor, upload code, watch Serial Monitor, make a modest test threshold, warm the sensor, record evidence, and explain why the formula has several steps. He should choose the comfort zones and make the paper rule table for the required challenge.
Moments when the parent should resist taking over
Do not declare a small difference from a household thermometer a failure. Do not provide the “correct” comfort temperature. Do not repair an if/else challenge by writing the comparisons yourself; ask which temperature range belongs to each row of the student’s table. Let normal measurement variation become a science conversation.
When the parent should step in
Step in for uncertain TMP36 orientation, 5V/GND risk, a warm component, a board/cable/port failure, or a wildly impossible reading after an orientation check. Pause and restore the working two-LED sketch if custom work becomes tangled. If 15–20 minutes of genuine diagnostic testing yields no new evidence, collect a top-down wiring photo, full code, selected port, error text, raw readings, and expected-versus-actual behavior before asking for help.
A simple understanding-based assessment
Ask the student to draw four boxes with arrows: sensor → raw reading → formula → LED rule. Then give a real displayed temperature and ask which LED should light, using his named threshold. Score the same four things as every lesson: safe wiring, a clear explanation, recorded evidence, and persistence through an intentional test or revision—not merely matching a thermometer perfectly.
Further resource: Arduino: Read Analog Voltage