Lighting Up the Onboard LED of the ESP-01 Board
Materials Needed:
- ESP-01 Module (Affiliate) – https://s.click.aliexpress.com/e/_DETsfWR
There are two types of boards the ESP-01 and the ESP-01 S. For this tutorial, i am using the “normal” ESP-01.
Source of the image and the comparison between the two boards: https://cyberblogspot.com/difference-between-esp-01-and-esp-01s/
- USB ESP-01 Programming Adapter with a CH340G chip (Affiliate) – https://s.click.aliexpress.com/e/_DETsfWR
- Computer with Arduino IDE installed
Goodies
- Datasheet – PDF download
Step 1: Installing Arduino IDE
- Download and install the latest version of the Arduino IDE from the official website: Arduino IDE Download
Step 2: Setting Up the Arduino IDE for ESP8266
- Open Arduino IDE, go to File -> Preferences.
- In the Additional Boards Manager URLs field, enter: http://arduino.esp8266.com/stable/package_esp8266com_index.json and click OK.
- Go to Tools -> Board -> Boards Manager, search for ESP8266 and install it.
Selecting the correct ESP8266 board:
- Go to
Tools
>Board
. - Find and select your specific board that is the Generic Esp8266
- And select the onboard LED Pin (The onboard LED is connected to Pin 1) and the Port:
Step 3: Installing the USB to TTL Converter Drivers (Optional->If problems arise)
Step 4: Connecting the ESP-01 to the Computer
To put the CH340G adapter in programming mode, follow these steps:
- Before plugging the USB ESP-01 programming adapter into a USB port on your computer, Press and hold the push button switch that you soldered in Step 2 for a few seconds.
- Plug the USB ESP-01 programming adapter into a USB port on your computer with the button pressed.
- Release the button: After a few seconds, release the push button switch. The Esp-01 should be in programming mode, and you can upload code to the ESP-01 module using your preferred development environment.
If having trouble, go to my previous blog post. It explains with images: https://www.edgemicrotech.com/preparing-the-usb-esp-01-programming-adapter-a-step-by-step-guide/
Step 5: Programming the ESP-01
The onboard led is connected to the GPIO 1 on the Esp-01 board, that is why we choose Builtin Led: “1”. This is why, in the code, the IDE knows that the onboard led is at GPIO 1.
Another thing is that the activation of the LED is made on logic “0”, that is, the logic is inverted based on the LED circuit of the board. In the code, we can see that the LED will be turned ON when the logic is “LOW”.
void setup() { pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output - IN THIS CASE THE PIN=1 } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, 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) delay(1000); // Wait for a second digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH delay(2000); // Wait for two seconds (to demonstrate the active low LED) }
- Copy the above code and paste it into the Arduino IDE.
- Select the correct board (Generic ESP8266 Module) and port from the Tools menu.
- Click on the Upload button to upload the code to the ESP-01. The next image demonstrate a successful upload. If not, go to the troubleshooting section.
Step 5: Result
- Remove the usb adapter and plug it back again (without pressing the button) – It will be now in running mode.
- The onboard Esp-01 led should blink.
Troubleshooting:
- The ESP-01 is not recognized by the computer: Ensure that the USB to TTL converter drivers are correctly installed. Check your connections and try a different USB port if necessary.
- The code doesn’t upload: Make sure you’ve selected the correct board and port in the Arduino IDE. Also, ensure that the ESP-01 is in programming mode (GPIO0 connected to GND during power up – The button has to remain pressed as the adapter is pluged on the computer).
- The LED doesn’t blink: Verify that your code is correct and has been uploaded successfully. Check that the LED is connected to GPIO1 (TX pin).
Conclusion: