Control Arduino + LM35 + LCD+Relay(2 channel)

Hello everybody, I got the problem through arduino coding . In my project i want to control the relay based on real time temperature where by:

1.temperature >30
relay1(motor):ON
relay2(LED):OFF

2.temperature (20 <Temperature <30)
relay1(motor):OFF
relay2(LED):OFF

3.temperature <20
relay1(motor):OFF
relay2(LED):ON

Here, i attached my arduino coding,I don’t know the code is right or not based on 3 conditions above.

sketch_nov17a_testing.ino (1.04 KB)

Here is my coding…hope everyone can help me.thank you

#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = A0;
int relay1 =7; //motor
int relay2 =8; //led lamp
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
reading = analogRead(sensorPin);
int celsius = reading/2;
lcd.setCursor(0, 0);
lcd.print("Temperature: ");
// print the number of seconds since reset:
lcd.setCursor(0,1);
lcd.print(celsius, DEC);
lcd.print((char)223);
lcd.print(“C”);
if (celsius >=31)
{
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
}

else if (celsius >=20 && celsius <=30)
{
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}

else if (celsius <20)
{
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
}

delay(500);
lcd.clear();
}

You have not really stated what your problem is?

Break the development of this into two parts...

  1. Reading the temperature sensor. (I would, by the way, change to a DS18B20). All you need here is to set up a continuous loop which reads the sensor frequently... once per 5 seconds?... and send the reading to the serial monitor.

  2. Switching the relay. EITHER replace the tture sensor with a potentiometer to "stand in" for tture sensor (or fiddle with glasses of cold/ warm/ hot water to "dunk" sensor in, and work on the "if sensor says this, do that"... until the "that" you get is the RIGHT that! (If you can spare the pins, dedicate some LEDs to "saying", from code near the reading of the sensor, which tture band the sensor is reporting at the moment.