Simple I/O, The Stoplight

Andreana Hartadi Suliman
3 min readFeb 11, 2022

In this second project of II2260 Embedded System, I will tell you about design systems that utilize GPIO as input and output. The purpose of this system is to light the external LED connected to a switch.

Prepare these things first.

  1. ESP-32

2. Breadboard

3. USB cable

4. Male to Male Cable

5. LED 3mm

6. Resistor 330 Ohm & 10K Ohm

7. Switch

Besides that, you should have ARDUINO IDE on your computer. For the installation please see this article https://medium.com/@andreanahs/blink-for-the-first-time-484fe454b503

Let’s add the necessary components to the breadboard. Connect the ESP-32 with a switch. We will place the switch in the middle of the breadboard. If the switch doesn’t fit, the switch is in the wrong direction. We will use male-to-male jumper cables. The first male-to-male jumper wire will connect the positive pole with pin “3V3” on the ESP-32. The second one will connect the “ground” pin on the ESP-32 with a negative pole on the breadboard. The third one will connect the switch with pin “D4” on the ESP-32. The fourth one will connect the LED with pin “D5” on the ESP-32. The fifth one will connect the feet of the switch with the negative pole of the breadboard.

Remember to put the led lamp before the middle of the breadboard. Then add the 330-ohm resistor on the negative side of the LED (the shorter feet) and the negative pole of the breadboard. After that, we put the 10K-ohm resistor beside the switch, put the resistor on the negative pole of the breadboard also.

Here’s the illustration.

Open the ARDUINO IDE and type this code.

upload that to your ESP-32, and here is the result!

After finishing that one, I have an idea. What if I make a stoplight from this project. So I add two more LEDs and arrange the components on the breadboard. Simple, just repeat what you’ve already done with the LED before, like the male-to-male cable and 330-ohm resistor. This is what it looks like.

Open the ARDUINO IDE and type this code. Basically, it is the same as before. I just add a little modification.

upload that to ESP-32, and it will look like this!

Now you reached the end of this tutorial. See you next time!

--

--

Andreana Hartadi Suliman

If we are afraid of failure, it means we have limited our ability. — Hi, nice to see you here. Have a good day!