really stuck on IF statments

ok so im a noob but i feel i really shouldn't be getting stuck on this.

this is a pretty basic controller that turns lights off and on in my shed. it will get more complicated once the basic stuff is working.

currently nothing is happening though

  • iv run a test program on it that turns all the relays and leds on and off and that works
  • the input pins are definitely getting 5v when i press the buton
  • the relays turn on when the ttl to them is low.
  • iv set one off the leds to turn on and off at different points in the code. and it flashes so i can see its running through the code
  • the relays 1-3 are on
  • the other led is set to turn on to show when the lights are on, i cant get this led to light up

any help is great as iv really been scratching my head on this one

//    FILE: shed_basic
//  AUTHOR: Josh Sams
// VERSION: 0.1.00
// PURPOSE: shed lighting control, mk2 test file
//    DATE:03/06/2014
//
// COPYRIGHT: Released to the public domain for non profit use only. (copyright: JCStech 2014)
//


#define RELAY4 6   //pin to turn on -----
#define RELAY3 7   //pin to turn on side light
#define RELAY2 8   //pin to turn on door light
#define RELAY1 9   //pin to turn on interior lights
#define PUSH 11    //pin to read push button outside
#define GREEN 10 //pin to read green push button on elcosure
#define WHITE 12  //pin to read white push button on elcosure
#define LDR A2     //pin to sense outdoor light
#define LED1 2     //pin to light 1st led
#define LED2 3     //pin to light 2nd led



int val = 0;
unsigned long TIME;



void setup() 
{
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);


  pinMode(PUSH, INPUT);
  pinMode(GREEN, INPUT);
  pinMode(WHITE, INPUT);
  pinMode(LDR, INPUT);



}
void loop(){    

  digitalWrite(LED1, HIGH);
  
  if(GREEN == HIGH){
   digitalWrite(RELAY1, LOW);
    delay(600);
    digitalWrite(RELAY2, LOW);
    delay(600);
    digitalWrite(RELAY3, LOW);
    digitalWrite(LED2, HIGH);
  }
  if(PUSH == HIGH){
    digitalWrite(RELAY3, LOW);
    delay(600);
    digitalWrite(RELAY2, LOW);
    delay(4000);
    digitalWrite(RELAY1, LOW);
    digitalWrite(LED2, HIGH);
  }
  delay(300);

  if(WHITE == HIGH) {
    digitalWrite(RELAY1, HIGH);
    delay(15000);
    digitalWrite(RELAY2, HIGH);
    digitalWrite(RELAY3, HIGH);
    digitalWrite(LED2, LOW);
  }
  digitalWrite(LED1, LOW);
delay(300);
}   
//END OF FILE

To start with,
if(GREEN == HIGH){
Change
if( digitalRead(GREEN) == HIGH)
{

Etc.
See:

Also, it looks like your switch connects the input pins to +5V when you press it? Have you connected pull-down resistors from each input pin to 0V? If not, the pins will float when the switch is not closed and you may get false input readings.

A better approach is to use the internal pull-up resistors in the Arduino. You do this by changing the pinMode() statements to:

pinMode(GREEN, INPUT_PULLUP);

Then you need to connect your switches to 0V instead of +5V, and change your if statements to:

if (digitalRead(GREEN) == LOW)

Hackscribble:
Also, it looks like your switch connects the input pins to +5V when you press it? Have you connected pull-down resistors from each input pin to 0V? If not, the pins will float when the switch is not closed and you may get false input readings.

A better approach is to use the internal pull-up resistors in the Arduino. You do this by changing the pinMode() statements to:

pinMode(GREEN, INPUT_PULLUP);

Then you need to connect your switches to 0V instead of +5V, and change your if statements to:

if (digitalRead(GREEN) == LOW)

yes! i have pull down resistors. im actually pritty good at the circuit bit. i understand that bit very well fortunately.

thanks to both off you there. since theirs no read statement anywhere there its never going to read the pin is it. i just assumed when you used a comparator on the pin it would read the pin

cheers all!