Hi,
i am making a pir and ldr based night led lamp. i have to add a push buttton to turn the lamp on/off manualy also.
The lamp should work both auto and manual.
MY code not working
int ledDelay = 30;
#define LAMP 9 // choose the pin for the RELAY
#define PIR 2 // choose the input pin (for PIR sensor)
#define button 8
int ledflag=0;
int pirState = LOW;
//const int fadingDelay = 50;
void setup()
{
Serial.begin(9600);
pinMode(LAMP, OUTPUT); // declare lamp as output
pinMode(PIR,INPUT); // declare sensor as input
pinMode(button,INPUT);
Serial.begin(9600);
}
void loop()
{
int value_button = digitalRead(button);
int value_ldr = analogRead(A0); // read LDR value
int value_pir = digitalRead(PIR); // read input value
Serial.println(value_ldr);
//Serial.println(value_pir);
if(value_button==HIGH){
if (ledflag==0) { // and the status flag is LOW
ledflag=1; // make status flag HIGH
digitalWrite(LAMP,HIGH); // and turn on the LED
} //
if((20>value_ldr) && ( value_pir==HIGH) ){
digitalWrite(LAMP,HIGH); // and turn on the LED
} //
else { // otherwise...
ledflag=0; // make status flag LOW
digitalWrite(LAMP,LOW); // and turn off the LED
}
delay(1000); // wait a sec for the
} // hardware to stabilize
}
nightlampbutton.ino (1.45 KB)