if statement to turn on relay problem, PLEASE HELP

i have a problem with my program, the relay won’t follow the statement that i make, after i pressed the push button the relay is just turned on, not following the rules

DHT11Project.ino (4.8 KB)

Can't see your code == can't help. Sorry.

#include <EEPROM.h>
#include <DS3232RTC.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>

LiquidCrystal_I2C lcd(0x27,16,2);

#define sensor A0
#define relay 4
#define button1 7
#define button2 8
dht DHT;

int push1=0;
int push2=0;

void setup() {
// put your setup code here, to run once:
setSyncProvider(RTC.get); // Initialize the rtc object
pinMode(relay, OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
Serial.begin(9600);
Serial.println(“Suhu dan Kelembapan Kandang Ayam\n\n”);
delay(1000);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();

}

void loop() {
// put your main code here, to run repeatedly:
DHT.read11(sensor);
int Menit=minute();
int push1 = digitalRead(button1);
int push2 = digitalRead(button2);

//EEPROMDATA
//Set Poin Suhu AYAM DAGENG
EEPROM.write(0, 32);
EEPROM.write(1, 30);
EEPROM.write(2, 28);
EEPROM.write(3, 27);
EEPROM.write(4, 26);
EEPROM.write(5, 25);
EEPROM.write(12, 70);

int Dg0= EEPROM.read(0);
int Dg1= EEPROM.read(1);
int Dg2= EEPROM.read(2);
int Dg3= EEPROM.read(3);
int Dg4= EEPROM.read(4);
int Dg5= EEPROM.read(5);
int Dgh= EEPROM.read(12);

//Set Poin Suhu AYAM TELOR
EEPROM.write(6, 33);
EEPROM.write(7, 32);
EEPROM.write(8, 30);
EEPROM.write(9, 28);
EEPROM.write(10, 25);
EEPROM.write(11, 25);
EEPROM.write(13, 60);
EEPROM.write(14, 65);

int Tl0= EEPROM.read(6);
int Tl1= EEPROM.read(7);
int Tl2= EEPROM.read(8);
int Tl3= EEPROM.read(9);
int Tl4= EEPROM.read(10);
int Tl5= EEPROM.read(11);
int Tlh1= EEPROM.read(13);
int Tlh2= EEPROM.read(14);

// Set temprature & Humidity to turn on relay
while( push1 == 1 )
{
lcd.setCursor(0,0); lcd.print(“Ayam Pedaging”);

for (Menit == 46;Menit<=50; Menit++) // to match the specified time in minute
{
if(DHT.humidity > Dgh||DHT.temperature > Dg0) //to see if the temprature & Humidity is exceed the
maximum value from the setpoint to turn on the
relay

{
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 11;Menit<=20; Menit++)
{
if(DHT.humidity > Dgh||DHT.temperature > Dg1){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 21;Menit<=30; Menit++)

{
if(DHT.humidity > Dgh||DHT.temperature > Dg2){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 31;Menit<=40; Menit++)

{
if(DHT.humidity > Dgh||DHT.temperature > Dg3){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 1;Menit<=10; Menit++)

{
if(DHT.humidity > Dgh||DHT.temperature > Dg4){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 51;Menit<=59; Menit++)

{
if(DHT.humidity > Dgh||DHT.temperature > Dg5){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}
}

while( push2 == 1 )
{
lcd.setCursor(0,0); lcd.print(“Ayam Petelur”);

for (Menit == 1;Menit<=10; Menit++)
{
if(DHT.humidity > Tlh1||DHT.temperature > Tl0){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 11;Menit<=20; Menit++)
{
if(DHT.humidity > Tlh1||DHT.temperature > Tl1){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 21;Menit<=30; Menit++)

{
if(DHT.humidity > Tlh1||DHT.temperature > Tl2){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 31;Menit<=40; Menit++)

{
if(DHT.humidity > Tlh1||DHT.temperature > Tl3){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 41;Menit<=50; Menit++)

{
if(DHT.humidity > Tlh2||DHT.temperature > Tl4){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}

for (Menit == 51;Menit<=59; Menit++)

{
if(DHT.humidity > Tlh2||DHT.temperature > Tl5){
digitalWrite(relay, HIGH);}
else{
digitalWrite(relay, LOW);}
}
}

// Tampilan di serial Monitor
Serial.print(“Kelembapapan udara=”);
Serial.print(DHT.humidity);
Serial.print("%");
Serial.print(“Suhu=”);
Serial.print(DHT.temperature);
Serial.print(“C”);
Serial.print("\n");
Serial.print(“now: “);
Serial.print(Menit);
Serial.print(”\n”);

delay(1000);

// Tampilan LCD

lcd.setCursor(1,1); lcd.print(“H: “);
lcd.setCursor(3,1); lcd.print((float)DHT.humidity,0);
lcd.setCursor(6,1); lcd.print(”%”);
lcd.setCursor(9,1); lcd.print("T: ");
lcd.setCursor(11,1); lcd.print((float)DHT.temperature,0);
lcd.setCursor(13,1); lcd.print((char)223);
lcd.setCursor(14,1); lcd.print(“C”);
delay(5);

}

for (Menit == 1;Menit<=10; Menit++)

oops.

not following the rules

Remember that when it comes to interpreting the rules, 99.999% of the time, the compiler is going to win.

Please remember to use code tags when posting code

  while ( push1 == 1 )
  {

Can the value of push1 change in the while loop ? If not then how will the while loop ever end ? Note also that you have more than one variable named push1. One global and one local to the loop() function. Same name but different variables with different scopes

AWOL:

for (Menit == 1;Menit<=10; Menit++)

oops.

Remember that when it comes to interpreting the rules, 99.999% of the time, the compiler is going to win.

Please remember to use code tags when posting code

for (Menit == 46;Menit<=50; Menit++) // to match the specified time in minute

if(DHT.humidity > Dgh||DHT.temperature > Dg0) //to see if the temprature & Humidity is exceed the
maximum value from the setpoint to turn on the
relay

*Okay i’ll remember to use code tags next time, thank you to remind me

UKHeliBob:

  while ( push1 == 1 )

{



Can the value of push1 change in the while loop? If not then how will the while loop ever end? Note also that you have more than one variable named push1. One global and one local to the loop() function. Same name but different variables with different scopes

I think no, thats why i'm a bit confussed, should i use while loop or another loop function

so the variable push1 at the global variable is actually not necessary?

for (Menit == 46;Menit<=50; Menit++)Still oops.

so the variable push1 at the global variable is actually not necessary?

You certainly don't need both of them, but the main problem is that you do not read the input and put the result in push1 inside the while loop, so the value of push1 will never change once in the while loop