[Solved] Detecting Doorbell AC With an Microcontroller For DIY Doorbell - Page 1
Forum section: electronics / beginners

author: shmuelzon
author_rank: Contributor
timestamp: May 21, 2022, 05:04:46 pm
content: Hey all,I'm trying to replace my existing doorbell buzzer with my own project running on an ESP32. I already have the audio/chime part working and I'm left with properly detecting the doorbell button press.I'd note that my current buzzer has 4 wires, 2 for 220v AC and another 2 routed from a 220v->12v transformer going through the button.For detecting the AC, I've went with Felix Rusu's solution of a zero-cross detecting opto-coupler, detailed here:https://lowpowerlab.com/2015/04/13/doorbell-moteino/I've attached the schematic of what I currently have and the PCB (yes, it's a mess).What I've noticed is that when I measure the circuit's output with a DMM (unfortunately, I don't have an oscilloscope) I read 0v when the button isn't pressed and 0.02v when it is although I expected to see ~3.3v there. If I also include the button's small light in parallel to the switch, it reads a lower voltage which I currently don't recall what it was, but it was an order of magnitude lower.Any ideas why I'm seeing such a low voltage there? Ideally, I want something high enough to register as a logic high.In my case, I'm removing the existing buzzer and I just need to detect the AC, maybe that can simplify things? I've also considered just connecting the doorbell wires to DC but I'm not sure the gauge nor length of the wires, so that might not work with a small power supply.If anyone has any other solutions instead of the above I'd also be happy to read them.Thanks in advance!

author: ledtester
author_rank: Super Contributor
timestamp: May 21, 2022, 05:14:59 pm
content: Try getting rid of the PNP and the cap and take the GPIO signal off of the collector of the NPN.Here's basically what I'm talking about:https://microcontrollerslab.com/el357-optocoupler-pinout-examples-features-applications-datasheet/#Zero_Crossing_Detection_Circuithttps://microcontrollerslab.com/el357-optocoupler-pinout-examples-features-applications-datasheet/#Microcontroller_Interfacing

author: BILLPOD
author_rank: Frequent Contributor
timestamp: May 21, 2022, 06:27:35 pm
content: Good Morning Shmuelzon, Most doorbells in my part of the world get their power from a 'Doorbell Transformer', which puts out approx. 20 volts AC, (mine is 19.3 VAC.) and they draw less than 500mA. Mine is between the floor joists in my basement.Look around and you will find yours.

author: james_s
author_rank: Super Contributor
timestamp: May 21, 2022, 06:59:55 pm
content: Your proposed solution should work fine. The gauge of the wires doesn't really matter as the current is very low, I would just use whatever size wire is used for the existing installation, here you can buy wire that is specifically sold for doorbell use.

author: shmuelzon
author_rank: Contributor
timestamp: May 22, 2022, 06:16:48 am
content: Thank you all for you responses!QuoteIf I do that, won't I just get high spikes at the AC's zero crossings? Suppose I handle that in software and act only on the first spike, what should I expect with the button's LED in parallel to the switch? Won't the optocoupler still act upon the AC? Or are we expecting the current to be low enough (with the 2x 10k ohm resistors near it and probably something similar near the LED) that it won't turn on the internal LEDs?QuoteI know where it is and, in my case, it's 12 VAC. It's location is exactly where I want to place my own since there's access to both 220VAC and the two wires going to the button outside, so it seems ideal.QuoteAny idea why it's not working well then? It suddenly dawned on me, do I need a pull-up on the GPIO?QuoteI don't want to change those wires, I was wondering if I can feed 3.3v from the microcontroller through the doorbell button instead of messing with AC at all. With my very limited understanding, I have a feeling that wont work with long wires. The button's LED probably won't work as well if it expects ~12V.

author: ledtester
author_rank: Super Contributor
timestamp: May 22, 2022, 06:37:52 am
content: Quote from: shmuelzon on May 22, 2022, 06:16:48 amWhen AC current is running through the optocoupler you will see a series of high-to-low transistions on the optocoupler collector and hence on the GPIO pin. With no AC current the voltage on the GPIO pin will remain high.QuotePlease provide a schematic of the button and LED you are talking about.Btw, there is something wrong with the wiring of the "Moteino Doorbell Detector/Automation" schematic... there is no way AC current will flow through the LED side of the optocoupler.

