ESP32 - FADE LED
We are going to learn how to:
-
Fade LED using ESP32.
Video Tutorial
you can watch this video tutorial
Hardware Required
1 | × | ESP-WROOM-32 Dev Module | |
1 | × | Micro USB Cable | |
1 | × | LED | |
1 | × | 220 ohm resistor | |
1 | × | Breadboard | |
2 | × | Jumper Wires |
Wiring Diagram
Schematic Diagram
Image is developed using Fritzing. Click to enlarge image
Breadboard Connections
ESP32 Code
const byte led_gpio = 15; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is void setup() { ledcAttachPin(led_gpio, 0); // assign a led pins to a channel ledcSetup(0, 4000, 8); // 4 kHz PWM, 8-bit resolution } void loop() { ledcWrite(0, brightness); // set the brightness of the LED brightness++; // change the brightness for next time through the loop delay(10); // wait for 10 milliseconds to see the dimming effect if(brightness>255){ // restart the fading at the ends of the fade brightness=0; } }
※ NOTE THAT:
Becuase the esp32 does not support analogWrite() we used ledcWrite() instead.
Quick Steps
- power up your board
- Open Arduino IDE
- Select the right board
- Select the right port
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to ESP32
- Press and keep pressing the button several seconds
- See the changes you made
Code Explanation
Read the line-by-line explanation in comment lines of source code!
Book Tutorial
We are considering to make the book tutorials. If you think the book tutorials are essential, you can download it. download book
References
※ NOTE THAT:
Some components works on 3.3v and others works on 5v!