PIR motion sensor game

PIR Motion Sensor Circuit

Components list:

Potentiometer x2, Piezo Buzzer x1, Wire, LED x2, Arduino Uno, 220 Ohm resistor x2

The PIR sensor in fritzing is not representative of the sensor we used. The sensor used for this can be found at Adafruit.

How the game works:

The red LED represents the status of the motion sensor, when it is lit, the sensor is armed and ready. The green LED indicates when the sensor has been triggered. One potentiometer controls the “pace” while the other controls “wait” to make the game a little more challenging. The buzzer will tick, and when the buzzer makes the go noise, you have to waive your hand frantically in front of the sensor before you run out of time. If you succeed in triggering the sensor, then it buzzes a satisfying tune. Conversely, if you lose then it triggers a sad tune. The motion sensor waits about 14 seconds before the next cycle of the game starts.

The rearm function has one minor drawback, mostly due to the inconsistencies in the motion sensor, and that the wait time is hardcoded to 14 seconds, even though the wait time could be higher or lower than that.


For all the fun things you can do with the PIR sensor from Adafruit, it has one major drawback. There is a delay, often inconsistent, every time the sensor is triggered. While it can be adjusted sightly, it ultimately comes down to cheap hardware not doing the job right.


here is the code:

const int digitalInPin = 8;
const int armedLedPin = 3;
const int motionLedPin = 2;
int time;
int x = 14; //takes about 14 seconds to rearm sensor
void setup() {
void loop() {
int motionVal = motionRead(digitalInPin,1000);
if(motionVal > 0) {
} else if (motionVal < 1) { digitalWrite(motionLedPin,LOW); digitalWrite(armedLedPin,HIGH); } Serial.println(time); rearm(); } int motionRead(int pin, int wait) { delay(wait); int sensorRead = digitalRead(pin); return(sensorRead); } void rearm() { time = x; for(int x; x>0; x–) {

One thought on “PIR motion sensor game

Leave a Reply