Sensing sound from a speaker

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
andydj
Posts: 3
Joined: Thu Jan 10, 2019 7:52 pm

Sensing sound from a speaker

Post by andydj » Thu Jan 10, 2019 8:25 pm

MicroPython newb here. Know python, arduino, some basic electronics, now venturing into MicroPython Land. Everybody's got to start somewhere, right?

I recently bought a D1 Mini clone, with a view to using the wifi capabilities. What I want to do is detect whether my doorbell is ringing, and if so senda udp packet to my laptop over the wifi - I can handle the socket programming bit, it's the other bit I'm struggling with. The doorbell is one of those cheap wireless ones, and it plays cheesy tunes when someone presses the button. I'd like to somehow attach the D1 Mini to the doorbell speaker (I'm thinking maybe to the A0 pin) and poll that, then send the udp packet if the signal is over a threshold value.

I haven't taken it apart yet, but I'm hoping I can simply solder some leads onto the back of the speaker, back to the D1, maybe with a current limiting resistor to keep it in range. Can anyone point me in the right direction?

Thanks in advance.

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

Re: Sensing sound from a speaker

Post by Roberthh » Thu Jan 10, 2019 8:37 pm

Without knowing the kind and level of signal at the speaker it is hard to give any advice. If that door bell has also a LED which lights up at the same time, interfacing is much easier. But still level & polarity must be known.

ThomasChr
Posts: 27
Joined: Sat Nov 25, 2017 7:50 am

Re: Sensing sound from a speaker

Post by ThomasChr » Thu Jan 10, 2019 8:52 pm

First you should try to examine the signal. An oscilloscope would be needed for that. Also Tones are no simple DC Voltage. It‘s AC. So depending on the moment of measuring you can get 5V, 0V or maybe -5V. As an alternative you can get simple chinese mikrophone moduls. They have an A0 analog AC Output but also a digital D0 Output which gives a clean High when the loudness is above a configurable Threshold.

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

Re: Sensing sound from a speaker

Post by kevinkk525 » Fri Jan 11, 2019 5:16 am

I connected my esp directly to the doorbell signal going into the doorbell device using a transistor. Our system is however very old.
Works good though using a pin interrupt and debounce.
Depending on the signal your doorbell device receives, this might be an option too.

andydj
Posts: 3
Joined: Thu Jan 10, 2019 7:52 pm

Re: Sensing sound from a speaker

Post by andydj » Fri Jan 11, 2019 9:46 pm

Thanks, all. Some useful points. It doesn't have an LED, but I've now opened it up to have a look, and it DOES have 2 unused pads on the PCB, one of which connects has a small SMD resistor on it, and the other is on the ground plane. Looked to me like it was intended for an LED option, especially since it's marked "LEDGND"... so I grabbed one out of my Arduino box, and held it in place while I pushed the bell button, and lo and behold, it flashed!

OK, so I think that is the route I'm going to go down then.

ThomasChr
Posts: 27
Joined: Sat Nov 25, 2017 7:50 am

Re: Sensing sound from a speaker

Post by ThomasChr » Sat Jan 12, 2019 8:52 am

Great news! Sensing a LED is childs play :-)

nekomatic
Posts: 9
Joined: Thu May 08, 2014 9:31 pm

Re: Sensing sound from a speaker

Post by nekomatic » Mon Jan 14, 2019 11:50 am

You could connect the LED side of an optocoupler like a 4N35 to those pads on the doorbell, then you have an electrically isolated open-collector output that's easy to interface to a pin on the ESP side. Or if isolation isn't important you can just connect a suitable resistor across them and detect the voltage level.

andydj
Posts: 3
Joined: Thu Jan 10, 2019 7:52 pm

Re: Sensing sound from a speaker

Post by andydj » Mon Jan 14, 2019 9:57 pm

I thought I'd put in an update: I got it working. Thanks for the hints!

The voltage on the LED pads read as about 1.8 volts, and this was confirmed by looking at it with the oscilloscope at my makerspace. So, being aware of the 1 volt upper limit on the ADC, I had to look at how to make a voltage divider, and breadboarded that, with some wires soldered to the LED pads. After checking with the meter that I was getting low enough voltages, I then attached it to the ESP8266, and wrote a loop to read A0, and sure enough, I was getting zeroes until the doorbell chimed, at which point I saw a few pulses at about "120" from the ADC, in sympathy with the blinks on the LED.

I've now soldered my two resistors for the voltage divider to the LED pads and splashed the extension wire onto that to connect to the ESP8266, and confirmed it's working.

Tonight, I wrote up a little python UDP socket server, and a micropython, adapted, adapted from here: https://pythontic.com/modules/socket/ud ... er-example (though there are loads of examples round - I just chose the first one I found, as I know the score and just needed a bit of a hint). Took a few iterations, but I have a rudimentary version working of both now. Happy to post the code if anyone's interested (it's not rocket science).

ThomasChr
Posts: 27
Joined: Sat Nov 25, 2017 7:50 am

Re: Sensing sound from a speaker

Post by ThomasChr » Tue Jan 15, 2019 5:50 am

Just a hint: Many of those cheap NodeMCU ESP8266 Boards have the voltage divider already built in.

Glad to hear that it works :-)

Thomas

Post Reply