int DO = 2; //Pin for Digital Output - DO int DA = A0; // Pin for Analog Output - AO int threshold = 469; //Set minimum threshold for LED lit int sensorvalue = 0; int ledPin = 13; // the number of the LED pin void setup() { //Serial.begin(9600); pinMode(3, OUTPUT); Serial.begin(9600); // set serial speed pinMode(13, OUTPUT); // set LED as output digitalWrite(13, LOW); //turn off LED } void soundreactiveled() { sensorvalue = analogRead(DA); //Read the analog value if (sensorvalue >= threshold) { //Compare analog value with threshold digitalWrite(3, HIGH); } else { digitalWrite(3, LOW); } }void plugcontrol(){ while (Serial.available() == 0); // do nothing if nothing sent int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number if (val == 1) { // test for command 1 then turn on LED Serial.println("LED on"); digitalWrite(ledPin, HIGH); // turn on LED } else if (val == 0) // test for command 0 then turn off LED { Serial.println("LED OFF"); digitalWrite(ledPin, LOW); // turn off LED } else // if not one of above command, do nothing { //val = val; } Serial.println(val); Serial.flush(); // clear serial port } void loop(){ soundreactiveled(); plugcontrol(); }