author: MadScientist
author_rank: Frequent Contributor
timestamp: May 22, 2022, 06:48:00 am
content: This circuit needs a pull down resistor on the input to the micro

author: Zero999
author_rank: Super Contributor
timestamp: May 22, 2022, 07:11:38 am
content: The base current is dependant on the current transfer ratio of the opto-coupler. If it's too high, the transistor can be damaged.Many of those components can be removed and it will still work. If you want active high, then swap the transistor and resistor.

author: ledtester
author_rank: Super Contributor
timestamp: May 22, 2022, 07:40:46 am
content: Quote from: ledtester on May 22, 2022, 06:37:52 amOkay I think I understand how the Moteino circuit is supposed to work... it seems to rely on the chime being able to return current from the optocoupler back to the AC node designated as "ground". When pressed the button shunts the optocoupler so it doesn't trigger anymore.It seems, though, a better idea would be to put the optocoupler in parallel with the chime.The PNP-capacitor configuration is still a head-scratcher - the flipped PNP notwithstanding. Once the optocoupler is triggered the cap will fill up and there's nothing to discharge it except perhaps the GPIO pin. But given that the opto is firing when the doorbell button is not pressed this means the MCU has to be constantly emptying the cap all the time to determine when the button is being pressed.Or am I missing something?EDIT: Ok, I guess the LED and 1.5K resistor will discharge the cap.

author: Zero999
author_rank: Super Contributor
timestamp: May 22, 2022, 10:47:57 am
content: Quote from: ledtester on May 22, 2022, 07:40:46 amYes, the LED and resistor will discharge the capacitor.It's a bad circuit. There's no need for that opto-coupler, since the MCU circuit and doorbell share the same 0V.

author: fordem
author_rank: Regular Contributor
timestamp: May 22, 2022, 12:23:14 pm
content: That just seems like a lot of unnecessary work - the door bell pushbutton is a simple normally open switch - disconnect it from the AC and wire it directly between a GPIO pin and ground.

author: themadhippy
author_rank: Super Contributor
timestamp: May 22, 2022, 01:22:23 pm
content: Quotewith a lamp in parallel with it,so you can see were the bell push is soQuoteaint gonna work

author: edavid
author_rank: Super Contributor
timestamp: May 22, 2022, 03:40:25 pm
content: Quote from: shmuelzon on May 22, 2022, 06:16:48 amYou are right about that, although you could place a filter cap at the NPN collector.QuoteYou are correct that the lighted button is a problem. (BTW, most doorbell buttons just use an incandescent lamp rather than an LED.) The fix for that is to place a shunt resistor across your sensing circuit so the lamp current won't produce enough voltage to turn on the opto, but the chime current will.QuoteHe was referring to your idea of replacing the transformer with a DC supply.For the PNP circuit, you need a pull-down, not a pull-up.QuoteIt would work fine with long wires. You would need to replace the lighted button with a plain one. Of course if you are doing this, maybe it would be just as well to use a wireless doorbell.

author: shmuelzon
author_rank: Contributor
timestamp: May 23, 2022, 07:25:21 pm
content: Thanks again for all the responses! Unfortunately, I'm too dense to understand what to do next... All of my experience so far was mainly digital logic, soFrom what I gather, since I want the little bulb/LED in the push button to work, I need to continue with the AC/Optocoupler path.I don't really care whether the AC detector will be be active high or low, I can work with both. Also, the original chime/buzzer that once was connected in series with the button will be removed since I'll play the audio with the microcontroller.With the original PNP circuit, I still don't understand why the "high" voltage was so low. Was it because I have two 10k resistors on the AC side? Does that lower the current through the optocoupler which, in turn, affects the internal transistor?If I go with Zero999's solution and drop the PNP (and the pull-down is already a part of the schematic) will I just see pulses when AC is detected?To overcome the light that's in circuit, I need the shunt resistor on the AC side? Basically, in parallel to the optocoupler? Wouldn't current always flow through it and not the optocoupler, even if the button is pressed? I think I'm missing something...

