ESP32 PWM with Arduino IDE (Analog Output)

In this tutorial we’ll show you how to generate PWM signals with the ESP32 using Arduino IDE. As an example we’ll build a simple circuit that dims an LED using the LED PWM controller of the ESP32. We’ll also show you how you can get the same PWM signal on different GPIOs at the same time.

Before proceeding with this tutorial you should have the ESP32 add-on installed in your Arduino IDE. Follow one of the following tutorials to install the ESP32 on the Arduino IDE, if you haven’t already.

We also recommend taking a look at the following resources:

Watch the Video Tutorial

This tutorial is available in video format (watch below) and in written format (continue reading).

Parts Required

To follow this tutorial you need these parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

ESP32 LED PWM Controller

The ESP32 has a LED PWM controller with 16 independent channels that can be configured to generate PWM signals with different properties.

Here’s the steps you’ll have to follow to dim an LED with PWM using the Arduino IDE:

1. First, you need to choose a PWM channel. There are 16 channels from 0 to 15.

2. Then, you need to set the PWM signal frequency. For an LED, a frequency of 5000 Hz is fine to use.

3. You also need to set the signal’s duty cycle resolution: you have resolutions from 1 to 16 bits.  We’ll use 8-bit resolution, which means you can control the LED brightness using a value from 0 to 255.

4. Next, you need to specify to which GPIO or GPIOs the signal will appear upon. For that you’ll use the following function:

ledcAttachPin(GPIO, channel)

This function accepts two arguments. The first is the GPIO that will output the signal, and the second is the channel that will generate the signal.

5. Finally, to control the LED brightness using PWM, you use the following function:

ledcWrite(channel, dutycycle)

This function accepts as arguments the channel that is generating the PWM signal, and the duty cycle.

Dimming an LED

Let’s see a simple example to see how to use the ESP32 LED PWM controller using the Arduino IDE.

Schematic

Wire an LED to your ESP32 as in the following schematic diagram. The LED should be connected to GPIO 16.

esp32-pwm-dim-led

(This schematic uses the ESP32 DEVKIT V1 module version with 30 GPIOs – if you’re using another model, please check the pinout for the board you’re using.)

Note: you 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. For more information about the ESP32 GPIOs, read: ESP32 Pinout Reference: Which GPIO pins should you use?

Code

Open your Arduino IDE and copy the following code.

// 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);
  }
}

View raw code

You start by defining the pin the LED is attached to. In this case the LED is attached to GPIO 16.

const int ledPin = 16;  // 16 corresponds to GPIO16

Then, you set the PWM signal properties. You define a frequency of 5000 Hz, choose channel 0 to generate the signal, and set a resolution of 8 bits. You can choose other properties, different than these, to generate different PWM signals.

const int freq = 5000; 
const int ledChannel = 0; 
const int resolution = 8;

In the setup(), you need to configure LED PWM with the properties you’ve defined earlier by using the ledcSetup() function that accepts as arguments, the ledChannel, the frequency, and the resolution, as follows:

ledcSetup(ledChannel, freq, resolution);

Next, you need to choose the GPIO you’ll get the signal from. For that use the ledcAttachPin() function that accepts as arguments the GPIO where you want to get the signal, and the channel that is generating the signal. In this example, we’ll get the signal in the ledPin GPIO, that corresponds to GPIO 16. The channel that generates the signal is the ledChannel, that corresponds to channel 0.

ledcAttachPin(ledPin, ledChannel);

In the loop, you’ll vary the duty cycle between 0 and 255 to increase the LED brightness.

for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
    // changing the LED brightness with PWM
    ledcWrite(ledChannel, dutyCycle);
    delay(15); 
}

And then, between 255 and 0 to decrease the brightness.

for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
    // changing the LED brightness with PWM
    ledcWrite(ledChannel, dutyCycle);
    delay(15);
 }

To set the brightness of the LED, you just need to use the ledcWrite() function that accepts as arguments the channel that is generating the signal, and the duty cycle.

