Arduino Room Temperature Control

Arduino

This project use LM35 as temperature sensor. Based on temperature level it will drive an exhausted fan to control the room temperature. We are using a single channel relay driver so user can drive a AC fan. Using the 4 Button user can change the temperature upper and lower level. Connect Arduino Uno as per below diagram

temperature-controller

 

Sample code below

#include <LCD.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
LiquidCrystal_SR lcd(12, 13, 8);

int fanPin = 9;
int tempPin = 2;
const int left=2;
const int right=3;
const int fwd=4;
const int back=5;
const int keypw=6;
int reading;
float tempC;
int thresholdU=45,thresholdL=30;
bool leftpin=true,rightpin=true,backpin=true,fwdpin=true;
bool fanstat=false;
int address = 0;

void setup() {
lcd.begin(16, 2);
lcd.clear();
// put your setup code here, to run once:
pinMode(fanPin, OUTPUT);
pinMode(left, INPUT);
pinMode(right, INPUT);
pinMode(fwd, INPUT);
pinMode(back, INPUT);
pinMode(keypw, OUTPUT);
// EEPROM.put(address, thresholdU);
EEPROM.get(address, thresholdU);
Serial.begin(9600); // initialization
Serial.println(“Starting”);
thresholdL=thresholdU-5;
}

void loop() {

reading = analogRead(tempPin);
tempC = reading / 9.31;
if(tempC>thresholdU ){
digitalWrite(fanPin, HIGH);

Serial.println(“Fan Started”);
}else if(tempC<thresholdL){
digitalWrite(fanPin, LOW);
}

lcd.setCursor(0, 0);
lcd.print(“U:”); // print Upper level
lcd.print(thresholdU);
lcd.print(“::L:”); // print Lower Level
lcd.print(thresholdL);
lcd.print(“:::”);
lcd.setCursor(0, 1);
lcd.print(“Temp:”); // print current temperature
lcd.print(tempC);
lcd.print(” “);
digitalWrite(keypw, HIGH);
leftpin = digitalRead(left);
rightpin = digitalRead(right);
fwdpin = digitalRead(fwd);
backpin = digitalRead(back);
if(leftpin==false){
Serial.println(“left press”);
thresholdL=thresholdL-1;
if(thresholdL<0)
thresholdL=0;
delay(2000);
}
if(rightpin==false){
Serial.println(“right press”);
thresholdL=thresholdL+1;

delay(500);
}
if(fwdpin==false){
Serial.println(“fwd press”);
thresholdU=thresholdU+1;
delay(500);
}
if(backpin==false){
Serial.println(“back press”);
thresholdU=thresholdU-1;
if(thresholdU<0)
thresholdU=0;
delay(500);
}

}