author: edavid
author_rank: Super Contributor
timestamp: May 23, 2022, 08:05:25 pm
content: First of all, why don't you tell us what you are trying to accomplish? Are you just reinventing the wireless doorbell?Quote from: shmuelzon on May 23, 2022, 07:25:21 pmIt could be that, but you have to tell us the part number of your optocoupler.Otherwise, it could be a bad part or a wiring error. If you remove the PNP, what's the optocoupler output voltage?QuoteYes, unless you put the filter capacitor back.QuoteMeasure the current that flows through the lamp in the button, then size the shunt resistor so the voltage across it is less then the optocoupler's turn on voltage.Let's say the lamp current is 50mA. You could use a shunt resistor of up to 20 ohms, and the voltage across it would be less than 1.0V, which won't turn on the optocoupler.But then you would want to measure the current drawn by the chime, and make sure the resistor wasn't dropping too much voltage at that current.If you remove the chime, you'll have to replace it with a resistor that will cause enough current to flow that the voltage across the shunt resistor will turn on the optocoupler. In that case you would have a lot more flexibility in choosing the shunt value.

author: ledtester
author_rank: Super Contributor
timestamp: May 23, 2022, 08:05:42 pm
content: Quote from: shmuelzon on May 21, 2022, 05:04:46 pmCan you clarify the relationship between the button and the light? What kind of light is it? Is it illuminated all the time or only when the button is pressed?

author: shmuelzon
author_rank: Contributor
timestamp: May 23, 2022, 08:48:07 pm
content: QuoteRight, so the idea was to take the existing doorbell I have in my apartment and replace it the current buzzing sound it does with a nice chime. Then I figured, I could have it do a bit more and change/randomize the actual sound that's played or just use it as a speaker connected to a home automation system.I wanted it to be a drop in replacement of the unit I have inside my house (looks something likehttps://eitanbraha-blogspot-com.translate.goog/2012/12/blog-post_8.html?_x_tr_sl=iw&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp). I want to use the existing wiring between this unit and the push button placed outside the door (looks something likehttps://www-waisbord-co-il.translate.goog/items/2463922-%D7%9C%D7%97%D7%A6%D7%9F-%D7%A4%D7%A2%D7%9E%D7%95%D7%9F-%D7%9E%D7%95%D7%90%D7%A8?_x_tr_sch=http&_x_tr_sl=iw&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp). That button has a small light that's on by default so it can be found in the dark. The light is in parallel to the switch and once the switch is pressed, it turns off and the buzzer is activated.QuoteThe chime is no longer connected to the AC wiring and the sound is produced by the microcontroller with it's own DC supply from the main 220VAC.QuoteAren't those basically the two 10k resistors I have near the optocoupler?QuoteThe optocoupler I'm using is a LTV814H.

author: ledtester
author_rank: Super Contributor
timestamp: May 23, 2022, 08:48:51 pm
content: Here's what the inside of my doorbell switch looks like:

author: edavid
author_rank: Super Contributor
timestamp: May 23, 2022, 10:27:57 pm
content: I've attached a sketch.RS = shunt resistor; should have less than 1V drop with only lamp current flowingRL = load resistor; choose so RS has greater than 3V drop with button pressedRLED = LED current limit; choose for OI LED current 5-10mA with switch closed

author: james_s
author_rank: Super Contributor
timestamp: May 24, 2022, 01:27:53 am
content: That looks like a non-lighted button, they're not uncommon, the lighted variety is the same except for a small lamp, these days probably an LED and resistor wired across the button.

author: BeBuLamar
author_rank: Super Contributor
timestamp: May 24, 2022, 01:57:37 pm
content: Can you just use only the switch. Get rid of all the other old stuff.

