Devices & Components
Arduino Uno Rev3
9V to Barrel Jack Connector
5 mm LED: Green
Standard LCD - 16x2 White on Blue
Resistor 100 ohm
5 mm LED: Red
Resistor 220 ohm
5 mm LED: Blue
Sound Sensor Module KY-038
Male/Male Jumper Wires
Solderless Breadboard Full Size
Male/Female Jumper Wires
5 mm LED: Yellow
Resistor 330 ohm
5 mm LED: White
9V battery (generic)
Software & Tools
Arduino IDE
Project description
Code
SoundSensorLEDwData
arduino
I added comments on the code for some explanation. I hope I know what I'm doing. lol.
1#include "Arduino.h" 2#include "LiquidCrystal_PCF8574.h" 3 4#define LCD_ADDRESS 0x27 5#define LCD_ROWS 2 6#define LCD_COLUMNS 16 7#define SCROLL_DELAY 150 8#define BACKLIGHT 255 9 10LiquidCrystal_PCF8574 LCDi2C; 11 12//Add name and position of the LED bulb on the breadboard + Where it's connected on the Arduino. 13// LED1 is LED Bulb 1 on the breadboard and 3 is Digital PWM 3 on the Arduino. 14 15int LED1=3; 16int LED2=4; 17int LED3=5; 18int LED4=6; 19int LED5=7; 20int LED6=8; 21int LED7=9; 22int LED8=10; 23int soundSensor=2; // Digital Pin 2 on the Arduino is where the "DO" of the Sound Sensor is connected. 24int sensorValue = analogRead(A0); //This is where the "AO" of the Sound Sensor is connected. 25 26boolean LEDStatus=false; 27 28void setup () { 29 30 Serial.begin(9600); 31 LCDi2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT); //These are the ones that we defined earlier. 32 pinMode(soundSensor,INPUT); //Because our Sound Sensor is an Input Device. 33 pinMode(LED1, OUTPUT); 34 pinMode(LED2, OUTPUT); 35 pinMode(LED3, OUTPUT); 36 pinMode(LED4, OUTPUT); 37 pinMode(LED5, OUTPUT); 38 pinMode(LED6, OUTPUT); 39 pinMode(LED7, OUTPUT); 40 pinMode(LED8, OUTPUT); 41 pinMode(sensorValue, OUTPUT); //sensorValue is declared as an output because it will be printed on the LCD and Serial Monitor. 42} 43 44void loop() { 45 int sensorValue=analogRead(sensorValue); 46 int SensorData=digitalRead(soundSensor); 47 if(SensorData=1){ 48 if(LEDStatus==false){ 49 LEDStatus=true; 50 Serial.println(sensorValue); //This will be printed on the Serial Monitor just to make sure that the data on the LCD is the same. 51 LCDi2C.setCursor(0,0); //This is to make the text not scroll up and disappear then reapper again when sensorValue data is being added. 52 LCDi2C.print("SoundLevel Data:"); //The text that will appear and stay on Row 1 of the LCD. 53 LCDi2C.setCursor(0,1); //This is to make the text not scroll up and disappear then reapper again when sensorValue data is being added. 54 LCDi2C.print(sensorValue); // The data that will appear on the LCD. 55 LCDi2C.print(" "); // This is to prevent extra digit from the past value appearing on current value. Like, when the past value is 1234, then the current is supposed to 619, but it appears as 6194. 56 } 57 58 if(sensorValue>=750) { // sensorValue greater than or equal to XX. XX numbers are gathered from the most recent data on the Serial Monitor. Copied and pasted it on a spredsheet, then arranged from the lowest to the semi highest sound volume level. 59 digitalWrite(LED8,HIGH); // You can use the different values from the sensor on each LED bulb if you want it to act like a sensor by displaying or lighting up corresponding LED bulbs according to the sensor values data. 60 } // Like Yellow LED bulbs will light up when the sensor picks up a low volume sound aka. Minimum volume level, Green LED bulbs light up when the Volume level is OK, and Red LED Bulbs light up when the volume hits the Loud volume threshold. 61 else{ // Alternatively, you can just add the same value to all the LEDs if you want all of them to react at the same time. 62 LEDStatus=false; // You can also play with the sensor values to make the LEDs dance. Rearranging the sensor values randomly for example. Or making 2 LEDs react at the same value and other LEDs react to other values. 63 digitalWrite(LED8,LOW); 64 } 65 if(sensorValue>=735) { 66 digitalWrite(LED7,HIGH); 67 } 68 else{ 69 LEDStatus=false; 70 digitalWrite(LED7,LOW); 71 } 72 if(sensorValue>=725) { 73 digitalWrite(LED6,HIGH); 74 } 75 else{ 76 LEDStatus=false; 77 digitalWrite(LED6,LOW); 78 } 79 if(sensorValue>=720) { 80 digitalWrite(LED5,HIGH); 81 } 82 else{ 83 LEDStatus=false; 84 digitalWrite(LED5,LOW); 85 } 86 if(sensorValue>=715) { 87 digitalWrite(LED4,HIGH); 88 } 89 else{ 90 LEDStatus=false; 91 digitalWrite(LED4,LOW); 92 } 93 94 if(sensorValue>=700) { 95 digitalWrite(LED3,HIGH); 96 } 97 else{ 98 LEDStatus=false; 99 digitalWrite(LED3,LOW); 100 } 101 102 if(sensorValue>=675) { 103 digitalWrite(LED2,HIGH); 104 } 105 else{ 106 LEDStatus=false; 107 digitalWrite(LED2,LOW); 108 } 109 110 if(sensorValue>=650) { 111 digitalWrite(LED1,HIGH); 112 } 113 else{ 114 LEDStatus=false; 115 digitalWrite(LED1,LOW); 116 } 117 } 118 else{ 119 LEDStatus=false; //Not really sure why I added this. Lol. 120 digitalWrite(LED1,LOW); 121 digitalWrite(LED2,LOW); 122 digitalWrite(LED3,LOW); 123 digitalWrite(LED4,LOW); 124 digitalWrite(LED5,LOW); 125 digitalWrite(LED6,LOW); 126 digitalWrite(LED7,LOW); 127 digitalWrite(LED8,LOW); 128 } 129 } 130 131
Downloadable files
I made this using Photoshop.
Just follow the wires from end to end.
I made this using Photoshop.

Comments
Only logged in users can leave comments