Created
June 7, 2013 11:02
-
-
Save dansku/5728545 to your computer and use it in GitHub Desktop.
Arduino Sound Sensor Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is the code to make a LED blink with the music. | |
You have to set the threshold so it' sensible enough to make the led blink. | |
You connect an LED to PIN13 and the Sound Sensor to Analog Pin 0 | |
*/ | |
int led = 13; | |
int threshold = 500; //Change This | |
int volume; | |
void setup() { | |
Serial.begin(9600); // For debugging | |
pinMode(led, OUTPUT); | |
} | |
void loop() { | |
volume = analogRead(A0); // Reads the value from the Analog PIN A0 | |
/* | |
//Debug mode | |
Serial.println(volume); | |
delay(100); | |
*/ | |
if(volume>=threshold){ | |
digitalWrite(led, HIGH); //Turn ON Led | |
} | |
else{ | |
digitalWrite(led, LOW); // Turn OFF Led | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment