Control LED using button switch- ESP 8266
Program
int led = 5; // LED pin D1
int button = 16; // push button is connected to D0
int temp = 0; // temporary variable for reading the button pin status
void setup() {
pinMode(led, OUTPUT); // declare LED as output
pinMode(button, INPUT); // declare push button as input
Serial.begin(9600);
}
void loop() {
temp = digitalRead(button);
if (temp == HIGH) {
digitalWrite(led, HIGH);
Serial.println("LED Turned ON");
delay(1000);
}
else {
digitalWrite(led, LOW);
Serial.println("LED Turned OFF");
delay(1000);
}
}
Comments
Post a Comment