Software developer here, trying to mess around with hardware (VERY NOVICE) and implement neat things around the house using ESP8266s and Arduinos.

I have a commercial wall plug that is activated when motion is detected, to turn on the light in my home office. I want to use that 24VDC signal to publish an MQTT message via ESP8266.

I connected to the relay inside the motion detector and it reads about 24.4VDC when motion is detected.

I read online about reducing voltage and used a voltage divider to bring the voltage down to a solid 3.26-3.3V.

On an ESP8266, I use the D1 pin, mode set to INPUT, sampled at 5Hz. It is powered via USB, connected to my laptop.

The problem is that when I connect that voltage-divided 3.3V signal to D1 on the ESP8266, instead of steady 1s I get a seemingly random mix of 1s and 0s...

So I measured the voltage between D1 and G on the ESP8266 and it is showing 1.57V.

I measured the voltage between the motion detector's ground and voltage-divided output and it's showing 12.6V instead of the original 3.3V.

As I said, I'm a software guy dabbling in hardware and this is some serious sorcery to me.

Attached is a crude schematic. Green numbers represent measurements AFTER the working 3.3V dashed line is connected to D1 on the ESP8266.

Any ideas would be greatly appreciated. Thank you in advance!


  • 2
    \$\begingroup\$ be very careful with any line powered appliance ... you may have 24.4 Vdc between two points in the circuit, but you may have line voltage between one of those points and earth ground \$\endgroup\$
    – jsotola
    Nov 30, 2019 at 4:00
  • \$\begingroup\$ You have many likely issues here. First, it's unclear that you've yet proven you actually have a 24v DC source. Meters don't really represent time domain behavior accurately. Next, you may need to proportionally scale the resistors in your divider to a lower value so that it will be "stiffer" in the face of minor loading by the board, for example there might be on-board pulling resistors. Finally note the D1 is traditionally a serial pin used to receive communication from a PC, which may be interfering with your hoped usage. And then indeed, there is the question of mains safety. \$\endgroup\$ Nov 30, 2019 at 5:13
  • \$\begingroup\$ I would suggest using an optocoupler. Choose a resistor value large enough to limit the current into the input LED, and wire the open-collector output to the ESP8266. \$\endgroup\$ Nov 30, 2019 at 6:58
  • \$\begingroup\$ Thanks guys. @ChrisStratton, i measured it in AC mode and it was reading 0.1V, the same as when i wasnt measuring anything so i think it is DC. Plus, the relay i tapped into is this one: conrad.com/p/…. \$\endgroup\$
    – Alex C
    Nov 30, 2019 at 18:03
  • \$\begingroup\$ Someone suggested that i need a common ground for motion detector and esp... I connected those grounds but the motion detector started to buzz like the relay inside it was rapidly going on and off... \$\endgroup\$
    – Alex C
    Nov 30, 2019 at 18:04

1 Answer 1


Thanks Caleb Reiser, I luckily had a 4N35 optocoupler lying around and I was able to get it up and running! I wasn't aware of their function before. Super cool! I can see it being useful in many cases.

One other gotcha was to add a pull-down resistor from the signal wire, to pull D1 to 0 when motion wasn't being detected, as it was staying high otherwise.



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.