Red LED Lighting Hello World exercise – An Introduction to IoT Architecture, Hardware, and Real-Life Applications

To test the functionality of the ESP32 and to give you a taste of working with your new development kit, we are going to create the equivalent of a Hello World exercise—a practical exercise to light up a red LED bulb.

Components you’ll need

For this, you will need the following components:

An ESP32 microcontroller

A red LED (or any other color you would like to use)

An 830-hole breadboard

Two jumper wires

A 1k Ohm resistor

As you go along, you can refer to the upcoming assembly diagram to see the placement of the components on the board and get an overall idea of what we are trying to create to follow the instructions more easily.

Setting up the required hardware

Now, we will proceed to set up the hardware accordingly. The following figure shows the breadboard diagram that can be used as a reference while you follow the instructions to wire up the board, breadboard, LED, and resistor:

Figure 1.5 – Breadboard diagram for connecting the LED

The long leg of the LED is the anode and the shorter leg is the cathode. Attach the anode to hole 30j and the cathode to hole 30- on the breadboard.

We now will attach the ESP32 to the board. Attach the ground pin (GND on the board) as shown in the figure to hole 6h and 3g to hole 13h. You can either do this with a jumper cable or just directly put it down with the corresponding legs of the microcontroller as such.

Attach the 1k Ohm resistor with one leg on hole 30h and the other on hole 25h.

Attach a wire from hole 25g to hole 13i.

Attach a wire from hole 6j to 9-.

Now we have successfully set up the hardware that is needed for this practical exercise. We can now move on to producing the necessary code on our Arduino IDE.

Coding it up on the Arduino IDE

Now, we will upload the code for running the LED experiment to the ESP32. Use the following code for this purpose:
const byte led_gpio = 32;
void setup() {pinMode(led_gpio, OUTPUT);}
void loop() { digitalWrite(led_gpio, HIGH);delay(1000);
  digitalWrite(led_gpio, LOW);delay(1000);}

In the setup section of the code, the digital pin led_gpio is initialized as an output. Within the loop section of the code, we are simply alternating between turning the light on and off (as indicated by the high and low). Each wait 1,000 milliseconds—equivalent to one second—before switching to the next state, as seen with the delay statement.

And with that, you’ve just created your first IoT program on the ESP32!

Leave a Reply

Your email address will not be published. Required fields are marked *