Creating a simple ESP32 Web Server to light LED's with Arduino IDE

Hello there!

It's been quite a while since my last post but I'm back and about to try another ESP32 project! So, this time I will try to create a simple webserver to control an ESP32. The basic idea of this project is to access an IP address over a web browser to wirelessly light-up LED's wired to an ESP32 via Wi-Fi Connection. This particular IP address is created by the ESP32 through Arduino IDE and will be accessible on any device's web browser connected to the local network. This project is based on randomnerdtutorials.com.

Step 1 - Hardware Requirement


So here's what we'll need:
  • A Microcontroller (ESP32)
  • A laptop/PC and compartments to connect to the ESP32
  • Enough Jumper Wires (I am using 3 Male-Females and 3 Male-Males)
  • A Breadboard
  • 2 LEDs
  • 2 Resistors
  • A power bank (optional)
Additionally, you can use variations of future devices to connect to the webserver, I have prepared my cellphone.

Step 2 - Software Requirement

If you haven't set up the Arduino IDE on your computer you can click here and check out my first article which contains a complete Software setup on Step 2.

Step 3 - Code and Compile

The code I am going to be using is available on this link to copy. Here's a sneak peek of the upper part of the code. Notice the 2nd and 3rd lines of it. That is where we will put the SSID and the password of the Network we are going to use. On a mac, you can easily find the SSID of your network you are currently using by clicking on the WiFi icon, it's the text where you find a checklist icon next to.


Step 4 - Circuit

Using the equipment I have prepared before I will now build the circuit. It is not exactly the circuit given by the randomnerdtutorials website, that one didn't work for me, so I did a little adjustments. Here's how it should look:


It truly is just a simple circuit containing 2 LEDs.  Here's a closer look on it:


You can see that I am using a brown jumper wire to trigger the left LED (it will receive signals from GPIO27 from the ESP) after it travels through the resistor first. The same thing goes for the right LED (GPIO26). Both LEDs then connect to GND through the black wire. I put the orange wire there just to be sure both LEDs were connected to the black wire because I had trouble with the breadboard.


Note: Make sure you are handling the LED legs correctly. The short leg is connected to Ground.

Step 5 - Upload

Once I was done making the circuit and made sure I had written the correct SSID and the network's password I uploaded the code. Remember to press the Boot button on the ESP32 while the uploader shows the "Connecting" message if needed. If the Arduino IDE is done uploading the ESP32 is ready to work the WiFi connection.

What we do now is open the Serial Monitor which should still be empty at this moment (make sure to pick the correct baud speed). Next we press the enable button (EN) on the ESP32 to get the address of the webserver. Here I got 192.168.1.5 on the monitor.





Step 6 - Observe and Explore

If everything went well the following is what we'll see on the browser we used to access the IP address given before. Make sure your device is connected to the correct network. (The one actually owning the SSID and password in your code).


Here's how it'll look like!



Notice that every command that you run on the webserver is being recorded by your Serial Monitor saying what was requested and what was enabled or disabled.

 

Since you have uploaded the code on your ESP32 you can also use a different power source while still running the same code. Here's how I tried using a power bank as the power source and my cellphone to access the webserver.

Hope you had fun! See you next time..


Comments

Popular posts from this blog

Inserting Data from an ESP32 to a MySQL database using PHP and Arduino IDE

Receiving Data on ESP32 from a HTML form of its Web Server using Arduino IDE

Plotting Real Time Sensor Readings on Web Servers using ESP32 and Arduino IDE