
Reading a Temperature Sensor — SIK Circuit 7
Read temperature from a TMP36 sensor and display Celsius and Fahrenheit readings on the Serial Monitor. Your introduction to serial communication and real-world data.
说明
Parts & Introduction
Parts & Introduction
The TMP36 is an analog temperature sensor that outputs a voltage proportional to temperature. You'll learn to use the Serial Monitor to display real-time readings — an essential debugging tool.
Parts Needed
- 1x Arduino Uno + USB cable
- 1x Breadboard
- 1x TMP36 Temperature Sensor
- 5x Jumper Wires
Warning: The TMP36 looks similar to the transistor. Look for "TMP" in tiny letters and a triangle logo. The transistor has "222" printed on it. Inserting the wrong component can damage it!
此步骤所需材料:
SparkFun Inventors Kit - V3.21 套件
Arduino Uno R31 个
Breadboard1 个
TMP36 Temperature Sensor1 个
Jumper Wires3 个所需工具:
Hardware Hookup
Hardware Hookup
Wiring Instructions
With the TMP36 flat side facing you and pins pointing down, the pins are (left to right): 5V, Signal, GND.
- Connect the left pin to 5V.
- Connect the middle pin (signal) to Analog Pin A0.
- Connect the right pin to GND.
That's it — just 3 wires! The TMP36 can only be connected in one direction. Double-check before powering on.
此步骤所需材料:
TMP36 Temperature Sensor1 个
Breadboard1 个
Jumper Wires3 个Arduino Code
Arduino Code
Open the Arduino IDE and upload the following sketch to your Arduino board.
/*
SparkFun Inventor's Kit
Example sketch 07 — TEMPERATURE SENSOR
Use the serial monitor to read temperature from a TMP36 sensor.
Hardware connections:
TMP36 (flat side, pins down, left to right): 5V, SIGNAL, GND
Connect 5V pin to 5V, SIGNAL pin to analog pin 0, GND pin to GND.
This code is completely free for any use.
*/
const int temperaturePin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
float voltage, degreesC, degreesF;
voltage = getVoltage(temperaturePin);
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0/5.0) + 32.0;
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print(" deg C: ");
Serial.print(degreesC);
Serial.print(" deg F: ");
Serial.println(degreesF);
delay(1000);
}
float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814);
// Converts 0-1023 to 0.0-5.0 volts
}此步骤所需材料:
Arduino Uno R31 个所需工具:
Test & Experiment
Test & Experiment
What You Should See
Open the Serial Monitor (magnifying glass icon in Arduino IDE, or Ctrl+Shift+M). You'll see lines updating once per second:
voltage: 0.73 deg C: 23.24 deg F: 73.84
Troubleshooting
- Nothing happens: Open the Serial Monitor! The output goes there, not to the LEDs.
- Gibberish text: Set the Serial Monitor baud rate dropdown to 9600.
- Temperature unchanged: Pinch the sensor with your fingers to warm it up, or apply ice to cool it down.
Experiments to Try
- Add an LED that turns on above a temperature threshold (like a heat warning).
- Log data over time to see temperature trends.
- Combine with the LCD (Circuit 15) to display temperature without a computer.
材料
5- $105.00
- 占位符
- 1 个占位符
- 占位符
CC0 公共领域
此蓝图以 CC0 协议发布。你可以自由复制、修改、分发和使用此作品,无需征得许可。
通过购买蓝图中的产品支持创客,他们将获得 创客佣金 (由供应商设定),或创建此蓝图的新版本并将其作为连接包含在你自己的蓝图中以分享收入。