Devices & Components
Arduino Mega 2560 Rev3
5 mm LED: Red
Breadboard (generic)
5 mm LED: Yellow
SparkFun Sound Detector (with Headers)
LED, Blue
Jumper wires (generic)
Software & Tools
Arduino IDE
Arduino Web Editor
Project description
Code
LEDSoundVisualizer.ino
c_cpp
Method of using Sound Detector by Sparkfun. Copy and paste into Arduino IDE.
1//Use Sparkfun's Sound Detector Guide to Create a Sound Visualizer 2 3// Define the Pin connections 4#define PIN_GATE_IN 2 5#define IRQ_GATE_IN 0 6#define PIN_LED_OUT 13 7#define PIN_ANALOG_IN A0 8 9void soundISR() 10{ 11 int pin_val; 12 13 pin_val = digitalRead(PIN_GATE_IN); 14 digitalWrite(PIN_LED_OUT, pin_val); 15} 16 17void setup() 18{ 19 Serial.begin(9600); //Starts Newline Baud Connection 20 21 pinMode(PIN_LED_OUT, OUTPUT); //Setting builtin LED for the SOUND detector as OUTPUT 22 23 pinMode(PIN_GATE_IN, INPUT); //Setting the Gate Pin as input 24 attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE); 25 26//Set LED Pins as OUTPUT 27 pinMode(5, OUTPUT); 28 pinMode(4, OUTPUT); 29 pinMode(3, OUTPUT); 30} 31 32void loop() 33{ 34//Sets the LEDs to OFF 35 digitalWrite(5, LOW); 36 digitalWrite(4, LOW); 37 digitalWrite(3, LOW); 38 39 int value; 40 41 value = analogRead(PIN_ANALOG_IN); 42 43 Serial.println("Volume Value: "); 44 45 if ((value>=10) && (value <=20)) 46 { 47 digitalWrite(5, HIGH); 48 Serial.print(value); 49 Serial.println("LOW VOLUME"); 50 } 51 else if ( (value > 20) && (value <= 30) ) 52 { 53 digitalWrite(4, HIGH); 54 digitalWrite(5, HIGH); 55 Serial.print(value); 56 Serial.println("MEDIUM VOLUME"); 57 } 58 else if (value > 30) 59 { 60 digitalWrite(3, HIGH); 61 digitalWrite(4, HIGH); 62 digitalWrite(5, HIGH); 63 Serial.print(value); 64 Serial.println("HIGH VOLUME"); 65 } 66 67 else { 68 Serial.println("LITTLE/NO VOLUME DETECTED"); 69 } 70 71 72 delay(1000); 73} 74
LEDSoundVisualizer.ino
c_cpp
Method of using Sound Detector by Sparkfun. Copy and paste into Arduino IDE.
1//Use Sparkfun's Sound Detector Guide to Create a Sound Visualizer 2 3// 4 Define the Pin connections 5#define PIN_GATE_IN 2 6#define IRQ_GATE_IN 0 7#define 8 PIN_LED_OUT 13 9#define PIN_ANALOG_IN A0 10 11void soundISR() 12{ 13 int 14 pin_val; 15 16 pin_val = digitalRead(PIN_GATE_IN); 17 digitalWrite(PIN_LED_OUT, 18 pin_val); 19} 20 21void setup() 22{ 23 Serial.begin(9600); //Starts Newline 24 Baud Connection 25 26 pinMode(PIN_LED_OUT, OUTPUT); //Setting builtin LED for 27 the SOUND detector as OUTPUT 28 29 pinMode(PIN_GATE_IN, INPUT); //Setting the 30 Gate Pin as input 31 attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE); 32 33//Set 34 LED Pins as OUTPUT 35 pinMode(5, OUTPUT); 36 pinMode(4, OUTPUT); 37 pinMode(3, 38 OUTPUT); 39} 40 41void loop() 42{ 43//Sets the LEDs to OFF 44 digitalWrite(5, 45 LOW); 46 digitalWrite(4, LOW); 47 digitalWrite(3, LOW); 48 49 int value; 50 51 52 value = analogRead(PIN_ANALOG_IN); 53 54 Serial.println("Volume Value: "); 55 56 57 if ((value>=10) && (value <=20)) 58 { 59 digitalWrite(5, HIGH); 60 Serial.print(value); 61 62 Serial.println("LOW VOLUME"); 63 } 64 else if ( (value > 20) && (value 65 <= 30) ) 66 { 67 digitalWrite(4, HIGH); 68 digitalWrite(5, HIGH); 69 70 Serial.print(value); 71 Serial.println("MEDIUM VOLUME"); 72 } 73 else 74 if (value > 30) 75 { 76 digitalWrite(3, HIGH); 77 digitalWrite(4, HIGH); 78 79 digitalWrite(5, HIGH); 80 Serial.print(value); 81 Serial.println("HIGH 82 VOLUME"); 83 } 84 85 else { 86 Serial.println("LITTLE/NO VOLUME DETECTED"); 87 88 } 89 90 91 delay(1000); 92} 93
Downloadable files
Sound Detector Hookup
Sound Detector Hookup

LED hookup
LED hookup

Sound Detector Hookup
Sound Detector Hookup

Comments
Only logged in users can leave comments