Voice Detector Circuit With Arduino Nano

by Xiuqi_SUNny in Circuits > Arduino

162 Views, 0 Favorites, 0 Comments

Voice Detector Circuit With Arduino Nano

Screenshot 2024-08-20 at 2.46.50 PM.png

Make a breadboard-based voice detector that will shine a red light if the voice has exceeded a certain volume.

The threshold volume can be adjusted by changing data in the code.

This is an easy Arduino project to make, with an easy circuit and simple coding.

Supplies

IMG_7671.jpg
  1. A laptop with Arduino IDE installed
  2. Analog microphone
  3. Extension cord
  4. Arduino Nano, soldered
  5. LED light
  6. 220 ohm resistor
  7. Breadboard
  8. Connector wires (male and female)

Screenshot 2024-08-23 at 11.40.58 AM.png
Screenshot 2024-08-20 at 2.43.11 PM.png

First of all, the basic circuit is constructed on a breadboard as follows.

This is a simple circuit, consisting of a microphone, a resistor, a LED light, and the Arduino Nano chip, processing all the information.

The chip receives input from the microphone, and the information (the analog read of the sound level) is processed by the Arduino Nano, and the output is sent to the LED light.

Construction of the circuit is done as follows:

  1. Arduino Nano is pushed into the breadboard as shown in the picture.
  2. Connecting the microphone to the Arduino
  3. AO pin --> A7
  4. G --> 5v
  5. + --> GND
  6. An LED light anode is connected to the D10 pin, and the resistor goes from the cathode of the LED to the GND pin on the same side of the D10 pin.

Coding

The coding is relatively simple, and I will be explaining the code step by step below.

First step:

Constants are set based on the circuit constructed.

const int OUT_PIN = 7; // the A7 pin that is connected to the Microphone, receiving input

const int LED_PIN = 10; // Arduino pin connected to LED's pin providing output

const int VOLUME_THRESHOLD = 20; // sound level, this can be adjusted freely, depending on individual's preference.


Second step:

Set mode of the pin (input/output)

void setup() {

Serial.begin(9600);

pinMode(OUT_PIN, INPUT); // set pin to input mode to receive analog data from the microphone

pinMode(LED_PIN, OUTPUT); // set Arduino pin to output mode to light the LED

}


Third step:

Receiving data from the microphone and comparing data with the threshold set.

void loop() { // a non-stop loop to keep receiving and comparing the value

double sound=analogRead(OUT_PIN); // get the sound in analog value from the microphone and store it in a variable sound

if(sound >=VOLUME_THRESHOLD) // if the variable sound is greater than the set threshold

analogWrite(LED_PIN, HIGH); // turn on LED

else // if the variable sound is smaller than or equal to the set threshold

analogWrite(LED_PIN, LOW); // turn off LED

delay(500); // This slows down the loop so it doesn't go too rapidly.

}

The code with and without annotation is uploaded below.

Downloads

Uploading the Code and Final Adjust

Screenshot 2024-08-30 at 12.14.22 PM.png

Once the code is done, it needs to be uploaded into the Arduino. Use an extension cord to connect the chip and your laptop with the code on it. Click Verify (first top left button) and then Upload (second top left button) to upload the code, and you are good to go!

After uploading the code, you can go to the testing section to see if it works.

Testing

download (1).gif

Test of the voice detector can be done in a quiet room. If all the constructions are successful, the light should light up at a certain sound level. I yelled and clapped to the microphone to see if the light could light up.

If there's any problem with any components, refer to the Modifications section below.

A final product is shown here. You can see that every time I clap, the red light is going to shine.

Modifications (optional)

During the construction of this little project, the main problem that appeared was with the microphone. Technically, microphones that can return analog values can be used, as the code in the Arduino requires an analog input to compare the data with the threshold being set.

If there's a problem with the microphone, check for the type (analog) and try to adjust the sensitivity using a screwdriver. If the light is shining even if it's quiet or not shining at all, first check the circuit, and try to adjust the variable VOLUME_THRESHOLD in the code, as it might vary depending on the type of microphone, the sensitivity of the microphone and the surroundings.