ESP32-Project 2: Simple I/O
ESP32 able to take input from external environment and give output based on the input. Last time, we’ve made a blink project that we use to demonstrate on how the microcontroller gives output. Now we will learn on how ESP32 take input and act based on the input we give.
For this project, we will need…
- ESP32
- Breadboard
- Micro USB cable
- PC (with Arduino IDE installed)
- Male-to-Male Jumper Cable
- 10K Ω Resistor
- LED and 330 Ω Resistor (for each LED you use, you need one resistor)
if you have not install/set up your Arduino, the first project will help you on that.
Now, lets just start right in.
Simple I/O
as the name suggest, this project is very simple.
The Program
You can code the I/O program. When you want to choose the pin you want to use, be sure to read this first so you won’t choose the wrong pin. Here’s my program for this project. In my program, I’m using pin 4 as an input pin and pin 5 as an output pin.
after that, verify your sketch and upload it to your ESP32 using Micro USB Cable.
Breadboard
If you’re forget about breadboard, then use this for the mapping connection
- First, connect the GND (ground) pin, Input pin and Output pin (I use pin 4 as input pin and pin 5 as output pin), 3V3 pin, 10K Ω resistor, and button. The 3V3 pin will act as the electricity source for the button as an input for the input pin.
I put my GND pin there because my breadboard doesn’t connected in the middle and I’m using the other half for bigger space.
2. For the LED, connect the Output pin, LED, 330 Ω resistor, and GND. The result would be like this
then we’re finished on the Simple I/O project. But, is it enough? can we get any further? the answer would be yes, we can.
here’s my result
EXTRA : Random LED Generator
We’re using ESP32 as a microcontroller, not as a normal button to light up the LED when we pressed it. We can program ESP32 to do many things such as this one.
Program
for this extra project we’re going to use the random() function that provided by the Arduino IDE. To use this function you can read this. I’m using 3 output pin for this extra project and you can see my program here.
this program will make ESP32 to change the output type randomly while the button didn’t pressed. The change will occurred multiple times until you press the button. when the button pressed, the program will lock the type and give output based on what I wrote on the program. click the upload button to upload the program to you ESP32
Breadboard
For the breadboard, you can do the second step of Project 2 which is connect the each output pin with led, 330 Ω resistor, and GND pin.
unfortunately I only have LED with the same colour.
the result video is here
This article is part of a series of project that used for a course named Embedded System guided by Dr. Kusprasapta Mutijarsa, S.T., M.T.