Introduction: Arduino Controled Temperature Sensor With Warning Light
I created this as a project to include in a book based on Arduino's that I am currently working on developing. The idea behind this project is that the Arduino will monitor the temperature in a room and should it get above a specific temperature it will make an LED blink until the temperature drops below the set temperature.
Step 1: What You Will Need.
1. Arduino Uno
2. Breadboard
3. A few male to male wires
4. LM 34 Temperature Sensor
5. A resistor, size can vary, the one used here is a 220 Ohm Resistor.
6. A simple LED.
Step 2: Setting Up the Circuit
This is an image of the circuit set up. I used a program called Fritzing to create the image of the circuit.
So basically how this is set up is I have an LED wired to digital pin 7 on the Uno. Important note, you need to make sure the positive end or anode is wired to the output pin on the board, this is usually the longer lead of the LED. The shorted end is the negative end or cathode. This needs to be wired with a resistor to the ground pin of the Uno.
The LM 34 Temperature sensor is a little trickier to set up. If you look at it there is a flat side and a rounded side. The diagram is set up as if you are looking at the flat side of the sensor. The middle pin of the sensor is wired to the Analog input pin labeled A0. The right pin of the sensor is the ground and needs to be wired to the ground pin of the Uno. The far left pin of the sensor is the input voltage pin. That is wired to the 5V pin of the Arduino.
Congratulations you have successfully set up the circuit.
Step 3: The Code.
So this code is what governs the Arduino. It tells the Arduino to read the sensor every 10 seconds and if the temperature is above 80 degrees Fahrenheit to blink the LED until the next read. It will also print the temperature to the serial monitor.
// Sets up variables
int AO = 0;
const int LED = 7;
//Sets up inputs and outputs.
void setup() {
Serial.begin(9600);
pinMode(LED,OUTPUT);
}
//Sets up the loop
void loop()
{
//Converts the voltage being read on the Analog pin to Fahrenheit, Celsius, Rankine, and Kelvin. Will also print those values to the serial monitor. This can be accessed via the magnifying glass in the upper right hand side of the Arduino IDE.
int rawvoltage = analogRead(AO);
float millivolts = (rawvoltage/1024.0) * 5000;
float fahrenheit = millivolts/10;
Serial.print(fahrenheit);
Serial.println(" degrees Fahrenheit, ");
float rankine = (fahrenheit + 460.67);
Serial.print(rankine); Serial.println(" degrees Rankine, ");
float celsius = ((fahrenheit - 32) * 5/9);
Serial.print (celsius);
Serial.println(" degrees Celsius, ");
float kelvin = (celsius + 274.15);
Serial.print(kelvin); Serial.println(" degrees Kelvin, ");
//Sets up the if statement, basically tells the Arduino to blink the LED for 10 seconds if the temperature is above 80 degrees Fahrenheit.
if (fahrenheit >= 80)
{
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
//Sets up else statement, basically if the temperature is below 80 degrees the Arduino will just wait 10 seconds before taking another read.
else
{
delay(10000);
}
}
Step 4: Finished
Congratulations you have now successfully built a temperature monitoring system with a warning light.
P.S. This is the first instructable I have written so I hope I have done well and explained everything well enough. If there are any suggestions or questions that can be used to help improve this instructable, please feel free to comment.