ledcWrite(ledChannel, dutyCycle);

As we’re using 8-bit resolution, the duty cycle will be controlled using a value from 0 to 255.  Note that in the ledcWrite() function we use the channel that is generating the signal, and not the GPIO.

Testing the Example

Upload the code to your ESP32. Make sure you have the right board and COM port selected. Look at your circuit. You should have a dimmer LED that increases and decreases brightness.

exp32-pwm

Getting the Same Signal on Different GPIOs

You can get the same signal from the same channel in different GPIOs. To achieve that,  you 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.

Schematic

Add two more LEDs to your circuit by following the next schematic diagram:

esp32-pwm-example

(This schematic uses the ESP32 DEVKIT V1 module version with 30 GPIOs – if you’re using another model, please check the pinout for the board you’re using.)

Code

Copy the following code to your Arduino IDE.

// the number of the LED pin
const int ledPin = 16;  // 16 corresponds to GPIO16
const int ledPin2 = 17; // 17 corresponds to GPIO17
const int ledPin3 = 5;  // 5 corresponds to GPIO5

// 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);
  ledcAttachPin(ledPin2, ledChannel);
  ledcAttachPin(ledPin3, 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);
  }
}

View raw code

This is the same code as the previous one but with some modifications. We’ve defined two more variables for two new LEDs, that refer to GPIO 17 and GPIO 5.

const int ledPin2 = 17; // 17 corresponds to GPIO17 
const int ledPin3 = 5;  // 5 corresponds to GPIO5

Then, in the setup(), we’ve added the following lines to assign both GPIOs to channel 0. This means that we’ll get the same signal, that is being generated on channel 0, on both GPIOs.

ledcAttachPin(ledPin2, ledChannel); 
ledcAttachPin(ledPin3, ledChannel);

Testing the Project

Upload the new sketch to your ESP32. Make sure you have the right board and COM port selected. Now, take a look at your circuit:

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

Wrapping Up

In summary, in this post you’ve learned how to use the LED PWM controller of the ESP32 with the Arduino IDE to dim an LED. The concepts learned can be used to control other outputs with PWM by setting the right properties to the signal.

We have other tutorials related with ESP32 that you may also like:

This is an excerpt from our course: Learn ESP32 with Arduino IDE. If you like ESP32 and you want to learn more, we recommend enrolling in Learn ESP32 with Arduino IDE course.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

