LED Lights Reflecting Sound Level Using Microphone and Arduino Uno

757

1

I have used the materials below to create a circuit of microphone sensor as input and led lights reflecting sound level as output.

- 6 leds, 6 resistors and 7 jumpers for leds

- microphone sensor, 1 jumper and 1 resistor for microphone

- arduino uno, usb cable to connect arduino to computer

Key point:

- Microphone sensor does not aim to create an equalizer so you will realize the microphone may mainly show 1023-1022 on serial monitor if you do not use the code I wrote on Arduino ide. In order to get quality and sensitive results from microphone on serial monitor, I have multiplied the sensor output with 50. Then I get a wider scale of numbers, then it was easier to decide sound level proportions of led lights.

In order to do the proportioning I have collected the data on serial monitor for about 40 sec. Then I used excel to understand the sound levels.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: LED Connections on Breadboard

- Connect each LED's negative (short) leg to a resistor's one leg. The other leg of resistor can be directly connected to Ground side of breadboard. From ground line of breadboard, make connection to GND in arduino uno with 1 jumper.

- Connect each LED's positive (long) leg to a Jumper. Each jumper's other leg will be connected to digital pins, 2,3,4,5,6,7 respectvely. Led 1 (on the most left side) will be connected to pin 2. Led 6 (on the most right side) will be connected to pin 7.

Step 2: Microphone Sensor Connection to Arduino

Microphone sensor has 3 cables:

- GND (green cable), that is directly connected to Arduino GND

- OUT (blue cable), that is connected to A0 in this circuit

- VCC (yellow cable), that is connected to breadboard D1. Connecting one leg of resistor to yellow cable on C1, I have connected resistor's second leg to breadboard's positive line. Then I made a connection from arduino 5V to breadboard's positive line.

Step 3: Arduino Code

///Turns on the LED according to sound level recorded by the sound or microphone sensor.

int led1 = 2;

int led2 = 3;

int led3 = 4;

int led4 = 5;

int led5 = 6;

int led6 = 7;

int sensorPin = A0; // input pin for the sensor

int sensorval = 0; // variable for the value coming from the sensor

// the setup routine runs once when you press reset:

void setup() { // initialize the digital pin as an output.

pinMode(led1,OUTPUT);

pinMode(led2,OUTPUT);

pinMode(led3,OUTPUT);

pinMode(led4,OUTPUT);

pinMode(led5,OUTPUT);

pinMode(led6,OUTPUT);

pinMode(sensorPin, INPUT); // initialize sensor as input

Serial.begin(9600); // initialize serial communication with computer }

void loop() {

sensorval = analogRead(sensorPin)*60; // read the value from the sensor , multiply by 60 for a sensitive calibration

Serial.println(sensorval); // send it to the computer's serial port screen

if (sensorval > 29500) { digitalWrite(led1, HIGH); } else { digitalWrite(led1,LOW); }

if (sensorval > 29600) { digitalWrite(led2, HIGH); }else { digitalWrite(led2,LOW); }

if (sensorval > 29690) { digitalWrite(led3, HIGH); } else { digitalWrite(led3,LOW); }

if (sensorval > 29750) { digitalWrite(led4, HIGH); } else{ digitalWrite(led4,LOW); }

if (sensorval > 29800) { digitalWrite(led5, HIGH); } else { digitalWrite(led5,LOW); }

if (sensorval > 29900) { digitalWrite(led6, HIGH); }else { digitalWrite(led6,LOW); }

delay(100); }

Step 4: Calibration of Led Lights

After working with the attached code, you may need to further calibrate the values in if else functions.

According to environment or sound level of your preference you may follow the instructions to amend the values:

- Read the serial monitor values for some time, less then 1 minute is cool. Otherwise excel may not paste all the values collected on the monitor.

- Stop the auto scroll on serial port screen. Select all data on screen, copy and paste to excel. Sort the values from A to Z.

- You will realize the values are mainly in a certain space. In my case, The values are mainly (85%) between 29000-3000. If you set the minimum value of y axis of graph to 29000, you will see closely how the data is spread between 29000 and above. Then you can make a rule for each led according to your wish.

I tried to divide into 7 pieces for 6 leds by leaving around 15% per each section.

Recommendations

• Internet of Things Class

22,728 Enrolled