Hi, I am fairly new to arduino and C+. In fact this is my first sketch so I expect the answer is quite simple.
When I execute the following code, and I ground pin 2, my program thinks pin 2 is HIGH. It always goes to the subroutine for condition pin 2 = HIGH. I don't understand why.
int Relay1 = 8; //Close relay set to pin 8
int Relay2 = 9; //Open relay set to pin 9
int IRsens = 10; //IR sensor connected to pin 10
int Lightsens = 2; //light sensor connected to pin 2
int val = 0; //variable to store state of pin
void setup()
{
pinMode(Relay1,OUTPUT); //sets the relay pin as an output
pinMode(Relay2,OUTPUT); //sets the relay pin as an output
pinMode(Lightsens,INPUT); //sets the light sensor as input
pinMode(IRsens,INPUT); //sets the IR sensor as input
}
void loop()
{
val = digitalRead(Lightsens);
if (val = HIGH){daymode(); //If it's daytime go to the daytime subroutine
}
if (val = LOW) {nightmode(); //If it's nightime go to the night subroutine
}
}
void daymode()
{
//while (Lightsens = HIGH){
//;} //While it's still too light just wait
//while (IRsens = LOW){
//;} //Once it's dark, wait for movement
delay(1000); //Wait 15mins for Chickens to enter
digitalWrite(Relay1,HIGH); //Turn on the close relay
delay(1000); //Timer to be set, might need close confirm switch
digitalWrite(Relay1,LOW); //Turn off the bloody relay
}
void nightmode()
{
//while (Lightsens = LOW){
//;} //While its still dark just wait
digitalWrite(Relay2,HIGH); //When light comes turn on the open relay
delay(2000); //Wait long enough for gate to open
digitalWrite(Relay2,LOW); //Turn off relay
delay(2000);
}
I hope I posted this correctly.
Any help greately appreciated.
Thanks.