Make the Arduino into a temperature sensing device. Now there are various temperature sensors based on your requirement you should decide which one suits best for your project. Choose LM35 if you want a cheap sensor with average output.
We often travel to new places and pack our clothes depending on the weather conditions. We all check for what is the temperature there.
Temperature is the measure of heat emitted out from an object. Temperature sensors are present in many electrical devices such as our Refrigerators, Air conditioners etc.
What is LM35?
LM35 is a thermocouple Sensor that senses the heat from its surroundings. It takes the heat from its closest proximity. The output of the sensor is linear in nature that is the temperature is directly proportional to the voltage produced by the temperature sensor. LM35 can measure temperatures from -40 ° C to +150 ° C.
LM35 has 3 terminals
- Vcc – supplies the voltage to the LM35 and is connected to the +5V
- Output – outputs the signal which will be connected to the Arduino Analog Pins
- GND – This is to ground the LM35 and complete the circuit
Working Principle
The LM35 gives output voltage in the range 0 to 1 Volt. This temperature can be linearly found out that each degree change is equal to approximately 9.3 analog reading on the Arduino. So we get
Temp = analogRead(tempPin) / 9.3
How does the LM35 work with Arduino?
The LM35 senses the temperature using the thermocouple and outputs a voltage from the OUT pin. This pin is connected to the analog input pin on Arduino. The analog pin then can map the voltage to a certain temperature.
Things needed
- LM35
- Arduino
- Jumper Cables
- 3 LEDs
- 3 resistors of 220ohms
- Breadboard
Circuit Diagram
In this circuit we are reading the analog input from the A0 pin and indicating any temperature change of more than than 2 degrees from the room or base temperature that is stored in the program. The Base temp in my Code is assigned to 20℃.
Code
const int sensorPin = A0; //input pin from the LM35
const float baselineTemp = 20; //Room Temperature
void setup(){
Serial.begin(9600); // open a serial port
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
Serial.print(", degrees C: ");
// convert the reading to 'C Centigrade
float temperature = sensorVal/9.3;
Serial.println(temperature);
if(temperature < baselineTemp){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4)
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6)
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
else if(temperature >= baselineTemp+6)
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(100);
}
Enjoy learning the LM35, if you like learning in a simple way through videos. Watch the videos at Electronics Simplified