I have an Arduino UNO that I am trying to make simple if statements code to read two conditions but my loop fails recognize the second condition. Why is my code not sensing analog in 4 and basically just halts?
I have attached my code, wiring diagram and flow chart. Any guidance with this project will be much appreciated. I am a notice at programming code.
I have attached a picture of my flow chart and wiring diagram.
You can see my code listed below:
int light;
int volt;
void setup() {
pinMode(13, OUTPUT); // put your setup code here, to run once:
pinMode(7, OUTPUT);
Serial.begin(9600);
}
void loop() {
light = analogRead(A0); // put your main code here, to run repeatedly:
volt = analogRead (A4);
if(light<700){
digitalWrite(13, HIGH); // LED on:
digitalWrite(7, HIGH); // Relay on:
}else{
digitalWrite(13, LOW); //LED off:
digitalWrite(7, HIGH);
if (light>700){
digitalWrite(13, LOW);
delay(900000); // 15 minute delay:
}else{
digitalWrite(13, HIGH);
if(volt<500){
digitalWrite(13, HIGH);
digitalWrite(7, HIGH);
}else{
digitalWrite(7, LOW);
delay(14400000); // 4hr delay for battery recharge:
if (volt>500){
digitalWrite(7, LOW);
digitalWrite(13, LOW);
}else{
digitalWrite(7, HIGH);
}
}
}
}
Serial.println(light);
delay(100);
}
