PIR and LDR based night lamp with manual lamp on off switch with push button

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)

MY code not working

Probably the least helpful thing you can write on this forum.

Please remember to use code tags when posting code

Can you describe in words what it should do ?

I think it is this:
When it is dark and the PIR becomes active then turn on the light. If the PIR is no longer active, then turn off the light.
When the lamp is on, and the button is pressed, then turn off the lamp.
When the lamp is off, and the button is pressed, then turn on the lamp.

Questions:
When the lamp is turned on by the button, and the PIR is never activated, should the lamp stay on forever ?
When the lamp is turned on by the button, and the PIR becomes active and then no longer active, should the lamp turn off ?

When it is dark and the PIR becomes active then turn on the light and stay on for a minute and turnoff.Also the lamp should operate in manual mode when push button is pressed lamp turn on and stay on till again button in pressed.