// Variable for the Microphone int MIC = A2; //Variable for the Blue LED int BLUELED = D0; //Variable for the Orange LED int ORANGELED = D6; //Variable for the Red LED int REDLED = D7; // Variable to read the value of the sensor int VALUE; // Variable to determine the current LED int CURRENTLED = BLUELED; void setup () { //Here I define the Microphone as input and the led as output pinMode (MIC, INPUT); pinMode (BLUELED, OUTPUT); pinMode (ORANGELED, OUTPUT); pinMode (REDLED, OUTPUT); } void loop() { VALUE = digitalRead(MIC); // This would turn off the First LED (BLue one) when it heard a sound if (VALUE == HIGH) { digitalWrite(CURRENTLED, LOW); if (CURRENTLED == BLUELED){ CURRENTLED = ORANGELED; /* If the blue led was the current one, for the next time the sensor heard a sound, the next "current LED" would be the orange one*/ }else if (CURRENTLED == ORANGELED) { CURRENTLED = REDLED; /* The same change would happen once the orange became the current, the next would be the red LED*/ }else if (CURRENTLED == REDLED) { CURRENTLED = BLUELED; /* Finally, it would go back to the blue one to repeat the loop */ } digitalWrite(CURRENTLED,HIGH); delay(200); } }