// Define the pin numbers for the button and LED const int buttonPin = D1; // button connected const int ledPin = D0; //LED connected void setup() { // Set the button pin as INPUT pinMode(buttonPin, INPUT); // Set the LED pin as OUTPUT pinMode(ledPin, OUTPUT); // Start Serial communication Serial.begin(9600); } void loop() { // Read the state of the button int buttonState = digitalRead(buttonPin); // Check if the button is pressed if (buttonState == HIGH) { // If the button is pressed, turn on the LED digitalWrite(ledPin, HIGH); } else { // If the button is not pressed, turn off the LED digitalWrite(ledPin, LOW); } // Print button and LED states to Serial monitor Serial.print("Button State: "); Serial.print(buttonState); Serial.print(" LED State: "); Serial.println(digitalRead(ledPin)); // Add a small delay to avoid flooding the Serial monitor delay(100); }