/*
Author: Kate Appel
Date: 2014
Purpose: Motion Activated PowerRelay
Details: Arduino pin 2 get PIR sensor data and send to pin 3 digital LOW to Power Relay to turn it on
*/
int led1 = 3; // the pin that the LED1 is attached to
static int state=0;
// the setup routine runs once when you press reset:
void setup() {
// declare pin 3,6 to be an output:
pinMode(2, INPUT_PULLUP);
pinMode(led1, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = digitalRead(2);
if(sensorValue)
{
digitalWrite(led1,LOW);//turn on the relay
Serial.write("Motion\n");
delay(30000);//wait for relay on for 30 seconds.
state=1;
}
else {
Serial.println(sensorValue);
digitalWrite(led1,HIGH);//turn off the relay
}
}
Comments