#define BUTTON_PIN D2 // The ESP8266 pin connected to button's pin
#define BUZZER_PIN D1 // The ESP8266 pin connected to Buzzer's pin
void setup() {
Serial.begin(9600); // Initialize the Serial to communicate with the Serial Monitor.
pinMode(BUTTON_PIN, INPUT_PULLUP); // Configure the ESP8266 pin to the input pull-up mode
pinMode(BUZZER_PIN, OUTPUT); // Configure the ESP8266 pin to the output mode
}
void loop() {
int button_state = digitalRead(BUTTON_PIN); // read new state
if (button_state == LOW) {
Serial.println("The button is being pressed");
digitalWrite(BUZZER_PIN, HIGH); // turn on
}
else
if (button_state == HIGH) {
Serial.println("The button is unpressed");
digitalWrite(BUZZER_PIN, LOW); // turn off
}
}