Lab 3 DIGITAL INPUT AND OUTPUT







FACULTY OF ELECTRONIC 
ENGINEERING TECHNOLOGY





LAB 3 - DIGITAL INPUT AND OUTPUT






MUHAMMAD DANIAL BIN ZAINAL AZLAN
192020173




UNIT 1-ESP32 DIGITAL INPUT AND OUTPUTS

Project Example :


 In this example, we’ll read the state of a pushbutton, and light up an LED accordingly.


  1. SP32 DOIT DEVKIT V1 Board
  2. 5mm LED 
  3. 330 Ohm resistor 
  4. Pushbutton 
  5. 10k Ohm resistor 
  6. Breadboard
  7. Jumper wires


Code 

With the circuit ready, copy the code provided below to your Arduino IDE. 






Testing  project

After uploading the code, we need to test circuit.  LED should light up when we press the pushbutton:


and turn off after we release it.



UNIT 2 -ESP32 TOUCH SENSOR 


Touch Sensitive LED 

Lets build a simple touch controlled LED circuit 

  1. ESP32 DOIT DEVKIT V1 Board
  2. 5mm LED 
  3. 330 Ohm resistor
  4. Breadboard 
  5. Jumper wires



CODE 




This code reads the touch value from the pin we’ve defined, and lights up an LED when the value is below the threshold, this means when you place your finger in the aluminum pad.
 

TESTING PROJECT 

Touch the pin jumper wire and we will see the LED lighting up.



  • Open Tools and open serial monitor at a baudrate 115200 and we will see new values being display every second.We can see that when we touch wire connected to GPIO 4 ,serial monitor show that LED is ON.



  • Moreover,we can use serial plotter to better see the values.Tools > Serialplotter.



UNIT 3 -ESP32 PULSE-WIDTH MODULATION(PWM)


DIMMING AN LED 


  1.  ESP32 DOIT DEVKIT V1 Board 
  2.  5mm LED
  3.  330 Ohm resistor 
  4.  Breadboard 
  5.  Jumper wires

Note: We can use any pin you want, as long as it can act as an output. All pins that can act as outputs can be used as PWM pins.

CODE

GETTING THE SAME SIGNAL ON DIFFERENT GPIOs


We can get the same signal from the same channel in different GPIOs. To achieve that, we just need to attach those GPIOs to the same channel on the setup(). 

Let’s modify the previous example to dim 3 LEDs using the same PWM signal from the same channel.


  1.  ESP32 DOIT DEVKIT V1 Board 
  2.  3x 5mm LED
  3.  3x 330 Ohm resistor 
  4.  Breadboard 
  5.  Jumper wires

CODE



TESTING PROJECT 


  • All the GPIOs are outputting the same PWM signal.So all three LED increase and decrease the brightness simultaneously,resulting in a synchronized effect.

ESP32 READING ANALOG INPUTS


In this section we’ll learn how to read an analog input with the ESP32. This is useful to read values from variable resistors like potentiometers, or analog sensors.


To see how this works let’s make a simple example to read an analog value from a potentiometer.


  1. ESP32 DOIT DEVKIT V1 
  2. Board 
  3. Potentiometer 
  4. Breadboard 
  5. Jumper wires

Wire a potentiometer with ESP32 using the following schematic diagram as a reference, with the potentiometer middle pin connected to GPIO 34.





CODE



Upload the code  to  ESP32. Before uploading any code to  ESP, always check  the right board and COM port selected.

TESTING PROJECT 


Open the Serial Monitor at a baud rate of 115200. Rotate the potentiometer and see the values changing when we rotate the wiper .















Post a Comment

0 Comments