5.1 Lighting System
5.1.1 Light up an LED
Open the 5.1.1Blink code with Arduino IDE.
#define LED_BUILTIN 27 //LED pins
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Choose the ESP32 Dev Module board and COM port, and upload the code.

Test Result:
LED blinks per second, because io27 on ESP32 board outputs high and low level alternatively every second.
Power Level |
Result |
|---|---|
HIGH |
LED ON |
LOW |
LED OFF |

5.1.2 Controlthe LED with PWM
Open the 5.1.2PWM code with Arduino IDE.
#define led 27 //Define LED pin
void setup(){
pinMode(led, OUTPUT); //Set pin to output mode
}
void loop(){
for(int i=0; i<255; i++) //for loop statement. Constantly increase variable i till 255, exit the loop
{
analogWrite(led, i); //PWM output, used to control the brightness of LED
delay(3);
}
for(int i=255; i>0; i--) //for loop statement. Constantly decrease variable i till 0, exit the loop
{
analogWrite(led, i);
delay(3);
}
}
Choose the ESP32 Dev Module board and COM port, and upload the code.

Test Result:
At an appropriate signal frequency, PWM changes effective output voltage by changing the duty cycle in one period. In plain English, within a specified time, the more high level the IO port outputs, the greater PWM value is, and the lighter LED will be.
The LED module willslowly light up from dark to bright, and then from dark to bright.



