/* * PIR sensor tester */ //int ledPin = 13; // choose the pin for the LED int inputPin = 6; // choose the input pin (for PIR sensor) int inputPinLeft = 5; int pirState = LOW; // we start, assuming no motion detected int pirStateLeft = LOW; int val = 0; // variable for reading the pin status int valLeft; const int SOL_PIN_A = 15; const int SOL_PIN_B = 18; const int SOL_PIN_C = 8; // 17 const int SOL_PIN_D = 9; // 18 const int SOL_PIN_E = 10; const int SOL_PIN_F = 17; // not 14, 11, 12 const int SOL_PIN_G = 16; const int flashtime = 75; void setup() { pinMode(SOL_PIN_A, OUTPUT); pinMode(SOL_PIN_B, OUTPUT); pinMode(SOL_PIN_C, OUTPUT); pinMode(SOL_PIN_D, OUTPUT); pinMode(SOL_PIN_E, OUTPUT); pinMode(SOL_PIN_F, OUTPUT); pinMode(SOL_PIN_G, OUTPUT); pinMode(inputPin, INPUT); // declare sensor as input pinMode(inputPinLeft, INPUT); Serial.begin(9600); } void loop(){ allUp(); val = digitalRead(inputPin); // read input value valLeft = digitalRead(inputPinLeft); if (val == HIGH) { // check if the input is HIGH if (pirState == LOW) { // we have just turned on Serial.println("Motion detected!"); allDown(); delay(3000); // We only want to print on the output change, not state pirState = HIGH; } } else if (valLeft == HIGH) { if (pirStateLeft == LOW) { // we have just turned on Serial.println("Motion detected Left!"); allDownLeft(); delay(3000); // We only want to print on the output change, not state pirStateLeft = HIGH; } } else { if (pirState == HIGH){ // we have just turned of Serial.println("Motion ended!"); // We only want to print on the output change, not state pirState = LOW; } } } void allUp(){ // turn the Solenoids on (HIGH is the voltage level) digitalWrite(SOL_PIN_A, HIGH); delay(flashtime); digitalWrite(SOL_PIN_B, HIGH); delay(flashtime); digitalWrite(SOL_PIN_C, HIGH); delay(flashtime); digitalWrite(SOL_PIN_D, HIGH); delay(flashtime); digitalWrite(SOL_PIN_E, HIGH); delay(flashtime); digitalWrite(SOL_PIN_F, HIGH); delay(flashtime); digitalWrite(SOL_PIN_G, HIGH); delay(flashtime); // wait for a second } void allDown(){ // turn the Solenoids off by making the voltage LOW digitalWrite(SOL_PIN_A, LOW); digitalWrite(SOL_PIN_B, LOW); digitalWrite(SOL_PIN_C, LOW); digitalWrite(SOL_PIN_D, LOW); digitalWrite(SOL_PIN_E, LOW); digitalWrite(SOL_PIN_F, LOW); digitalWrite(SOL_PIN_G, LOW); } void allDownLeft(){ // turn the Solenoids off by making the voltage LOW digitalWrite(SOL_PIN_G, LOW); digitalWrite(SOL_PIN_F, LOW); digitalWrite(SOL_PIN_E, LOW); digitalWrite(SOL_PIN_D, LOW); digitalWrite(SOL_PIN_C, LOW); digitalWrite(SOL_PIN_B, LOW); digitalWrite(SOL_PIN_A, LOW); }