PROJECT: Sound Triggered LED
Step 1 - Build the Project

Use a sound trigger to take noise readings from your environment. If the noise reaches a threshold, turn on an LED for the entire time the noise is above your threshold. 

Step 2 - Upload the Code

/* * Turn an LED on when the sound trigger 'hears' a loud noise */ void setup() { pinMode(A4,INPUT); //Center pin of sound trigger pinMode(13,OUTPUT); //LED } void loop() { /* * Turn on the LED while noise is detected. Your noise threshold * may be different than the default. Experiment with this number. */ const int soundThreshold = 600; if (analogRead(A4)>soundThreshold){ digitalWrite(13,HIGH); delay(50); } else{digitalWrite(13,LOW); } } //Try to create another threshold to control a second light // for example, a reading over 900 turns on another light // (c) 2017 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Step 3 - Read the Walkthrough

Within the setup(), set the center pin of your sound trigger to an INPUT and the LED as an OUTPUT.

In the loop, create an integer to hold the noise threshold. Experiment with this number so that you can clap and turn on the light. 

The if statement takes a reading from the sound sensor and compares it to your threshold. If the reading is greater than the threshold, the if statement is true and the code inside the loop will run. 

Otherwise, the else statement runs, leaving the LED light off.