1

I have a cheap wireless doorbell. My plan is to include an ESP8266 and power the doorbell from the microcontroller 3.3V output as the doorbell also runs on 3V

I specifically chose a model with a LED, as I thought it should be easy to use the LED as a trigger on the ESP8266 and consume as a digital input.

I've soldered two wires from the LED positive and negative solder points. What I find strange is that I measure 3V between the PCB ground and the positive LED wire when the doorbell is not triggered. If I measure between the negative LED wire and positive LED wire, I see a voltage spike corresponding to each LED flash (it flashes 5 times). I plan to debounce this in software.

I did not expect to measure a voltage when the doorbell is not triggered between the positive LED wire and the PCB ground, and this will definitely not work as I intended.

Disclaimer: I'm not an electronic engineer, and my test equipment consists of a multimeter.

I've included a photo of the PCB. It is labelled "QH-823A-19" but searching for this on the Internet has provided no usable information.

What have I tried?

  1. I've tried to trace the tracks running to the LED solder points, but the tracks run under some components which makes this hard
  2. I've tried to measure different points on the board for a positive 3V spike when the LED flashes, no success

Any advice on how to achieve this? Am I going about this the wrong way?

enter image description here

11
  • The LED will be wired so that the anode is connected to +3V and the cathode is connected to the MCU's output pin. Set to HIGH the LED is off, and set to LOW it's on. This is common since historically microcontrollers have been able to sink more current than they can source, and it may be that this one has a specific current limited pin for driving an LED to reduce the number of external components required.
    – Majenko
    Jul 22, 2021 at 13:44
  • I measured the voltage between the cathode wire and the PCB ground. It reads as high when the LED is not on, but pulses to LOW when the LED starts flashing Unless I am misunderstanding you, I don't actually want to switch the LED on from the MCU, but rather, detect from the MCU when the LED is ON. I am thinking then that perhaps I can set the input high and detect when it goes low?
    – Will777
    Jul 22, 2021 at 13:55
  • Consider tossing away the store bought door bell kit as the ESP processors normally have build with WIFI radios PCB antennas allowing them to connect to your house network directly. If battery operated, the WIFI option can be replaced by an ESP-NOW network with a software change to the ESP code. But you will then need to create some sort of mains powered ESP-NOW to WIFI bridge somewhere in your house.
    – st2000
    Jul 22, 2021 at 13:55
  • "I measured the voltage between the cathode wire and the PCB ground. It reads as high when the LED is not on, but pulses to LOW when the LED starts flashing"... so @Majenko is correct. Actually, it should read 3.3V - the LED diode voltage drop. So maybe 2.5V when high.
    – st2000
    Jul 22, 2021 at 13:56
  • You may want to feed the signal through a comparator to ensure that it gets high enough to register as a HIGH on the ESP. Either that or use an analog input to read the voltage, which won't mind if it's not high enough to be HIGH, since you can define your own threshold in software then.
    – Majenko
    Jul 22, 2021 at 13:59

2 Answers 2

1

Your LED is connected between V+ and the GPIO of the microcontroller. This is a common arrangement because historically microcontrollers have been able to sink more current than they can source. It's also easier to make a "low side" constant current source, which this custom chip may have, to reduce the number of external components needed.

To read the state you need to take the voltage at the cathode of the LED referenced to the ground of the doorbell circuit. This will give you a voltage at or near the board supply voltage when the LED is off, and a lower voltage (near zero but probably not zero) when the LED is on.

If the voltages are within the threshold voltages VIH and VIL of the ESP8266 then you can just directly read that level as a logic level. If not then you may need to "condition" the voltage to give proper logic levels.

For example you could use a comparator (an op-amp running in "saturated" mode) to compare that voltage to a single threshold voltage that is roughly half way between the HIGH and LOW voltages. That would then swing the output between the supply and ground voltage levels giving you a much cleaner signal.

Or you may use an analog input (the ESP8266 only has one, and that is quite a crude one with only 1.1V maximum allowed on it, so a voltage divider will be needed) to measure the voltage and do the comparison in software.

Another option would be to remove the LED completely and replace it with an optocoupler, thus making the LED itself an electronically operated button to the ESP8266. This will also keep the ESP8266 ganvalically isolated from the doorbell.

