Motion sensor on Raspberry Pi. Not going smoothly. Is a screen even on when nobody's looking at it? HINT: DID NOT USE!

The reason for all my pain.

This is related to the Airport departure board project you can check out here.


2th Jul, 2022: Indeed the WIFI was causing issues with the PIR sensor. I absolutely need the WIFI, so the PIR sensor is no more on this project. I added a button instead. Not exactly as I would like but this project is now closed.

30th Jun, 2022: I just found this: weird problem: PIR sensor positive on wifi activity - Raspberry Pi Forums, I'm rethinking if I should pursue motion detection using the PIR...

29 Jun 2022: This is an evolving project, not yet complete as of 29 Jun 2022 as I am struggling with some very annoying false positives that happen at short intervals. This is driving me absolutely bonkers!

Simple goal was to add a motion sensor to activate the screen only when someone was looking at it. It's proving to be more challenging than expected.

Keep reading for what is going on and leave a comment if you have any ideas. I will keep updating this post. Cheers.


On the airport departure board project, the fact that the screen remained on even when nobody was there to admire its beauty was a bit frustrating to me. I knew I had to do something about that. The immediate solution was somehow to detect movement and activate the screen upon detection. It follows that I had to add a motion sensor to the system. This describes my adventure making that happen.


I selected a motion sensor that I got off Sparkfun years ago. It's this one and it's still available and no I don't get any kickback from steering you towards this product from this vendor.

The first thing I had to do was bypass the voltage regulator on the sensor board. That was highlighted to me on the excelent Sparkfun documentation for this sensor. The regulator turns the input voltage to 5V to supply the rest of the electronics. It, however, requires an input voltage greater than 5V (somewhere from 7 to 12 seems to be ok). If you give it 5V it will misbehave and guess what voltage I have available to supply it with? Yes, 5V coming from the pi.

The black wire is signal (you thought it was ground? Surprise, it isn't!), the brown wire is ground and the red wire is supply. You can see above that I removed the red wire and connected it to the output of the regulator, effectively feeding the circuit with my own 5V. Not to worry, it is a nice, regulated supply, courtesy of the pi.

I then connected the output of the sensor (remember, it's the black wire) to the pins in blue in this next picture (I'll talk about the pin marked in red later):
My test setup looked like this:

The IR LED you see at the bottom serves no purpose whatsoever other than to keep the sensor in place on top of the breadboard.

As I proceeded with my testing, I started to see the need for some kind of visual cue that the sensor was indeed detecting motion. I initially printed that information to the screen and it was fine but soon I wanted to be able to assess the readings without having any terminal window active. I then added a 5mm red LED with a 330Ohm current limiting resistor connected to pin 27 (the mystery is now solved for the red marker you can see on the picture of he pi pinout). I set it to switch on whenever motion was detected. It worked pretty well. 

In some cases, I had to completely shield the detector, see the next picture for my elegant solution. You can just about see the red LED on the left that switches on when movement is detected. Again, the IR LEDs are only there to keep the sensor housing in place.

The hardware is done, time now to go soft.


I could lie and say that programming this easy feature was a piece of cake but it wasn't. The main challenges I faced in order of increasing emotional pain were the following:

  1. false detection of positives. Something I thought I wouldn't again think about after the pandemic.
The picture above shows the output of my program. The arrows are pointing at the time intervals between false positives. Anyone can tell that what that means is that the screen never switches off because, annoyingly, at intervals shorter than the power off timeout, the sensor will say "wait, I see nothing but I'm still here".

Now you may ask if there's anything that can be done on software about this? I thought it could but quite frankly I'm loosing hope. This looks like a hardware thing, possibly related to the power supply and possibly to the hack of bypassing the on-board voltage regulator.

I watched this guy on YouTube tackling this issue with a different type of PIR sensor. He ended up adding some inductors and capacitors to the power connections but I still cannot believe I may end up having to do that.

The software as it currently is is available on my GitHub (everything that has *motion* on it is for this application). Everything works well except for you know what.

Last comments

I'm still working on this. I was taught to never give up even when I should. LOL, I've given up, it's got a button now instead.