How to Build a Simple Arduino-Based Temperature Sensor for Under $20
Building a simple temperature sensor with an Arduino is an easy and inexpensive way to monitor temperatures. With just a few basic electronic components, you can assemble a fully-functional temperature logger for under $20. Here's a step-by-step guide on how to build your own Arduino temperature sensor.
What You'll Need
To build the temperature sensor, you'll need the following parts:
- Arduino Uno board - The brains of the temperature sensor. Prices start around $5.
- TMP36 temperature sensor - Measures ambient temperature. Costs $1-2.
- Breadboard - Allows easy prototyping and wiring. Can be found for $5.
- Jumper wires - For connecting the components. A kit costs under $5.
- 10K ohm resistor - Works with the temp sensor. A few cents each.
- LED - Visual indicator. Also just a few cents.
- 9V battery & cable - Power source for Arduino. Around $5-10.
In total, all of the parts can be sourced for around $20, give or take a few dollars. Having a basic electronics toolkit with wire strippers, cutters, and a soldering iron is also recommended.
How It Works
The TMP36 temperature sensor works by outputting an analog voltage that is proportional to the ambient temperature around the sensor. At room temperature (25°C or 77°F), the sensor will output about 750 mV.
This analog voltage gets fed into one of the Arduino's analog input pins. The Arduino can then use its analog-to-digital converter (ADC) to convert this voltage to a digital value.
Some simple code can then take this digital value and convert it back to a temperature reading, in degrees Celsius, Fahrenheit, or Kelvin. This temperature can then be displayed on the Arduino's serial monitor or used to drive other outputs like an LED or LCD display.
Circuit Diagram
Here is a circuit diagram showing how to connect the components:
The key points in the wiring:
- The TMP36 VCC pin connects to 5V pin on Arduino
- The GND pin connects to Arduino GND
- The analog voltage output of sensor connects to analog pin A0
- The 10K resistor connects between analog out and GND
- The LED anode connects to Arduino pin 11, cathode to GND
Code
Here is some sample Arduino code to read the temperature sensor, convert the analog input to a temperature, and print it to the serial monitor:
```cpp
// Set analog pin for TMP36 sensor
int tempPin = 0;
// Variables to store temperature values
float tempC;
float tempF;
void setup() {
// Begin serial communication at 9600 baud
Serial.begin(9600);
}
void loop() {
// Read analog voltage from sensor
int reading = analogRead(tempPin);
// Convert to temperature in Celsius
tempC = (reading * 5.0 * 100.0)/1024;
// Convert Celsius to Fahrenheit
tempF = (tempC * 9.0)/5.0 + 32.0;
// Print temperatures
Serial.print(" C ");
Serial.print(tempC);
Serial.print(" F ");
Serial.println(tempF);
delay(500); // Wait half second and repeat
}
```
This code reads the analog voltage from the sensor pin, converts it to Celsius, then converts Celsius to Fahrenheit. It prints both values to the serial monitor every half second.
Building and Testing
With all the parts assembled, follow these steps:
- Build the circuit on a breadboard based on the wiring diagram above
- Upload the Arduino sketch to read the sensor
- Open the serial monitor at 9600 baud to see temperature output
- Verify the readings look reasonable by checking room temperature
- Optionally add an LED that blinks when a temperature threshold is exceeded
Once you have it working on a breadboard, you can transfer the circuit to a perfboard or PCB for a more compact and permanent sensor package. Add functions like data logging, alarm outputs, LCD display, etc.
Going Further
Some ideas for enhancing this basic temperature sensor:
- Log readings to an SD card for data logging
- Add real-time clock for timestamping readings
- Transmit data wirelessly using a radio module
- Interface to computer via serial port
- Switch to a more accurate thermocouple-based sensor
- Use solar power instead of a battery
By leveraging the Arduino platform, you can build a fully-featured temperature monitor on a low budget. The possibilities are endless!