0

I get the basics of how to use a sound sensor (I've got this one) but could anyone tell me how to detect a clap and if possible please provide the required code. Thanks in advance, Louis

1

At a guess that sensor is a purely digital output which reports high when a loud noise is present and low otherwise. It is quite common to see similar sensors with an additional analogue output pin.

The output pin high will be at the same level as the supplied voltage. I guess it is meant to be powered with 5V which means the high output will also be 5V.

You must not feed 5V into a Pi GPIO as they are only tolerant of 3V3. Use a pair of resistors to form a voltage divider to drop the 5V output to a Pi safe 3V3.

Turning the small pot with a screw will change the audio threshold level for the output pin to be switched high. Set the level you want.

Then use any programming language you want to monitor the GPIO you have connected (via the voltage divider) to the output pin. When it reads 1 a loud noise is present.

  • Thanks for the help. Just a few more things can someone please explain why I need a voltage divider and also does anyone know if I can detect a clap. – King Balloonion Jan 12 '17 at 18:51
  • The Pi's GPIO are designed to handle 3.3 volts. You will damage the GPIO and eventually the Pi if you feed 5 volts into them. Imaging feeding 12 volts into a bulb designed for 6 volts. Yes, you will be able to detect a clap close to the microphone. I have similar units. – joan Jan 12 '17 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.