Hello, i tried to make project temperature controlled relay with time setting but im facing some problem
here is the project instruction must be:
first set time, then set temperature, press enter, relay will on if the current temperature is lower than set temperature, oppositely relay will off if the current temperature is higher than set temperature, and so on. relay will off if timer off.
but the problem is, when i set the temperature higher than current temperature, relay is on off on off on, it must be relay keep on because it still not reaching the set temperature, but it continue on then off, then on, then off. as the relay blinking, the temperature on display also not stable.
please help
here is the code
#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = A0;
int relay =12;
int buzzer =13;
int hours = 0; // start hours
int minutes = 0; //start min
int seconds = 0; //start seconds
int celsius = 0;
int suhu = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(relay,OUTPUT);digitalWrite(12,HIGH);
pinMode(buzzer,OUTPUT);digitalWrite(13,HIGH);
pinMode(8, INPUT);digitalWrite(8,HIGH); // pin start
pinMode(9, INPUT);digitalWrite(9,HIGH); // pin up
pinMode(10, INPUT);digitalWrite(10,HIGH); // pin down
lcd.clear();
delay (200);
lcd.setCursor (0,0);
lcd.print(" Alat Terapi ");
lcd.setCursor(0,1);
lcd.print(" Sinusitis ");
delay(2000);
lcd.setCursor(0,0);
lcd.print(" Berbasis ");
lcd.setCursor(0,1);
lcd.print(" Arduino Uno ");
delay(2000);
lcd.setCursor (0,0);
lcd.print(" Oleh ");
lcd.setCursor(0,1);
lcd.print(" Albama ");
delay(2000);
lcd.setCursor(0,0);
lcd.print(" NIM ");
lcd.setCursor(0,1);
lcd.print(" 14.006 ");
delay(2000);
lcd.setCursor (0,0);
lcd.print(" Pembimbing I ");
lcd.setCursor(0,1);
lcd.print(" Syahir,ST.MT ");
delay(2000);
lcd.setCursor(0,0);
lcd.print(" Pembimbing II ");
lcd.setCursor(0,1);
lcd.print(" Muh. Nurman, BE");
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.print("Setting Waktu");
lcd.setCursor(0,1);
lcd.print( " Dan Suhu " );
delay(2000);
// lcd.scrollDisplayLeft();
// wait a bit:
if(digitalRead(9)==LOW||digitalRead(10)==LOW)
{delay(200);
while(1)
{
if(digitalRead(9)==LOW){hours++;}
if(digitalRead(10)==LOW){hours--;}
if(digitalRead(8)==LOW){delay(200);break;}
lcd.begin(16, 2);lcd.print("Setting Jam ");
lcd.setCursor(4, 2);lcd.print(hours);
delay(200);
}
while(1)
{
if(digitalRead(9)==LOW){minutes++;}
if(digitalRead(10)==LOW){minutes--;}
if(digitalRead(8)==LOW){delay(200);break;}
lcd.begin(16, 2);lcd.print("Setting Menit ");
lcd.setCursor(4, 2);lcd.print(minutes);
delay(200);
}
while(1)
{
if(digitalRead(9)==LOW){seconds++;}
if(digitalRead(10)==LOW){seconds--;}
if(digitalRead(8)==LOW){delay(200);break;}
lcd.begin(16, 2);lcd.print("Setting Detik ");
lcd.setCursor(4, 2);lcd.print(seconds);
delay(200);
}
while(1)
{
if(digitalRead(9)==LOW){suhu++;}
if(digitalRead(10)==LOW){suhu--;}
if(digitalRead(8)==LOW){delay(200);break;}
lcd.begin(16, 2);lcd.print("Setting Suhu ");
lcd.setCursor(4, 2);lcd.print(suhu);
delay(200);
}
while(1)
{
program();
}
}
}
void program()
{
while (hours > 0 || minutes > 0 || seconds >= 0) {
reading = analogRead(sensorPin);
celsius= (5.0*reading)*100/1024;
if (celsius > suhu) <<<<<<<<<<<<<<< is this right?
{
digitalWrite(12, HIGH);
}
else
{digitalWrite(12,LOW);
}
lcd.begin(16, 2);lcd.print("Waktu Suhu");
lcd.setCursor(12,2);
lcd.print(celsius);
lcd.print("C");
lcd.setCursor(0, 2);
(hours < 10) ? lcd.print("0") : NULL;
lcd.print(hours);
lcd.print(":");
(minutes < 10) ? lcd.print("0") : NULL;
lcd.print(minutes);
lcd.print(":");
(seconds < 10) ? lcd.print("0") : NULL;
lcd.print(seconds);
lcd.display();
stepDown();
delay(1000);
}
}
void stepDown() {
if (seconds > 0) {
seconds -= 1;
} else {
if (minutes > 0) {
seconds = 59;
minutes -= 1;
} else {
if (hours > 0) {
seconds = 59;
minutes = 59;
hours -= 1;
} else {
trigger();
}
}
}
}
void trigger() {
lcd.clear(); // clears the screen and buffer
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
lcd.println("Selesai");
delay(1000);
}