Project 5 Part 2 : ESP32 Output — PWM
Hello all, my name is Bryan Eagan. I’m currently a second year student in Institut Teknologi Bandung majoring in Information System and Technology. At the moment I’m taking a class namely Embedded Systems. In this class, we are learning how to partake in the ever growing technological scene. As an IT student we are not restricted to just software, instead we are also learning how to develop hardware and integrate the 2 elements to create IoT (Internet of Things).
For the second part of this week’s project, I will be utilizing the ESP32’s LED PWM controller that can be configured to generate PWM signals with difference properties.
For this project the components I will be using are :
- ESP 32 Board
- Breadboard
- Jumper wire : male to female, female to female
- 3x 330 Ohm resistor
- 1 LED
- Arduino IDE
I am referring this project to https://randomnerdtutorials.com/esp32-pwm-arduino-ide/. The circuit diagram looks like this :
I then coded the program according to the blog reference and which is like below :
// the number of the LED pin
const int ledPin = 16; // 16 corresponds to GPIO16
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
}
void loop(){
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
}
The main function of this function is to control the brightness of the LED by dims and shines seamlessly (increase and decrease brightness)
I had issues at first when uploading the sketch. I then looked up the internet on troubleshooting solutions to the problem, so I checked on my laptop’s device manager and sure enough I was using the wrong port. After fixing the port input, the code ran smoothly.
This is the demo video for project 5 part 2 :
https://drive.google.com/file/d/1mHcp4a__9_KIvHRIbvb5i1HfpSYIX7M0/view?usp=sharing