Clap detection (or any other loud sound?)

Posted on
  • Hey y'all,
    Is it possible to connect a simple two-pin electret microphone to an Espruino microcontroller and program the uC to wake on a loud sound, like a clap or snapping of a finger? I can't find any resources regarding microphones in the Espruino website, or anywhere else. I don't think it would be hard at all, I'm just not sure if there's a way yet. I'm using an MDBT42Q module, if it helps.

    Thanks!

  • Hi! Yes, totally - there are various ways to do it, but by far the easiest would be to buy a microphone module that does it for you.

    Something like: https://www.ebay.co.uk/itm/Sound-Detecti­on-Sensor-Module-Electret-Condenser-Micr­ophone-Arduino-PIC-Pi-LM393/273149595283­

    The blue potentiometer on there can be tweaked to choose how sensitive it is, then all you need to do is use setWatch on the pin that's connected to the digital output :)

  • Is the potentiometer the only way to set the trigger volume threshold(the volume needed to trigger a function)? Or can I edit it in software? I really want to use only the mic without any other components.

  • Mon 2019.06.24

    'I really want to use only the mic without any other components.'

    Without an op-amp of some kind, I don't believe there will be sufficient amplification (est micro-volts) from the tiny mic output, and possibly an impedance mismatch also. Trying to capture without that or a latch circuit, will hamper success. Even the A-D requires 700uv for a single digit. http://www.espruino.com/ADC

    Do you have access to a scope to look at the mic output? If so, what is the range? If not, a spec/datasheet?

  • Do you want the uC to detect the clap (sampling the audio all time) or do you want the sleeping uC be woken up by an interrupt triggered by the microphone?

  • Do you have access to a scope to look at the mic output? If so, what is the range? If not, a spec/datasheet?

    @Robin I don't have a scope.

    Do you want the uC to detect the clap (sampling the audio all time) or do you want the sleeping uC be woken up by an interrupt triggered by the microphone?

    @maze1980 I want the sleeping uC to be triggered by the mic interrupt.

  • @barry_b_benson, take a look at this pub https://pub.tik.ee.ethz.ch/students/2013­-FS/GA-2013-03.pdf - also attached as pdf.

    What I notice is that many clap switches need two claps for one toggle. All switches use some kind of amplifier to create a sufficient voltage top get digital electronics triggered... (as @Robin points out). Attached schema seems quite simple - 3 resistors, 1 capacitor and a single transistor. The reference is found in the initial pub in the literature summary, and is http://embedded-lab.com/blog/making-a-si­mple-clap-switch/


    2 Attachments

  • Nice find @allObjects, Hum along . . . Clap On, . . . Clap Off

    and they are still sold, forty years later!!

    Now I can't get that ear worm out of my mind ;-)

    Quite a simple circuit, isn't it.

    1985
    The switch was designed to respond to a specific acoustic signal: two claps. Joseph Pedott, founder of Joseph Enterprises, Inc., began selling the Clapper in 1985. (You've probably heard of Joseph Enterprises' other super-popular invention, The Chia Pet.)

    https://www.amazon.com/Clapper-Activated­-Detection-Appliances-Technology/dp/B000­0CGKLR

  • We'd really need to know just how much voltage you get from the microphone when there's a clap before we know if it can be connected directly. @allObjects solution looks great if you can't connect direct though.

    You could keep checking the analog value, but that's going to use a whole bunch of power - so using a battery won't then be a very viable option.

    Bluetooth Espruinos do have a 'low power comparator' which can work to 1/16th of the supply voltage (or can compare to the voltage on pins D2 or D3): http://www.espruino.com/NRF52LL

    So you could set that up - although the current solution in Espruino will require you to use two pins connected together so that you can then use setWatch to trigger code to run when the voltage goes above a certain level.

  • I want the sleeping uC to be triggered by the mic interrupt.

    https://www.espruino.com/Reference#l_ESP­8266_deepSleep says you must pull down the RST pin, i.e. the mic alone will not work, and the clap detector circuit above doesn't work (0V output, with 5V peaks during claps), the signal is inverted.

  • Tue 2019.06.25

    re: 'and the clap detector circuit above doesn't work (0V output, with 5V peaks during claps), the signal is inverted'

    Solve by adding an additional transitor inverter at the tail end.

    See 'Digital Logic' half way down page:

    https://learn.sparkfun.com/tutorials/tra­nsistors/applications-i-switches

    https://electroconcepts.wordpress.com/20­18/02/23/how-is-transistor-used-as-a-swi­tch-or-inverter/

  • @maze1980, @barry_b_benson was asking about how to do this with an Espruino MDBT42Q - these have significantly better sleep/wake arrangements than the ESP8266 does (which effectively just shuts itself down losing the contents of RAM and then has to be rebooted) .

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Clap detection (or any other loud sound?)

Posted by Avatar for BootySnorkeler @BootySnorkeler

Actions