// https://forum.arduino.cc/t/pir-as-switch-for-serial-output/1224834
// https://wokwi.com/projects/390019934465917953
/// switched from serial1
/// pushbutton not a PIR - pushbutton has bouncing turned off!
/// now PIR select it when running. 3 second latch, three second inhibit period
// a global variable flag
bool pirIsON;
const byte pirPin = 5;
const byte pirLEDPin = 4;
# define ACTIVE HIGH
void setup() {
Serial.begin(9600);
Serial.println("Jello Whirled!\n");
pinMode(pirPin, INPUT_PULLUP);
pinMode(pirLEDPin, OUTPUT);
pirIsON = digitalRead(pirPin) == ACTIVE;
}
void loop() {
bool sensorActive = digitalRead(pirPin) == ACTIVE;
if (sensorActive) { // PIR activated (NO)...
if (!pirIsON) {
Serial.write('A'); //send 'A' over serial TX pin 1
pirIsON = true;
}
}
else { // PIR not activated (NC)...
if (pirIsON) {
Serial.write('a'); //send 'a' over serial TX pin 1
pirIsON = false;
}
}
digitalWrite(pirLEDPin, pirIsON ? HIGH : LOW);
}
/*
{
"type": "wokwi-pir-motion-sensor",
"id": "pir1", "top": -140,
"left": -16.98, "attrs": {"delayTime":"5", "inhibitTime":"5" } },
*/