AC doorbell signal

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

AC doorbell signal

Post by kevinkk525 » Sun Aug 09, 2020 3:44 pm

The doorbell in our new appartment has an AC signal so it can power some LEDs inside the switches. If the switch is pressed, the signal is shorted to a "common ground" (not sure what exactly this is, it might be the neutral wire of the AC transformator and not the general ground). The voltage measured by my multimeter is ~4V AC.

Now I'd like to connect an ESP to it so I can send a mqtt message whenever someone's at the door but I'm not sure how to best read the signal.
After some research I came up with 2 possible solutions:

1) Using an AC optocoupler PC814 (not PC187 as shown in the schematics):
Unbenannt.PNG
Unbenannt.PNG (14.96 KiB) Viewed 3431 times
Advantage: Doorbell signal and ESP power circuit are properly separated.
Disadvantage: Because there is always an AC signal, the resistor has a sustained current of ~50mA leading to at least 150mW of heat (depending on the actual voltage of the signal, I'm not sure about the measured 4VAC, looks strange to me).

2) Using Schottky and voltage divider
Unbenannt2.PNG
Unbenannt2.PNG (10.69 KiB) Viewed 3431 times
Advantage: I probably have all the components at home :D Almost no current flowing.
Disadvantage: Circuits are not separated, ground between ESP and doorbell signal would need to be connected (and doorbell signal might not have a proper ground)

Can anyone help me a little bit with some advice on how to do this properly?
Last edited by kevinkk525 on Mon Aug 10, 2020 4:53 am, edited 2 times in total.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: AC doorbell signal

Post by pythoncoder » Sun Aug 09, 2020 4:02 pm

Unless you are sure that there is a common ground (and you say you are not) the second solution is very dubious. Connecting neutral to earth (at least on UK wiring) is positively dangerous. Go for the opto isolator.

Considering that solution I'm not sure where your 50mA comes from. 4V RMS across IKΩ is 4mA RMS. The actual will be less:

a) because the LED only conducts for one half cycle reducing it to 2mA.
b) The LED drops 1.2V reducing it further.
c) presumably the signal only occurs when the button is pressed.

If you are concerned about the current from the 3V3 supply, the 1kΩ resistor could be increased to 10KΩ.

Or am I missing something?
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: AC doorbell signal

Post by pythoncoder » Sun Aug 09, 2020 4:13 pm

A couple of further thoughts now I've looked at the opto datasheet.

Given that you're unsure about the waveform you might want to protect the LED against reverse voltage (it's only rated to 6V). I would suggest a series diode and a shunt resistor across the isolator LED (maybe 100KΩ but completely non-critical).

Secondly the current transfer ratio is only 80%. I would definitely go for 10KΩ on the 3.3V side to guarantee a hard turn-on.
Peter Hinch
Index to my micropython libraries.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: AC doorbell signal

Post by kevinkk525 » Sun Aug 09, 2020 6:14 pm

pythoncoder wrote:
Sun Aug 09, 2020 4:02 pm
[...] Go for the opto isolator.

Considering that solution I'm not sure where your 50mA comes from. 4V RMS across IKΩ is 4mA RMS. The actual will be less:

a) because the LED only conducts for one half cycle reducing it to 2mA.
[...]
c) presumably the signal only occurs when the button is pressed.
Thank you for your quick answer!

Yeah I was very concerned about connecting the common ground and would like to avoid that at all costs. Too much could go wrong there.

The 50mA were from the datasheet of the optocoupler but you are right, with a 1kR resistor that is of course not correct. My mistake. The signal occurs all the time and is shorted to ground when the button is pressed. But with 4mA RMS this should be no problem as it is only around 16mW.

The PC814 is actually an AC optocoupler with 2 diodes so the full cycle can be used. (the schematics is posted have it wrong but in the datasheet there's a correct picture of the optocoupler)
pythoncoder wrote:
Sun Aug 09, 2020 4:13 pm
Given that you're unsure about the waveform you might want to protect the LED against reverse voltage (it's only rated to 6V). I would suggest a series diode and a shunt resistor across the isolator LED (maybe 100KΩ but completely non-critical).
So I guess this isn't needed since there are already 2 diodes in the optocoupler?


Edit: Realized that I wrongly used the PC817 in my post because it is what LTSpice had but I meant to use the PC814 which is an AC optocoupler with 2 diodes.
Last edited by kevinkk525 on Mon Aug 10, 2020 4:52 am, edited 2 times in total.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: AC doorbell signal

Post by pythoncoder » Mon Aug 10, 2020 4:46 am

I can't find any data on the PC184 but from your description it sounds like you are right about the AC side of the circuit.
Peter Hinch
Index to my micropython libraries.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: AC doorbell signal

Post by kevinkk525 » Mon Aug 10, 2020 4:51 am

Thanks for the confirmation. Here's the data by the way: https://datasheet.octopart.com/PC814X-S ... 120760.pdf

It's the PC814 not PC184... sorry.. was late yesterday :roll:
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: AC doorbell signal

Post by pythoncoder » Mon Aug 10, 2020 5:21 am

Given the transfer characteristics I'd still go with 10KΩ on the DC side. The dark current is 100nA so you'll only get an offset of 1mV on the GPIO.

You will get pulses when the LED goes off near the zero crossings. You can either handle those in code or with a simple CR network between the opto coupler and the I/O pin. I can give you some pointers if you want to use a hardware filter.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: AC doorbell signal

Post by Roberthh » Mon Aug 10, 2020 6:15 am

With both the ESP32 and ESP8266 I have seen multiple triggers of an ISR if the input signal has a slow slope, with slow meaning > 10µs for the transition. So either you have to compensate for that with code or you have to add a external slope shaping, like a schmitt-trigger gate.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: AC doorbell signal

Post by kevinkk525 » Mon Aug 10, 2020 7:33 am

Thanks for your answers.
Yes I will go for 10kR on the DC side then.

I could handle multiple interrupts with a debounce of a few ms. Haven't thought about using hardware to stabilize it.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: AC doorbell signal

Post by pythoncoder » Tue Aug 11, 2020 5:56 am

Roberthh wrote:
Mon Aug 10, 2020 6:15 am
With both the ESP32 and ESP8266 I have seen multiple triggers of an ISR if the input signal has a slow slope, with slow meaning > 10µs for the transition. So either you have to compensate for that with code or you have to add a external slope shaping, like a schmitt-trigger gate.
Interesting, I did wonder about that. Best done in code, then.

@kevinkk525
You've probably figured that a standard debouncer won't work as it assumes the bouncing will stop after a period. But I'm sure you can write uasyncio code that triggers an event on a high to low transition and clears it when the input stays high for a period. An application for the Delay_ms class?
Peter Hinch
Index to my micropython libraries.

Post Reply