1
  • Some feedback on your suggested solution, Majenko. It is working fine. I decided to go with the optocoupler route, I added a PC817C, on the input side I use the anode and cathode of the led output from the doorbell circuit with a small resistor of 56E, on the output side I have a small debounce circuit, which feeds into a power latch circuit (P and N channel Mosfet) which powers up the ESP8266, it connects to WiFi and sends an MQTT message, and then sets the latch pin low to switch the circuit off again.
    – Will777
    Jul 24, 2021 at 7:58
0

Schmitt Trigger using a Comparator

If you follow @Majenko's advice of using a comparator, you could add some hysteresis to it with a few resistors to create an inverting Schmitt trigger. This will increase the noise immunity and thus reduce the noise going to the ESP8266. The following simulation has a noisy input transformed into square pulses. It also performs a small level shift from an input of 3 V to an output of 3.3 V.

Figure 1 – Schmitt trigger circuit.

Schmitt trigger simulation waveforms

Figure 2 – Schmitt trigger simulation.

Hysteresis versus Low-Pass Filtering

There is a subtle difference between hysteresis and low-pass filtering.

The following experimental circuit, Figure 3, demonstrates this difference with an interactive simulation where you can click on the switches to add/remove noise and add/remove filtering.

The low-pass filter has a cut-off frequency of 40 Hz.

I've set the high-going threshold, Vt+, to 2.31 V and the low-going threshold, Vt-, to 1.54 V. I calculated these figures from the 74HC14 datasheet using the thresholds for 3 V at 25°C and scaling them for 3.3 V.

Figure 3 – Circuit showing difference between hysteresis and low-pass filtering.

Hysteresis provides greater noise immunity and reshapes a slowly changing signal into a square wave ready for a digital input. But it can't filter out noise spikes that breach its threshold levels. These spikes would cause the Schmitt trigger to output square pulses. See the orange section of Figure 4.

Low-pass filtering filters out high frequency spikes which could breach the upper and lower thresholds of a Schmitt trigger. See the green section of Figure 4. Note that it also introduces a phase shift. If the noise were created by switch-bounce, then the low-pass filter would be performing debouncing. The blue section represents the ideal world where there is no noise, no need of filtering, and the output is in phase with the input.

Simulation of hysteresis versus filtering.

Figure 4 – Simulation of hysteresis versus low-pass filtering.

5
  • Tim, thanks for the suggestion, I've been trying out a 74HC14 as part of a hardware debounce solution and it seems to work well. As I mentioned, I'm a hobbyist, so no electronics engineering background (I'm a comp sci guy). In your provided circuit diagram, is the input signal coming from the left, where I see the 40Hz? What does the line connect to between the bottom resistor and ground going out to the left?
    – Will777
    Jul 23, 2021 at 8:02
  • @Wil777, the 74HC14 is a good choice for cleaning up a slowly changing signal and producing a square wave for a digital input, but it won't perform debouncing. Consider a noise spike that crosses both trigger thresholds - it will output a short square wave. Debouncing is performed by a low-pass filter, either in hardware with an RC filter before the Schmitt trigger, or in software with a debouncing algorithm, or both.
    – tim
    Jul 23, 2021 at 10:45
  • Tim, I do have an RC circuit combined with the 74HC14, but my understanding that the 74HC14 also provides hysteresis was based on an article I read on hackaday called "Embed With Elliot: Debounce Your Noisy Buttons"
    – Will777
    Jul 24, 2021 at 7:58
  • @Will777, there is a subtle difference between low-pass filtering for debouncing and hysteresis for signal reshaping. I've updated my post to explain it. I've just looked at Eliot's Hackaday articles. He is saying the same thing: Stage 1 - low-pass filter for debouncing; Stage 2 - hysteresis for signal reshaping; Stage 3 - software debouncing algorithm. BTW, here is my "The Ultimate Debouncer(genuine tm)!" or your money back :-)
    – tim
    Jul 24, 2021 at 11:07
  • Thanks Tim, nice article and I see it caters for a lot of different configurations of software debouncing. Since my MCU is powered down, and I am triggering a power latch to start it up from the doorbell, hardware is prefereable for debouncing. It is working very well
    – Will777
    Jul 27, 2021 at 18:06

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.