#include <Arduino.h>
// Define LED pin
const int ledPin = 2; // Use pin 2 for the LED on the ESP32
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set LED pin as output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Check if data is available to read from serial
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
// Process the command
if (command == "On" || command == "on") {
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("LED turned on");
} else if (command == "Off" || command == "off") {
digitalWrite(ledPin, LOW); // Turn off LED
Serial.println("LED turned off");
} else {
// Invalid command
Serial.println("Invalid command");
}
}
}