Author Topic: [Solved] Detecting Doorbell AC With an Microcontroller For DIY Doorbell  (Read 2982 times)

0 Members and 2 Guests are viewing this topic.

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 11
  • Country: il
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!
« Last Edit: June 14, 2022, 01:10:02 pm by shmuelzon »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
« Last Edit: May 21, 2022, 05:30:04 pm by ledtester »
 

Offline BILLPOD

  • Regular Contributor
  • *
  • Posts: 246
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #2 on: May 21, 2022, 06:27:35 pm »
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. :popcorn:
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #3 on: May 21, 2022, 06:59:55 pm »
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.
 

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 11
  • Country: il
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #4 on: May 22, 2022, 06:16:48 am »
Thank you all for you responses!

Quote
Try getting rid of the PNP and the cap and take the GPIO signal off of the collector of the NPN.
If 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?

Quote
Look around and you will find yours
I 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.

Quote
Your proposed solution should work fine
Any idea why it's not working well then? It suddenly dawned on me, do I need a pull-up on the GPIO?

Quote
The gauge of the wires doesn't really matter as the current is very low
I 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.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #5 on: May 22, 2022, 06:37:52 am »
Thank you all for you responses!

Quote
Try getting rid of the PNP and the cap and take the GPIO signal off of the collector of the NPN.
If I do that, won't I just get high spikes at the AC's zero crossings?
When 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.

Quote

 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?

Please 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.
« Last Edit: May 22, 2022, 06:49:14 am by ledtester »
 

Offline MadScientist

  • Frequent Contributor
  • **
  • Posts: 439
  • Country: 00
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #6 on: May 22, 2022, 06:48:00 am »
This circuit needs a pull down resistor on the input to the micro
EE's: We use silicon to make things  smaller!
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #7 on: May 22, 2022, 07:11:38 am »
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.
« Last Edit: May 22, 2022, 07:13:10 am by Zero999 »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #8 on: May 22, 2022, 07:40:46 am »
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.

Okay 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.

« Last Edit: May 22, 2022, 07:45:40 am by ledtester »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #9 on: May 22, 2022, 10:47:57 am »
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.

Okay 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.
Yes, 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.
« Last Edit: May 22, 2022, 11:09:34 am by Zero999 »
 

Offline fordem

  • Regular Contributor
  • *
  • Posts: 234
  • Country: gy
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #10 on: May 22, 2022, 12:23:14 pm »
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.
 

Offline themadhippy

  • Super Contributor
  • ***
  • Posts: 2567
  • Country: gb
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #11 on: May 22, 2022, 01:22:23 pm »
Quote
the door bell pushbutton is a simple normally open switch -
with a lamp in parallel with it,so you can see were the bell push is so
Quote
wire it directly between a GPIO pin and ground.
aint gonna work
 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #12 on: May 22, 2022, 03:40:25 pm »
Quote
Try getting rid of the PNP and the cap and take the GPIO signal off of the collector of the NPN.
If I do that, won't I just get high spikes at the AC's zero crossings?
You are right about that, although you could place a filter cap at the NPN collector.

Quote
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?
You 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.

Quote
Quote
Your proposed solution should work fine
Any idea why it's not working well then? It suddenly dawned on me, do I need a pull-up on the GPIO?
He 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.

Quote
I 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.
It 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.
 

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 11
  • Country: il
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #13 on: May 23, 2022, 07:25:21 pm »
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, so  :-//

From 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...
 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #14 on: May 23, 2022, 08:05:25 pm »
First of all, why don't you tell us what you are trying to accomplish?  Are you just reinventing the wireless doorbell?

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?

It 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?

Quote
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?

Yes, unless you put the filter capacitor back.

Quote
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...

Measure 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.
« Last Edit: May 23, 2022, 08:24:20 pm by edavid »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #15 on: May 23, 2022, 08:05:42 pm »
... If I also include the button's small light in parallel to the switch ...

Can 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?
 

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 11
  • Country: il
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #16 on: May 23, 2022, 08:48:07 pm »
Quote
First of all, why don't you tell us what you are trying to accomplish?  Are you just reinventing the wireless doorbell?
Right, 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 like https://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 like https://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.

Quote
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.
The 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.

Quote
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
Aren't those basically the two 10k resistors I have near the optocoupler?

Quote
It could be that, but you have to tell us the part number of your optocoupler
The optocoupler I'm using is a LTV814H.
« Last Edit: May 23, 2022, 08:58:36 pm by shmuelzon »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #17 on: May 23, 2022, 08:48:51 pm »
Here's what the inside of my doorbell switch looks like:

1494331-0

 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #18 on: May 23, 2022, 10:27:57 pm »
I've attached a sketch.

RS = shunt resistor; should have less than 1V drop with only lamp current flowing
RL = load resistor; choose so RS has greater than 3V drop with button pressed
RLED = LED current limit; choose for OI LED current 5-10mA with switch closed
« Last Edit: May 23, 2022, 10:29:33 pm by edavid »
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #19 on: May 24, 2022, 01:27:53 am »
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.
 

Offline BeBuLamar

  • Super Contributor
  • ***
  • Posts: 1188
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #20 on: May 24, 2022, 01:57:37 pm »
Can you just use only the switch. Get rid of all the other old stuff.
 

Offline eugene

  • Frequent Contributor
  • **
  • Posts: 493
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #21 on: May 24, 2022, 11:46:58 pm »

Quote
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
Aren't those basically the two 10k resistors I have near the optocoupler?


In 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 one would 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.

90% of quoted statistics are fictional
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #22 on: May 25, 2022, 12:17:45 am »
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.
 
The following users thanked this post: shmuelzon

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #23 on: May 25, 2022, 12:39:48 am »
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.

It's a little tricky to find an AC relay with the right pullin voltage.
 

Offline eugene

  • Frequent Contributor
  • **
  • Posts: 493
  • Country: us
Re: Detecting Doorbell AC With an Microcontroller For DIY Doorbell
« Reply #24 on: May 25, 2022, 01:03:06 am »
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.

Brilliant! 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.
90% of quoted statistics are fictional
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf