Hello, i've done a simple project, making temperature controlled relay.
the parts i used :
arduino uno
lm35
5V DC Relay
lcd 16x2
5V DC heater
3 push buttons, up down to set temperature, start button to start the program.
the system works perfectly.
But i want to modify this project by adding cooler. so i can choose between heating or cooling that connected to 1 relay. i put switch between heater and cooler, so i can switch manually, and no need more relay.
the problem is i've tried to modify the sketch, by adding one more push button as a selection to run program of cooler. But i confuse where i put the "break" function to the sketch because it keep looping.
please help.
here is the code
#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = A0;
int relay =8;
float celsius ;
int Tempset = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(relay,OUTPUT);digitalWrite(8,HIGH);
pinMode(9, INPUT);digitalWrite(9,HIGH); // pin up
pinMode(10, INPUT);digitalWrite(10,HIGH); // pin down
pinMode(12, INPUT);digitalWrite(12,HIGH); // pin to trigger heating control
pinMode(13, INPUT);digitalWrite(13,HIGH); // pin to trigger cooling control
lcd.clear();
delay (200);
lcd.setCursor (0,0);
lcd.print(" Heating & ");
lcd.setCursor(0,1);
lcd.print("Cooling Control");
delay(2000);
lcd.clear();
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.begin(16, 2);
lcd.setCursor (0,0);
lcd.print("Set");
lcd.setCursor(0,1);
lcd.print("Temperature");
delay(2000);
// lcd.scrollDisplayLeft();
// wait a bit:
if(digitalRead(9)==LOW||digitalRead(10)==LOW)
{delay(200);
while(1)
{
if(digitalRead(9)==LOW){Tempset++;}
if(digitalRead(10)==LOW){Tempset--;}
if(digitalRead(12)==LOW){delay(200);heater();}
if(digitalRead(13)==LOW){delay(200);cooler();}
lcd.begin(16, 2);lcd.print("Set Temp");
lcd.setCursor(4, 2);lcd.print(Tempset);
delay(200);
}
}
}
void heater()
{
reading = analogAvg(sensorPin);
celsius= ((5.0*reading)*100/1024);
if(celsius < Tempset )
digitalWrite(8,LOW);
else if( celsius > Tempset+1)
digitalWrite(8,HIGH);
lcd.begin(16, 2);lcd.print("Temp");
lcd.setCursor(12,2);
lcd.print(celsius);
lcd.print("C");
delay(1000);
}
void cooler()
{
reading = analogAvg(sensorPin);
celsius= ((5.0*reading)*100/1024);
if(celsius > Tempset )
digitalWrite(8,LOW);
else if( celsius < Tempset-1 )
digitalWrite(8,HIGH);
lcd.begin(16, 2);lcd.print("Temp");
lcd.setCursor(12,2);
lcd.print(celsius);
lcd.print("C");
delay(1000);
}
int analogAvg (int sensorPin)
{
unsigned int total=0;
for(int n=0; n<Tempset; n++ )
total += analogRead (sensorPin);
return total/Tempset;
}