PROJECT #2 - Trying Input Output (I/O) Of ESP32 Dev Board Using The Arduino IDE
Hello again! For this project, I'm going to try turning on an external LED using a push button connected to ESP32 Dev Board. After that, I'm going for a more complex I/O using more components. You'll need these components :
- 1 Breadboard
- 1 ESP32 Development Board
- 4 / 9 Jumper Wire Male-to-Male
- 1 / 3 LED
- 1 / 2 Push Button
- 1 / 3 330 Ohm Resistor
- 1 / 2 10K Ohm Resistor
* X / Y (X for only simple I/O, Y for the more complex ones)
Push Button |
10K Ohm Resistor |
Now, let's get started!
PART 1: SIMPLE I/O
STEP 1: Prepare The Required Software
The required software is the same as the "LED Blink" project from before. You can check here and look for part 1 step 1 and continue there.
STEP 2: Set Up The Components on The Breadboard
Setup the side of the breadboard to become a ground and a power source by connecting the side to the GND and 3v3 pin beside ESP32 Dev Board (use the sideline [red/blue line] for reference). Then, connect a GPIO pin (you can choose any number from 2 / 4 - 5 / 13 - 33) to the longer side of the LED. After that, connect the shorter side of the LED to a 330 ohm resistor. The other side of the resistor should be connected to the ground (GND).
To set up the push button, put the push button in the middle of the breadboard and connect a power source to one side of the push button. After that, connect a GPIO pin to the other side of the push button. (Careful not to connect the GPIO pin to the power source directly in one line). Lastly, connect the GPIO pin from the push button to a 10K resistor that's connected to the ground. Refer to the image below for reference. (Source: https://randomnerdtutorials.com/esp32-digital-inputs-outputs-arduino/)
Circuit Scheme |
Full View |
Component View |
ESP32 Connection View |
STEP 3: Program The Dev Board
Copy the program code from this link or look at the image below. (Note: I'm using D4 for the push button and D5 for the LED)
Input Output 1 Button Program |
Don't forget to verify and upload the code to the ESP32 Dev Board.
STEP 4: Observe the Dev Board and Debug If You Have To
When you press and hold the push button, the external LED should be turned on until you release the push button. Refer to the video below for the correct result.
And that's it for the first part!~
PART 2: COMPLEX I/O
The concept of the program is to turn on a specific LED with a combination of 2 push buttons.
STEP 1: Setup The Components on The Breadboard
Based on the first part, connect 3 LEDs and 2 push buttons to a GPIO pin. In my case, I've set up left and right push buttons, and the 3 LEDs are (in order from left to right) red, yellow, and green. For my program, I'm going to make this logic :
- If both buttons are pressed, the yellow LED will turn on.
- If only the left button is pressed, the red LED will turn on.
- If only the right button is pressed, the green LED will turn on.
Refer to the photo below for my project.
Full View |
Component View |
ESP32 Connection View |
STEP 2: Program The Dev Board
The source code for this part is based on the first part. I'm just adding more variables and adjusting the if condition. The logic of the source code is still the same. You can see more in the image below.
Input Output 2 Button p1 |
Input Output 2 Button p2 |
STEP 3: Observe the Dev Board and Debug If Necessary
Refer to the video below for the result. It should be the same as the logic I explained in the first step.
Thank you for reading this blog and happy experimenting! ^^
- Ryu / 18220025
Comments
Post a Comment