How to Build a Sound Detector Circuit

Arduino Sound Detector


In this project, we will go over how to build a sound detector circuit.

A sound detector circuit, as you would probably know, is a circuit that can detect sound, such as talking, clapping, or shouting.

Based on this sound that the circuit detects, we can let anything happen in the circuit, such as have an LED light.

In this sound detector circuit which we will build now, we are going to use a microcontroller, an arduino board, to light an LED when sound is detected.

Of course, we will use a microphone to be able to detect sound. But a microphone alone is insufficient for this circuit. This is because a microphone alone, without an amplifier, produces very small electrical signals. If we connected the output sound signals from a microphone directly into the pin of an arduino, the board wouldn't be able to detect any meaningful signal, since it is so small. To be able to detect a signal that is large enough, the signal needs to be amplified first to be usable by the Arduino. Therefore, we must connect the microphone to an amplifier, have the signal amplified, and then connect the amplified signal into the arduino.

So in order to build our circuit, we will use a microphone and connect it to an audio amplifier to get amplified signals. The amplifier IC that we use is the popular LM386 IC. This IC will amplify the output signals that the microphone produces so that the arduino will be able to detect large enough signals to interpret them.



Components Needed for Sound Detector Circuit

  • A Condenser Microphone
  • 6 Volts of power (either from 4 'AA' batteries or a DC power supply)
  • 2KΩ-6KΩ resistor (depending on the microphone in use)
  • 10Ω resistor
  • 10KΩ potentiometer
  • 2 10μF electrolytic capacitor
  • 100μF electrolytic capacitor
  • 0.1μF ceramic capacitor
  • 47nF ceramic capacitor
  • Arduino
  • LED


Condenser microphones, resistors, capacitors, and the LM386 audio amplifer chip can be easily obtained from most electronic online retailers.

Before we show the complete schematic diagram of the arduino sound detector circuit, we will first show the pinout of the LM386. This way, the connections that we make from the microphone to it will make more sense.

The pinout diagram is shown below:

LM386 Pinout Diagram

Pin Terminals

Terminals 1 and 8 represent the gain control of the amplifier. These are the terminals where you can adjust the gain by placing a resistor and capacitor or just capacitor between these terminals. In this circuit, we will place a 10µF capacitor between these terminals for the highest voltage gain. You can adjust this as necessary to adjust the gain, as needed.
Terminals 2 and 3 are the sound input signal terminals. These are the terminals where you place the sound which you want to amplify. In our case for this circuit, the condenser microphone will be connected to these terminals. Terminal 2 is the -input and Terminal 3 is the +input. In our circuit, the positive microphone terminal will be placed on terminal 3 and terminal 2 will be connected to the negative microphone terminal, tied to ground.
Terminal 4 is GND (ground). This is where the negative voltage of the power source connects to.
Terminal 5 is the output of the amplifier. This is the terminal in which the amplified sound signal comes out.
Terminal 6 is the terminal which receives the positive DC voltage so that the op amp can receive the power it needs to amplify signals.
Terminal 7 is the Bypass terminal. This pin is usually left open or is wired to ground. However, for better stability, a capacitor is added in our circuit because this can prevent oscillations in the amp chip.

Audio Amplifier Circuit

Now that you what each of the pins of the LM386 represents, we can assemble the whole audio amplifier circuit.

The schematic for the amplifier part of the circuit is shown below:

LM386 microphone amplifier circuit

  • R1 is a resistor that connects the microphone to positive voltage so that the microphone is able to power on. Microphones cannot work without the necessary power needed. The value of the resistor is variable because it depends on the specific microphone that you have in use. Check the datasheet of the microphone you are using to find out the most suitable value for the necessary pull-up resistor.
  • C1 is a capacitor that blocks DC voltage on the input signal and allows AC to pass through. When we speak into a microphone, our voice or music is the AC signal. This is the only part of the signal that we want to pass through to output. The DC signal is only used to give power to the microphone; we do not want it to appear in output. This is why we use this capacitor. It blocks the DC but allows the AC to go into output.
  • R2 is a potentiometer that is used to control the sound volume.
  • C2 is a capacitor that sets the voltage gain of the LM386 amplifier. Therefore, the voltage out is 200 times the voltage in. This provides us with the maximum gain that the LM386 can provide.
  • C3 is a capacitor that improves the stability of the LM386 amplifier to prevent issues such as oscillations. Oscillation can distort sound signals, making them unclear or unintelligible.
  • C4 is a capacitor that removes any DC offset from the output of the LM386 amplifier.
  • C5 is a capacitor that acts as a current bank for output. This capacitor drains when sudden surges of current occur and refills with electrons when the demand for current is low.


The circuit starts with the condenser microphone. The microphone picks up sound signals and transforms them into electrical signals. These electrical signals are then amplified by the LM386 IC. These signals are then output through pin 5 of the amplifier IC, which are then fed to the arduino board to be processed.

Arduino Sound Detector Circuit

The complete Sound Detector Circuit is shown below:

Sound detector circuit

The output signal, again, comes from pin 5 of the LM386 IC. The positive terminal (+) goes into an analog terminal of the Arduino; we will connect it, in our case, to A0 of the analog terminal. The negative terminal (-) connects to GND on the arduino. This allows us to process the output signal of the microphone. If we don't speak into the microphone, it will pick up a faint signal and give us a very low reading. If we make loud noises such as shout, clap into the microphone, etc., we will get a loud reading. We will program the software for the arduino to light up the LED attached to digital pin, D13, when a certain threshold of sound is reached. The LED will light up for a half of second and then turn off each time this sound threshold is reached. The LED will mimic each sound picked up by the microphone. This way, our circuit functions as a sound detector circuit.


Code

The code to turn on an LED when sound is detected is shown below.

//these define the pin connections
const int microphonePin= 0; //the microphone positive terminal will connect to analog pin A0 to be read
const int ledPin=13; //the code will flash the LED connected to pin 13

int sample; //the variable that will hold the value read from the microphone each time

const int threshold= 800;//the microphone threshold sound level at which the LED will turn on

void setup() {
pinMode (ledPin, OUTPUT);//sets digital pin 13 as output
Serial.begin(9600); //sets the baud rate at 9600 so we can check the values the microphone is obtaining on the Serial Monitor
}

void loop(){
sample= analogRead(microphonePin); //the arduino takes continuous readings from the microphone
Serial.println(sample);
if (sample > threshold)
{
digitalWrite (ledPin, HIGH); //if the reading is greater than the threshold value, LED turns on
delay (500); //LED stays on for a half a second
digitalWrite (ledPin, LOW); //LED turns off
}
else
{
digitalWrite(ledPin, LOW);
}
}


This is the code needed to detect sound and turn on an LED for a half a second each time sound is detected.

And this is how a sound detector circuit works.

To see a demo of this circuit in real life, see the video below.



Related Resources

How to Drive a 7 Segment LED Display with an Arduno

How to Build a Dark-activated Light Circuit

How to Build a Hall Effect Sensor Circuit

How to Build a Touch Sensor Circuit

How to Build an Accelerometer Circuit

How to Build a Motion Detector Circuit

How to Build a Motion Detector Alarm Circuit

HTML Comment Box is loading comments...