Lab 2 ESP32 Digital Inputs and Outputs
Download Full PDF report (LAB2)
_____________________________
• ESP32 DOIT DEVKIT V1 Board
• 3x 5mm LED
• 10k Ohm resistor
• Pushbutton
• Breadboard
• Jumper wires
• Potentiometer
Exercise :
1) Push button to control a LED light to turn on when toggle
Code:
- First declare pin for LED output and switch input.- Then set initial button state to LOW and create a “serial.begin” to check output.
- Use If Else to control the LED to become HIGH when button is pressed (ACTIVE LOW)
- The value goes up when leave sensor untouched.
- The value goes down when touch the sensor.
- The value is almost same as digital serial output.
3) USING Pulse-Width Modulation(PWM) to dim an LED.
Code:
- Using dutyCycle as value PWM to control brightness of the LED.Output:
-The LED dim and bright over time can be observed.
4) Getting the same signal on different GPIOs using “ledcAttachPin”.
Code:
-Assign three LED output into one channel attach pin.Output:
- Three LED is operate in the same time can be observed.
5) Reading analog reading using potentiometer
Code:
Output:
-When increasing the resistance of potentiometer, we can observe the change in input port value
When increasing the resistance of potentiometer, we can observe the change in input port value in serial:
Conclusion :
As a conclusion, ESP32 is a very smart and convenience microcontroller that can be easily programmed using software. Besides, ESP32 able receive input from pin and output value after processed using pin again. In this lab session, I know how to program a ESP32 using software Arduino. First step is to define the pin we going to use for input or output in order to let ESP32 recognize and do it’s job. We can either send value HIGH or LOW at a time to output in LED light bulb and also receive input value from switch or sensor too. Besides, I also learned that the touch sensor will output different threshold value when in touch with different things. On the other hands, PWM is used to control a LED light bulb brightness by using value between 0-255(8bits). The higher the PWM, the brighter the LED light bulb.
Furthermore, I also learn how to assign a list of input into one channel to control them once together. Finally, a potentiometer can be used as an input for ESP32 too and user can spin the potentiometer to control the input value. By using If Else or While loop, many type of smart application can be created using this ESP32 microcontroller. Besides, ESP32 is also feature in wireless or Bluetooth control which I am going to learn in next lab
-End of Lab 2-
Comments
Post a Comment