/* A motion sensor, when detecting motion, sends 3.3v to Pin 2
After getting input on pin 2, pin 3 will activate a motor for 1 second.
Then the program will wait designated time before activating the motor again.
*/
int PIR = 2;
int PUMP = 3;
//initialize Pin 2 as input and Pin 3 as output
void setup()
{
pinMode(PIR, INPUT);
pinMode(PUMP, OUTPUT);
Serial.begin(9600);
}
//Runs until shutting down. Wait for input, send output, wait designated time, repeat
void loop(){
//read the output state:
int outputState = digitalRead(PUMP);
//print the state of the output
Serial.println(outputState);
//if sensing nothing, do nothing
if (digitalRead(PIR == LOW))
{
digitalWrite(PUMP, LOW);
}
else
{
//if sensing movement activate pump for one second
if (digitalRead(PIR == HIGH))
{
digitalWrite(PUMP, HIGH);
delay(1000);
}
}
//wait one minute before looking for movement again
delay(600);
}