//Receive commands from App //vars string sgCommand; unsigned int igUpdateTime; void setup() { Serial.begin(9600); // open serial port, set the baud rate to 9600 bps igUpdateTime = millis(); // loop timer } void loop() { //Execute loop every 10 seconds if((millis() - igUpdateTime) > 10000) { igUpdateTime = millis(); if(Serial.available() > 0) { sgCommand = Serial.read(); switch (sgCommand) { case "light on": digitalWrite(5, HIGH); break; case "light off": digitalWrite(5, LOW); break; case "fan on": digitalWrite(6, HIGH); break; case "fan off": digitalWrite(6, LOW); break; case "all on": digitalWrite(5, HIGH); digitalWrite(6, HIGH); break; case "all off": digitalWrite(5, LOW); digitalWrite(6, LOW); break; } } } }