LAB 2 : Exploring the ESP32 GPIOs

LAB 2 ESP32 Digital Inputs and Outputs 

Objective :
- To learn how to use GPIO port on the ESP32 controller to input and output digital value.
- Able to use ESP32 to read input like switch and touch sensor and show output value.
- Learn how to code using Arduino and print output.


Equipment and components :

• ESP32 DOIT DEVKIT V1 Board

• 3x 5mm LED

• 10k Ohm resistor

• Pushbutton

• Breadboard

• Jumper wires

• Potentiometer



Introduction : 
    ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs either a Tensilica Xtensa LX6 microprocessor in both dual-core and single-core variations, Xtensa LX7 dual-core microprocessor or a single-core RISC-V microprocessor and includes built-in antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power-management modules. 

    In this lab, I am going to learn how to use Arduino ESP32 to create a custom programmed application which can detect and output value on LED. By connect the pin of ESP32 to desired input or output device and define it in the code, we can obtain the objective we want. Figure 1 show the I/O pins on the ESP32:

Figure 1


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)

Output:

After pressed the switch:

Serial Output at Baud rate 115200:



2) Using Touch Sensor on the default pin of ESP32(touchRead())
Code:

Output:

-The LED turn on when pressed the wire

The threshold value before and after touched:

Besides, we can also use the serialplotter to see the graph value change:











          

  - 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

Popular posts from this blog

LAB 3

LAB 1