author: eugene
author_rank: Frequent Contributor
timestamp: May 24, 2022, 11:46:58 pm
content: Quote from: shmuelzon on May 23, 2022, 08:48:07 pmIn the simplest form an old school doorbell is just a transformer, chime, and push button in series. When you press the button it closes the circuit and current goes through the chime.Lighted buttons have a bulb in parallel with the switch. So how does the bulb light up? The answer is that it gets power through the chime. The bulb has some resistance, I don't know how much, but it's enough to limit the current through the chime so that the chime isn't constantly energized. When you press the button it shorts the bulb and allows a large current to energize the chime and make it ring. Notice how the bulb goes out when you press the button? That's not a user interface feature; it's a consequence of how the bulb is wired up.When you removed the chime you removed the source of power to the bulb. When you added the optocoupler you provided a different path for current to light the bulb, but it has 2x10k resistance plus the LED(s) in the optocoupler, all in series with the bulb. That's why the bulb is so dim.To restore the brightness of the light, you could replace the chime in the circuit with a resistor. Use your DMM to measure the resistance of the chime. It's probably in the neighborhood of 10 to 50 ohms. For the sake of discussion, let's assume it's 12 ohms. OK, suppose you wire the resistor into the circuit where the chime was. When the button isn't pressed it supplies current to the bulb. When the button is pressed it has 12V across it. That means there will be 1A of current going through it and it will dissipate 12W of power! So you would need a really big power resistor.One reasonable option is to leave the chime wired up, but remove some part of it so that it doesn't make any noise. Removing the plunger comes to mind. That's the part that flies out and hits one of the bells when energized, then flies back and hits the other bell when power is removed. You could also remove the bells. In the that case the plunger might fall out anyway.Another solution is to modify a lighted button to work on a lower voltage, ideally 3.3V or a little less. As already noted, most lighted doorbell buttons use an incandescent bulb that requires 12V to 20V, but you can replace that with a LED. You can buy LEDs with 3.1V forward voltage drop, then you don't even need to add a current limiting resistor, but they tend to be bright and directional.This onewould probably work, though I haven't tried it.I've added photos of a new (but very inexpensive) button that I happened to have and disassembled. Notice that it uses a single sided PCB and a bulb with leads. I could easily remove the bulb and replace it with a common 3mm LED. If a current limiting resistor is needed, I would cut a narrow slot across one of the two traces, scratch away some of the solder mask around the slot, then solder in a surface mount resistor across it. You could do something similar with a leaded resistor.Now, with the addition of a pull-up resistor, you can use the button directly as shown below. The pull-up resistor and the current limiting resistor need to be sized carefully so that there is no more than 3.3V at the GPIO pin when the button isn't pressed. Your ESP32 might be destroyed if you apply more than 3.3V to any of its pins. In the diagram below, I show a 100 ohm pullup to drop 1.8V with 18mA. If you pull up to something other than 5V then you would need a different size resistor. The size of the current limiting resistor depends on the forward voltage drop of the LED and the amount of current you want to pass through it.

author: james_s
author_rank: Super Contributor
timestamp: May 25, 2022, 12:17:45 am
content: A really simple solution is to use a mechanical relay in place of the optocoupler, that will be electrically very similar to the solenoid coil in the original doorbell and will avoid the challenges posed by an illuminated button.

author: edavid
author_rank: Super Contributor
timestamp: May 25, 2022, 12:39:48 am
content: Quote from: james_s on May 25, 2022, 12:17:45 amIt's a little tricky to find an AC relay with the right pullin voltage.

author: eugene
author_rank: Frequent Contributor
timestamp: May 25, 2022, 01:03:06 am
content: Quote from: james_s on May 25, 2022, 12:17:45 amBrilliant! Though it would need to be close enough to the chime in both operating voltage and coil resistance.If being resourceful makes you feel good, you could turn the chime into a relay. Remove the bell(s) and mount a push button switch that gets pressed by the solenoid plunger. A solution like this has the advantage that you don't need to tap into the existing electrical system at all. (That might be an advantage to renters.) It's conceivable that modifications to the chime could be simple and completely reversible.

author: vk6zgo
author_rank: Super Contributor
timestamp: May 25, 2022, 02:13:03 am
content: Quote from: fordem on May 22, 2022, 12:23:14 pmOr just rectify the switched 12v ac, filter it a bit, (you don't want the cap too big or it won't turn off), turn an optocoupler on with it, & use the output transistor of that device to switch 3.3v to the PIC, or whatever.It's not as if it has to be a fast detection of the switch function.Another way, if you can get at the transformer, is to rectify & properly filter the 12v ac prior to the switch.

author: james_s
author_rank: Super Contributor
timestamp: May 25, 2022, 03:56:09 am
content: Quote from: edavid on May 25, 2022, 12:39:48 amHow hard can it really be? You do need either an AC relay or a bridge rectifier and DC relay, and you'll want it to be approximately close to the doorbell voltage, but given the extremely low duty cycle it shouldn't really matter. I would bet that just about any random junkbox relay would work with the rectifier approach. A conventional doorbell coil will burn out if the button is held down indefinitely, it doesn't matter if the relay would too.

author: antenna
author_rank: Frequent Contributor
timestamp: May 25, 2022, 04:48:11 am
content: Even simpler, rectify the AC and use the resultant DC, whatever voltage, through a resistor and 5v zener diode (or two red LEDs) and take the signal voltage right off the diode. The diode regulates to logic level. Or is the common-mode on the doorbell wire an issue?

