Introduction: Automatic Temperature Sensor

In This Model we are going to combine a temperature sensor and an fan and are going to program the arduino to handle the analog output from the sensor and use it to determine if the temperature is okay or High .

if the temperature is high then fan will start automatically and a Warning message will be displayed on the LCD Screen....

Step 1: Getting Started !

Materials Required :-

-- Arduino UNO (or any other Microcontroller)

-- LM35 (or any other temp. sensor)

-- LCD 16 X 2

-- Mosfet Transistor

-- 9-18 Volt Battery (for fan)

-- Connecting wires

-- Breadboard

Step 2: The Circuit ​!!

connect the circuit as shown in the fritzing diagram.

the reading of LM35 goes to arduino pin A5.

the lcd wiring is as follows :-

* LCD RS pin to digital pin 7
* LCD Enable pin to digital pin 6

* LCD D4 pin to digital pin 5

* LCD D5 pin to digital pin 4

* LCD D6 pin to digital pin 3

* LCD D7 pin to digital pin 2

* LCD R/W pin to ground

* 10K resistor: ends to +5V and ground

* wiper to LCD VO pin (pin 3)

Step 3: Get Ready for Some Maths !!!

LM35 is a precision centigrade temperature sensor :-

as the datasheet reads as :-

Each 10 mV is directly proportional to 1 Celcius. so we need to calculate a number to be multiplied or divided so that the ratio of mV and celcius is same Lets obtain it :-

(5 x 1000 / 1024) / 10 where SUPPLY VOLTAGE is 5.0V (the voltage used to power LM35)

1024 is 2^10, value where the analog value can be represented by ATmega 328 (Arduino UNO) or the maximum value it can be represented is 1023. The actual voltage obtained by VOLTAGE_GET / 1024. 1000 is used to change the unit from V to mV 10 is constant.0.48828125. By doing simple math: (5.0 * 1000 / 1024) / 10 = 0.48828125

Hence the ratio for the analogReading to temperature = 0.48828125

Step 4: Code It !!!!

Code is :-

float temp;

int setValue = 40;

int tempPin = A0;

int fan = 9 ;

#include LiquidCrystal lcd(7, 6, 5, 4, 3, 2);


void setup() {

lcd.begin(16, 2);

pinMode(fan,OUTPUT);

Serial.begin(9600);

}

void loop() {

lcd.clear();

temp = analogRead(tempPin);

temp = temp * 0.48828125;

if (temp setValue){

int fanpwm = map(temp,setValue,140,75,255);

analogWrite(fan,fanpwm);

lcd.clear();

lcd.print("WARNING");

lcd.setCursor(0,1);

lcd.print("High Temp:-");

lcd.setCursor(11,1);

lcd.print(temp);

delay(40);

}

}