How to Build a Sound Alarm Circuit

This is a circuit that will go off if the circuit detects any sound above a certain threshold. Once the
circuit detects sound, the alarm goes off alerting us to this sound.

In our circuit, we will make it so that an LED turns on when the circuit detects sound and stays on, stimulating an alarm circuit.

This circuit has extreme use when an area ordinarily should be very quiet and should have no sound like a quiet zone.
Under quiet conditions, with little to no sound, the alarm will not go off. When a sound is detected such as someone walking through the room
or talking in a room, the alarm will go off. Thus, we can detect intruders in a room that shouldn't be there if they create sound
while operating in a room where there shouldn't be any.

This is the basis of a sound alarm circuit. It can detect sounds where there should be none. That way, we know something
is out of the ordinary.

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

A Condenser Microphone

6 Volts of power (either from 4 'AA' batteries or a DC power supply)

5.6KΩ resistor

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 alarm 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:

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:

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.

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 Alarm Circuit

The complete Sound Alarm Circuit is shown below:

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 and stay on unless power to the circuit is shut off. This way, our circuit functions as a sound alarm circuit.

This is the code needed to detect sound and turn on an LED and have it stay on. In this code, the LED will actually turn on for 10 minutes before shutting off. You can modify this value
for it to stay on for however long you want. Since the delay() function takes parameters in ms, to calculate the amount of time you want the LED on for, just remember that 1000ms equals 1 second.
And there are 60 seconds in a minute. Then you multiply that value by the number of minutes you want the LED on for.

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