uint8_t LEDpin = D0; bool LEDstatus = LOW; // Set up the serial connection void setup() { Serial.begin(115200); pinMode(LEDpin, OUTPUT); digitalWrite(LEDpin, LOW); Serial.println("Ready. Type 'on' or 'off'."); } // Loop to monitor serial connection // When receiving an appropriate 'on' or 'off' // it will change the state of the LED void loop() { if (Serial.available()) { String command = Serial.readStringUntil('\n'); command.trim(); if (command == "on") { LEDstatus = HIGH; digitalWrite(LEDpin, HIGH); Serial.println("LED is ON"); } else if (command == "off") { LEDstatus = LOW; digitalWrite(LEDpin, LOW); Serial.println("LED is OFF"); } else { Serial.println("Unknown command. Use 'on' or 'off'."); } } }