60 thoughts on “ESP32 PWM with Arduino IDE (Analog Output)”

    • Hi dale.
      Those functions are part of the ESP32 core library for the Arduino IDE by default.
      So, once you have ESP32 installed on Arduino IDE, you don’t need to include anything else in your code to use those functions.
      Regards,
      Sara 🙂

      Reply
      • I am having the same problem! I have 2 similar projects, except one has a servo as well. I am trying to use PWM to vary the backlight intensity of an LCD on both projects, It works perfectly on one board, very badly on the other. I finally traced it down to a conflict between Servo.h and the ledc both using the same hardware timer (Servo wins out, and the PWM can only output a few hundred millivolts. (More if you lower the PWM frequency)
        Any idea of how to solve this issue?

        Reply
      • Actually, I see now, that as my servo output goes up (higher degrees of rotation) the PWM output goes up as well. This is for a PWM output of 255(in 8 bit resolution) The max PWM output is still only a few hundred millivolts.

        Reply
    • Actually, I have figured out the issue, for anyone else happening to read this. The Servo and ledc are using the same timer, and Serho.h grabbed the timer first. You need to set things up so that the ledc uses a different timer than Servo.

      Reply
  1. Hi Sara,
    “All GPIOs are outputting the same PWM signal. So, all three LEDs increase and decrease the brightness simultaneously, resulting in a synchronized effect.”

    Is itpossible to setup the different channels with different frequency and PWM in order to control the LED brightness separately?

    Reply
  2. You can also use macros when defining constants.
    So instead of const int ledPin = 16, you can use:
    #define LEDPIN 16
    it saves memory

    Reply
  3. const int ledPin = 16

    Will not actually consume any RAM: the compiler knows there is no reason to create a variable in RAM, so it’ll stay out of RAM (it will be stored in flash memory).

    #define ledPin 16

    Can actually become a bad practice… Why?
    Because it can lead to very hard to find bugs.
    Think about this mistake:

    #define ledPin 16;

    The “text-replace” nature of #define can mislead you with a stray semicolon or other unexpected replace…

    Apart from that, concerning the desired light effect on a LED, here is a simple idea to give the impression that it breathes:

    void loop(){
    ledcWrite(ledChannel, 128 – 128 * cos(2*PI*(millis() % 2001)/2000));
    }

    Reply
  4. hi
    can I have different frequencies for each of 16 pins?
    (different PWMs with adjaustble duty cycles and frequencies for all pins)?

    Reply
    • Hi.
      In theory, that’s possible. You need to create different PWM channels with different frequencies.
      However, I’m not sure if in practical terms, the ESP32 can handle all the 16 channels at the same time. You have to experiment to find out.
      Regards,
      Sara

      Reply
      • thank you very much for the reply.
        one another question
        can we change the frequency of a channel while running the program (with coding in the loop)?
        without resetting the esp?

        Reply
        • I have tried this driving a two tone sounder.

          change the frequency with ledcSetup(), and remember to then perform a ledcWrite().

          void loop() {
          // put your main code here, to run repeatedly:
          ledcSetup(1, 2048, 8);
          ledcWrite(1, 127);
          delay(2000);
          ledcSetup(1, 4069, 8);
          ledcWrite(1, 127);
          delay(2000);
          }

          Reply
  5. I’ve used Arduinos for a long time now but now need to use the ESP32 Devkit. I need to drive 4 motors (same freq for each, but different duty cycle) and I need to drive two or four RC type servos. When I run code for PWM for the BLDC motors, it works fine. If I run code to just position the servos, it works fine. When I try to combine the code, it appears that setting the freq for the PWM messes up the servos. It doesn’t want to give me a 50Hz frame rate. Do you know if there is a conflict between the servo library and the standard PWM functions of the ESP32? I’ve bought two of your courses, but the answer doesn’t seem to be there and I haven’t found anything online yet.

    Reply
  6. I’m wondering and confounded by how you would set off a second (or more) LED light at a different time, but repeat the same cycle as the first LED? Say, when the first LED begins to decrease brightness, the second LED would start to increase its brightness.

    I’ve tried calling a custom function nextLight() within the for loop. Doing that simply stops the first LED’s cycle while the nextLight LED runs fully. It’s wonky. Unintuitive.

    const int redLED1=26;
    const int redLED2=25;

    // setting PWM properties
    const int freq=5000; // 5000Hz for our LEDs here
    const int freq2=5000;
    const int ledChannel=0;
    const int ledChannel2=2;
    const int resolution=8;
    const int resolution2=8;

    void setup() {
    ledcSetup(ledChannel, freq, resolution);
    ledcSetup(ledChannel2,freq2,resolution2);
    // attach the channel to the GPIO to be controlled
    ledcAttachPin(redLED1, ledChannel);
    ledcAttachPin(redLED2, ledChannel2);

    Serial.begin(115200);

    }

    void loop() {
    // put your main code here, to run repeatedly:

    //increase LED brightness channel 1
    for(int dutyCycle=0;dutyCycle<=255; dutyCycle++){
    // changing the LED brightness with PWM
    ledcWrite(ledChannel, dutyCycle);
    delay(15);
    }
    // decrease LED brightness channel 1
    for(int dutyCycle=255;dutyCycle>=0;dutyCycle–){
    // changing the LED brightness with PWM
    if(dutyCycle==250){
    nextLight():
    }
    ledcWrite(ledChannel, dutyCycle);
    delay(15);
    }
    }

    void nextLight(){
    for(int dutyCycle=0;dutyCycle<=255; dutyCycle++){
    // changing the LED brightness with PWM
    ledcWrite(ledChannel2, dutyCycle);
    delay(15);
    }
    for(int dutyCycle=255;dutyCycle>=0;dutyCycle–){
    // changing the LED brightness with PWM
    ledcWrite(ledChannel2, dutyCycle);
    delay(15);
    }
    }

    Reply
  7. I tried the PWM example as coded in the tutorial and it did not function. I looked at a PinOut of a 30 Pin ESP32 board and found that ADC channel 0 is on the same pin as GP04. I moved the led to GP04, changed the code to reflect the move and the PWM example is now functional. It seems as if ADC channels are tied to specific GPIO’s.

    Reply
  8. Hi! I haven’t understood the channel that we need to choose. what is it depend on? in your code I have tried to change the channel from 0 to 2 It still worked.

    Reply
  9. Hello Sara, I am writing to you from Ecuador, my question is how can I perform a power control of a led using a potentiometer in an MCU Esp 32, thank you very much

    Reply
  10. Hello Sarah,
    I am not sure I understand the nature of the programmability of the LED channels and
    I feel confused by this sentence above, “You can get the same signal from the same channel in different GPIOs.”

    Might it be,
    You can set the same PWM signal to more than one GPIOs.
    Is it that you set a GPIO to a channel?
    Or are we setting a channel more than once to different GPIOs.

    For what it is worth I am on page 304 of your Building Web Server book and am getting a lot of value out of the book! I came here to better understand the LED and PWM system in the ESP32.

    Thanks,
    Forrest Erickson

    Reply
    • Hi Forrest.

      What I mean by “You can get the same PWM signal on more than one GPIO” is that you can set the same PWM signal (and the same channel) on more than one GPIO.

      In the ESP32, PWM channels produce PWM signals. You then attach those channels to the GPIOs where you want to have the signals. If you want to have the same signals on multiple GPIOs, you don’t need to create multiple PWM channels. You can use the same channel for multiple GPIOs.

      For example, it is possible to have the following scenarios:
      – PWM channel 1 –> signal on GPIO 23
      – PWM channel 1 –> signal on GPIO 22
      – PWM channel 1 –> signal on GPIO 21
      All GPIOs will have the same PWM signal.

      I’m sorry if this is confusing. English is not my native language, and sometimes my sentences seem clear to me, but not so much for others.

      Regards,
      Sara

      Reply
      • Sara,

        Thanks for the clarification. You did great. Re: “English is not my native language, and sometimes my sentences seem clear to me, but not so much for others.”
        It is my native and I still mangle it.

        I still had questions about the independence of the setup of the channels and did some experimenting based on your example code. I have pushed the results of the experiments to my github at: https://github.com/ForrestErickson/PWMExperiments

        Bottom line. You cannot program the frequency of channel 0 and 1. The last one you set governs both.
        I also experimented with higher frequencies and resolutions and here is a summary of what I found:
        // Set Freq: 80KHz 100KHz 200KHz 50KHz
        //const int resolution = 8; // Freq became 80.00 100.00 200.00
        //const int resolution = 9; // Freq became 80.00 100.0 156.3
        const int resolution = 10; // Freq became 78.13 78.13 78.13 50.00
        //const int resolution = 11; // Freq became 39.06 39.06 39.06
        //const int resolution = 12; // Freq became 19.53 19.53 19.53

        Hope this helps visitors.

        Reply
  11. Hello Sir/ Mam,

    I need help regarding the Motor driver control with esp32 using pwm signals.

    I tried with esp32 but both motors are working at a time I need individual pwm control for each motors.

    This is my ESP32 code:
    //ESP32
    // Set the Motor_1 PWM and Direction pin
    const int m1_pwm = 16; // 16 corresponds to GPIO16–>ESP32–>RX2
    const int m1_dir = 4; // 4 corresponds to GPIO4—->ESP32–>D4

    //// Set the Motor_2 PWM and Direction pin
    const int m2_pwm = 17; // 17 corresponds to GPIO17–>ESP32–>TX2
    const int m2_dir = 5; // 5 corresponds to GPIO4—->ESP32–>D5

    // setting PWM properties for motor 1
    const int freq_1 = 5000;
    const int resolution_1= 8;
    const int pwmChannel_1 = 0;

    // setting PWM properties for motor 2
    const int freq_2 = 5000;
    const int resolution_2= 8;
    const int pwmChannel_2 = 0;

    void setup(){
    // configure Motor PWM functionalitites
    ledcSetup(pwmChannel_1, freq_1, resolution_1);
    ledcSetup(pwmChannel_2, freq_2, resolution_2);

    // attach the channel to the GPIO to be controlled
    ledcAttachPin(m1_pwm, pwmChannel_1);
    ledcAttachPin(m2_pwm, pwmChannel_2);

    pinMode(m1_dir,OUTPUT); // Motor 1 direction output pin
    pinMode(m2_dir,OUTPUT); // Motor 1 direction output pin

    }

    void loop(){
    digitalWrite(m1_dir,HIGH); // m1 with clock wise direction
    ledcWrite(pwmChannel_1, 255); //0 t0 255 value
    delay(1000);

    digitalWrite(m1_dir,LOW); // m1 with anti clock wise direction
    ledcWrite(pwmChannel_1,50);
    delay(1000);

    ledcWrite(pwmChannel_1,0); //stop the motor 1
    delay(1000);

    digitalWrite(m2_dir,HIGH); // m2 with clock wise direction
    ledcWrite(pwmChannel_2, 20);
    delay(1000);

    digitalWrite(m2_dir,LOW); // m2 with anti clock wise direction
    ledcWrite(pwmChannel_2, 150);
    delay(1000);

    ledcWrite(pwmChannel_2, 0); //Stop the motor 2
    delay(1000);
    }

    When I run this code both motor are woking at a time There is no sequence of operation.

    Arduino Uno Code:
    //ARDUINO UNO

    //Motor 1 Direction and PWM
    #define m1_dir 8
    #define m1_pwm 9

    //Motor 2 Direction and PWM
    #define m2_dir 10
    #define m2_pwm 11

    void setup()
    {
    //Motor 1 setup
    pinMode(m1_dir,OUTPUT);
    pinMode(m1_pwm,OUTPUT);

    //Motor 2 setup
    pinMode(m2_dir,OUTPUT);
    pinMode(m2_pwm,OUTPUT);
    }
    void loop()
    {

    digitalWrite(m1_dir,HIGH); // m1 with clock wise direction
    analogWrite(m1_pwm,255);
    delay(1000);

    digitalWrite(m1_dir,LOW); // m1 with anti clock wise direction
    analogWrite(m1_pwm,50);
    delay(1000);

    analogWrite(m1_pwm,0); //stop the motor 1
    delay(1000);

    digitalWrite(m2_dir,HIGH); // m2 with clock wise direction
    analogWrite(m2_pwm,255);
    delay(1000);

    digitalWrite(m2_dir,LOW); // m2 with anti clock wise direction
    analogWrite(m2_pwm,50);
    delay(1000);

    analogWrite(m2_pwm,0); //stop the motor 2
    delay(1000);
    }

    Arduino uno is working fine.

    Please find the attached Google drive link for more information.

    LInk: https://drive.google.com/drive/folders/1Mxnd4OIE9hLgx_0LpEF3GXx2r5O5J6yQ?usp=sharing

    Please I need Help

    Thank you in advace.

    Reply
    • Hi.
      Change the number of your PWM channel 2.
      Instead of:
      const int pwmChannel_2 = 0
      use
      const int pwmChannel_2 = 1
      Regards,
      Sara

      Reply
  12. Hola Sara, he generado 2 ondas PWM en diferentes GPIO que varía según un potenciometro como señal analogica de entrada.
    Mi consulta es: ¿Se podría desfasar 90 grados las ondas?

    Reply
  13. Hi,

    I tried passing a potentiometer value which is read on ADC to PWM but it didn’t work. can you walk me through how to do it?
    BTW below is the code I wrote:

    const int ledPin=16;
    const int potPin=4;

    const int freq=5000;
    const int ledChannel=0;
    const int resolution=16;
    int dutyCycle=0;

    void setup() {
    // put your setup code here, to run once:
    ledcSetup(ledChannel, freq, resolution);
    ledcAttachPin(potPin, ledChannel);

    }

    void loop() {
    // put your main code here, to run repeatedly:

    dutyCycle=analogRead(potPin);
    //dutyCycle=dutyCycle/4;
    ledcWrite=(ledChannel, dutyCycle);
    }

    Reply
  14. A soros ellenállás a GPIO kimeneti áramának korlátozása miatt fontos, az esp védelmében.
    attól hogy csak rövit impulzusokra kapcsolja be a ledet attól még túllépheti a GPIO maximálisan megengedett áramkorlátját, ami a kimenet meghibásodásához vezethet.
    Steve

    Reply
    • Hi.
      Choose channels 0 and 3, for example.
      Those are not grouped.
      To know which ones are grouped, you have to test them. I remember that those two are independent.
      Regards,
      Sara

      Reply
  15. Thank you very much for your answer!
    I haven’t an oscilloscope. Is there a simple way to test it without an oscilloscope?

    Thank you again!

    Reply
  16. I connected a piezo element to ground and alternating to GPIOs 16 and 17.
    I can hear the same frequence using with channels 0 1 or 2 3. Frequence is different with 0 2, 0 3, 1 3.
    I think it could be a good test if you can’t use an oscilloscope.
    I uploaded this sketch:

    const int ledPin0 = 16;
    const int ledPin1 = 17;
    const int freq0 = 500;
    const int freq1 = 100;
    const int ledChannel0 = 1; const int ledChannel1 = 3; //OK
    //const int ledChannel0 = 3; const int ledChannel1 = 3; //OK
    //const int ledChannel0 = 0; const int ledChannel1 = 3; //OK
    // const int ledChannel0 = 0; const int ledChannel1 = 1; //NO it sounds the same frequence
    // const int ledChannel0 = 2; const int ledChannel1 = 3; //NO it sounds the same frequence
    const int resolution = 8; // dutycycle 128 is 50%
    void setup(){
    ledcSetup(ledChannel0, freq0, resolution);
    ledcSetup(ledChannel1, freq1, resolution);
    ledcAttachPin(ledPin0, ledChannel0);
    ledcAttachPin(ledPin1, ledChannel1);
    } //fine set up
    void loop(){
    ledcWrite(ledChannel0, 128);
    ledcWrite(ledChannel1, 128);
    } // fine void loop

    Reply
  17. hi:
    the functions used to control the PWM on the LEDs were unfamiliar for me, but that makes me wonder how I know how many or where I can find all the functions that ESP32 can handle, by any chance do you know where?
    Thank you in advance.

    Reply
  18. I think the tutorial is very confusing because it glosses over the fact that pairs of PWM channels use the same timer and therefore must use the same frequency. e.g Channel pairs (0,1) (2,3) (4,5) (6,7) must have the same frequency.

    I also don’t see how the clock source is selected. Does Arduino have some algorithm for doing this automatically ? Is the source fixed ?

    Reply
  19. Hi,

    I see this is an old tutorial, but have you tried the new ESP32-C3 processors yet?

    It seems Arduino doesn’t like the ledcSetup command for the C3 variety – using the 2.0.14 board manager from espressif.

    Any thoughts? I can’t get the simple code to compile because:
    error: ‘ledcSetup’ was not declared in this scope
    ledcSetup(PWM_CHANNEL1, PWM_FREQ1, PWM_RESOLUTION1);

    exit status 1
    ‘ledcSetup’ was not declared in this scope
    any thoughts would be appreciated

    Reply
  20. Hi:

    my esp32 dev kit v1 have 30pins, from pinout diagram it supports 22 pins with PWM, is that means 16 PWM channel not only support 16 pins output with PWM?

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.