I have:
PIR Sensor
Relay
Button
What I need it to do:
- Sensor searching
- It sees me and turns on the relay.
- If the button is pressed while the relay is on, turn it off for 5 seconds.
- start back over
//Varialbles
int calibrationTime = 15; //the time we give the sensor to calibrate
int pirPin = 3; //pin connected to the PIR sensor's output
int relayPin = 12; //pin connected to the relay
int buttonPin = 2;
//Setup
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(buttonPin, INPUT);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
//LOOP
void loop(){
int sensorValue = digitalRead(pirPin); //declaring sensorValue to equal the tigger of PIR Sensor
int buttonValue = digitalRead(buttonPin);
if(sensorValue == HIGH){ //sensor is triggered
digitalWrite(relayPin, LOW); //turn on the relay
Serial.println("On"); //write on
if(buttonValue == HIGH){
Serial.println("button Pressed");
digitalWrite(relayPin, HIGH);
delay(1000);
Serial.println("1 Second");
delay(1000);
Serial.println("2 Seconds");
delay(1000);
Serial.println("3 Seconds");
delay(1000);
Serial.println("4 Seconds");
delay(1000);
}
}else{
digitalWrite(relayPin, HIGH);
Serial.println("OFF");
}
}