I have a raspberry pi 3b+ and a haunted house.

My raspberry pi sits in the living room tv cabinet (with adequate ventilation) as a server. I had a large button lying around, so i put it inside a small lego box & hooked it up to the pi as shown here: enter image description here The button worked great! I had it call a webhook from my hubitat to turn on some lights in the room. Then, one day, I changed the speed of my ceiling fan from high to medium. And suddenly, the lights came on. I looked in the hubitat logs, and the webhook had been called. Every single time i change the ceiling fan (7 ft away line of sight) speed from high to medium (and ONLY when it goes from high to medium), the webhook is called, like clockwork. If you are wondering, the python was detecting gpio.rising via callback. I changed it to falling with no luck. Then, i though the pull down resistor wasnt strong enough (the wires were 3 feet long in a C-shape), so i added a 10k external pull down resistor: enter image description here Still, the fan still triggered the button. So i changed the resistor with an unnecessarily strong 1k resistor, yet nothing happened. Finally, in a last ditch attempt, i tried keeping the line pulled up and having the button ground it (i got a bit lazy - hence the unnecessary resistors i didnt remove: enter image description here I thought to myself, "surely a line pulled high cant be affected by emf." Yet, the issue persisted with no change. In this mode, i set it to detect falling. Finally, as a last ditch attempt, i tried switching out the power brick (which sits on a surge protector). And - you guessed it - nothing happened. My button is still fully functional - yet is TOO functional, somehow wirelesly communicating via emf, interference, or arcs, vausing the button to trigger.

Here are some little details that might help:

  • The pi & fan are on different breakers
  • We do NOT have arc fault circuit breakers (i live in USA)
  • The rpi has a fully functional DHT11 sensor connected to other gpio pins.
  • To connect to the button, i am using solid core 24 awg wire.
  • i have 3 buttons that run through the wall to an esp8266 in the basement. The wires (inside a wall) also have a close proximity to the fan, yet never once have they gotten activated due to the fan
  • I have zigbee bulbs in the fan's light sockets
  • The button i am using is the button found in the google aiy kit.
  • My bouncetime argument is 900 ms

Thanks in advance for all you help trying to remove this electrical ghost from my house - its downright creepy that the fan is linked like clockwork to the button. It also means i have to disable the button, which family has gotten used to

3 Answers 3


As Milliways suggests this is almost certainly caused by long wires picking up EMF.

The simplest solution is to debounce the GPIO.

Be aware that the RPi.GPIO bouncetime parameter has nothing to do with debounce. It should be called ignore time as its purpose is to ignore all subsequent level changes for a period of time.

I suggest you add a short sleep in your callback and then read the GPIO again to check that the level has really changed.

  • About how long should this delay be? 100 ms? Thanks. Does this also mean i can eliminate or reducw the 900 ms debounce in the callback? Thanks in advance. Commented Mar 5, 2022 at 14:25
  • 1
    The 900 ms "debounce" in the callback setup achieves nothing - it can be deleted. A 1 ms delay before reading the GPIO may be enough (the typical length of an EMF pulse is unknown to me).
    – joan
    Commented Mar 5, 2022 at 16:18
  • I added a 100 ms delay before re-checking the switch, and now it works. Thanks! My house isnt haunted anymore :) Commented Mar 5, 2022 at 21:56
  • @anonymous adding delays (by whatever means) and multiple sampling will help with spurious short lived events but do nothing to prevent interference. Low impedance circuits and/or shielding are the traditional engineering solutions to prevent the problem,
    – Milliways
    Commented Mar 8, 2022 at 10:42
  • @Milliways i already tried a pulldown - the emf (im suspecting it was caused by a mini-arc in the fan speed controller) still came. So now i am using the pi’s internal pullup & no issues, even with the strong emf. Commented Mar 8, 2022 at 13:24

Those (like me) who prefer a simple hardware solution to a simple software solution can take a clue from a comment to the accepted answer: the 100 msec delay did the trick.

In "hardware world", one would think of a low pass filter (LPF) as a solution to the OP's problem. Here's a simple R-C low-pass filter on the left, and a graph of voltage vs. time on the right, where time is expressed in terms of a time constant τ:

Low-Pass Filter RC Time Constant
low-pass RC filter rc time constant

The RC time constant (τ) is calculated simply :

τ = R x C

and the chart illustrates the transient response of the LPF to a high-frequency input.

Imagine that vin for the circuit above is a high-frequency pulse generated on the wiring connected to the GPIO input. The RC filter effectively slows that waveform: Before reaching the GPIO pin, the induced current must flow through the resistor, and charge the capacitor to some voltage. The RC time constant chart shows us how long it takes to charge the capacitor to 100 percent of vin as a function of τ. Larger values of R or C will increase that charging time, effectively "raising the bar" for high frequency noise. Said another way, the RC filter reduces the high frequency impedance of your RPi input, but has little effect on the low frequency inputs.

One could say that the hardware-based RC low pass filter, and the software-based delay/ignore timer perform the same function in different ways. Which one makes the "best" solution depends upon the circumstances. Either one may work in many cases, but it's often useful to have an extra tool at hand. To design an RC LPF with a 100 msec time constant is easy enough:

Choose a value for R or C, and calculate the other one. If we chose a 10K𝝮 R for a τ of 100msec:

C = τ / R; C = 100msec / 10K = 10 uF

Replace your 220𝝮 R with a 10K𝝮 & add a Cap from the GPIO input to Ground. Place the capacitor as close as possible to the GPIO pin for best results.


It is difficult to understand what you have actually done but it appears you have connected long antennas to GPIO pins.

Try using a conventional circuit (with a low ~1k pullup) and connect switch to Gnd. Forget internal pullup.

  • I already tried a high circuit (3.3v) with a 1k pulldown and this did nothing, so i highly doubt that this would work. @Joan also seems to have a solution which applies to all of these. Commented Mar 5, 2022 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.