author: james_s
author_rank: Super Contributor
timestamp: May 25, 2022, 06:39:38 am
content: Quote from: antenna on May 25, 2022, 04:48:11 amThe issue, which has been discussed at length here is the lamp that is wired across an illuminated button. That will cause the LEDs you suggest to glow at all times whether the button is pressed or not.

author: shmuelzon
author_rank: Contributor
timestamp: May 25, 2022, 06:58:28 am
content: QuoteI must say, the AC relay sounds very tempting to me, thanks for that!Does this look like something that would be suitable?https://www.amazon.com/Baomain-Power-Relay-PTF08A-Socket/dp/B00YTW5Q0EI seems, from the reviews, that others have used it for their doorbells as well.

author: BeBuLamar
author_rank: Super Contributor
timestamp: May 25, 2022, 09:23:45 am
content: What if you just use the switch only? No transformer not 220VAC. The switch is the same as the relay.

author: eugene
author_rank: Frequent Contributor
timestamp: May 25, 2022, 02:18:58 pm
content: Quote from: shmuelzon on May 25, 2022, 06:58:28 amMeasure the DC resistance of the solenoid winding in the chime. Find AC relay with similar coil resistance and 12V operating voltage. The coil resistance is always stated in the relay data sheet and often in the sell sheet. If it's not listed, then move along.EDIT: theOmron datasheetfor the LY2N-AC12 shows the coil resistance to be 46 ohms. The part on Amazon is a different manufacturer, but it's probably a copy of the Omron part, so likely similar.

author: antenna
author_rank: Frequent Contributor
timestamp: May 25, 2022, 05:37:26 pm
content: Quote from: james_s on May 25, 2022, 06:39:38 amThen why not just add a load resistor to replace the return path the doorbell coil offered? The button light will still work and you can sample across that load resistor with your diode network (which, while the button is not pressed, has a voltage drop across it too small to make it through the zener). Just make the return path resistor 1/10 the resistance of the lamp, then take the output from that resistor and do what I suggested. A common theme on this forum is to "just throw IC chips or a microcontroller at it". That is not always the answer.

author: james_s
author_rank: Super Contributor
timestamp: May 25, 2022, 06:12:55 pm
content: Quote from: eugene on May 25, 2022, 02:18:58 pmIMHO that is overthinking things. Doorbell coil resistance varies widely, it is just not critical at all. You have an unregulated transformer, a button and a coil, often the button has a small lamp across it. The duty cycle is extremely low, you could probably overdrive a relay coil by a factor of 10 and it would still last decades. I wouldn't even bother calculating, I'd just hook something up and see if it works.

author: eugene
author_rank: Frequent Contributor
timestamp: May 25, 2022, 07:47:38 pm
content: You are correct that I'm probably overthinking it. The coil resistance will have only a minor effect on lamp brightness. With the optocoupler out of the way, almost any 12VAC relay would probably work well enough.

author: rob77
author_rank: Super Contributor
timestamp: May 25, 2022, 08:13:44 pm
content: Quote from: BeBuLamar on May 25, 2022, 09:23:45 amthat's not possible in many cases... for example if you have a door bell with intercom and remote door opening.. the system sends you 12 or 18V AC to ring the bell.. you have to either detect it or use it with an AC relay or rectify it and use the voltage..i wanted to have a secondary doorbell in a room where my doorbell is not audible.. so bought a cheap wireless doorbell, shorted the remote button and instead of a 12V battery (23A size) connected the rectified 12V from the doorbel wires , works perfectlycommon mode voltage is not a issue because it's wireless

author: BeBuLamar
author_rank: Super Contributor
timestamp: May 25, 2022, 08:19:38 pm
content: Quote from: rob77 on May 25, 2022, 08:13:44 pmBut in the OP situation he has no wireless remote. I am sure the switch alone can be used to trigger whatever contraption he came up with.

author: aargee
author_rank: Frequent Contributor
timestamp: May 26, 2022, 03:02:44 am
content: Not really sure if this fits, but...On our doorbell, I replaced the bulb with an LED and dropping resistor. The doorbell switch shorted the LED when pressed, the sense is on the anode of the LED which sent a Low to the doorbell circuit.It is simple and works at my place.

author: shmuelzon
author_rank: Contributor
timestamp: June 14, 2022, 01:09:31 pm
content: Hey all,Just wanted to update that the AC relay solution works perfectly with the illuminated push button.Thank you all for your help!