/* Based on the ESP8266 Blink by Simon Peter Blink the red LED(pin 13), and green LED(pin 12) alternating. Build in pushbutton on pin 14 on the ESP-01 module This example code is in the public domain */ int ledGreen = 13; int ledRed = 12; int motor = 16; int buttonPin = 14; int buttonState = 0; void setup() { pinMode(motor, OUTPUT); pinMode(ledGreen, OUTPUT); // Initialize the LED pin as an output pinMode(ledRed, OUTPUT); // Initialize the LED pin as an output pinMode(buttonPin, INPUT); //initialize button pin as input Serial.begin(9600); } // the loop function runs over and over again forever void loop() { digitalWrite(ledGreen, HIGH); // Turn the LED on (Note that LOW is the voltage level digitalWrite(ledRed, LOW); // Turn the LED on (Note that LOW is the voltage level // but actually the LED is on; this is because // it is active low on the ESP-01) Serial.println("low"); delay(1000); // Wait for a second digitalWrite(ledGreen, LOW); // Turn the LED off by making the voltage HIGH digitalWrite(ledRed, HIGH); // Turn the LED on (Note that LOW is the voltage level Serial.println("high"); delay(500); // Wait for two seconds (to demonstrate the active low LED) buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(motor, LOW); Serial.println("btn high"); } else { // turn LED off: //digitalWrite(ledGreen, LOW); digitalWrite(motor, HIGH); Serial.println("btn low"); } }