Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Sound Control Light
- int soundPin = A2; // Analog sound sensor is to be attached to analog
- int ledPin = 4; // Digital LED is to be attached to digital
- void setup() {
- pinMode(ledPin, OUTPUT);
- pinMode(soundPin, INPUT);
- Serial.begin(9600);
- }
- void loop(){
- int soundState = analogRead(soundPin); // Read sound sensor’s value
- Serial.println(soundState);
- // if the sound sensor’s value is greater than 400, LED light up
- //Otherwise, the light will be turned off
- if (soundState > 262) {
- digitalWrite(ledPin, HIGH);
- delay(100);
- }else{
- digitalWrite(ledPin, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement