int ldr_val = 0; // variable to store the ldr sensor status (value)
int pir_value = 0; // variable to store the motion sensor status (value)
int led_w = 9; // pin 9 is set to LED white
int led_r = 10; // pin 10 is set to LED Red, Emergency
int led_b = 13; // pin 13 is set to LED Blue, to detect the motion sensor is working or not
int motion = 2; // pin 2 is set to Motion sensor
int button = 7; //pin7, button
int buzzer = 4; //pin4, buzzer
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led_w,OUTPUT); //LED White , ldr , output
pinMode(led_r,OUTPUT); // LED Red, emergency , output
pinMode(led_b,OUTPUT); // LED blue ,motion , output
pinMode(motion,INPUT); // motion , input
pinMode(button,INPUT); // buton, input
//pinMode(led_b,LOW); //motion , led blue
}
void loop() {
// put your main code here, to run repeatedly:
ldr_val = analogRead(A0); //the value is read by analog at A0
Serial.println(ldr_val); //The value read by A0 will print at the screen
//condition of environment
if (ldr_val<500)
{
pir_value = digitalRead(motion);
if (pir_value == HIGH) {
digitalWrite (led_b,HIGH); // motion, turn on led blue
delay(2000);
digitalWrite (led_w,HIGH); // ldr, turn on LED white
delay(5000);
}
}
else
{
digitalWrite(led_b,LOW); // turn off LED blue
delay;
digitalWrite(led_w,LOW); //led white
delay;
}
// emergency button
if (digitalRead(button) == HIGH) { //when button is pressed
digitalWrite(led_r,HIGH); //turn on led red
digitalWrite(buzzer,HIGH); // turn o the buzzer
delay(1000); //turn on led red for 5 seconds
}
else {
digitalWrite(led_r,LOW); // turn off led red
digitalWrite(buzzer,LOW); // turn off buzzer
delay;
}
}