Picture a fan that should start gently, run quietly, and still move enough air on a hot afternoon. PWM is the controller’s way to ask for less or more effort, but the physical result depends on frequency, duty cycle, driver losses, motor inertia, and the load.
Use PWM as an actuator command with evidence around it. The right setting is not just a number from 0 to 255; it is a duty, frequency, ramp, and feedback choice that keeps motion, brightness, heat, or position under control.
In 60 Seconds
Pulse Width Modulation (PWM) is a digital technique that simulates analog control by rapidly switching power on and off at a specific duty cycle. It enables precise control of motor speed, LED brightness, and servo position using simple digital microcontroller pins without analog hardware.
Key Concepts
PWM (Pulse Width Modulation): A technique for controlling average power by rapidly switching a signal between HIGH and LOW; duty cycle = (time HIGH) / (period) x 100%; a 50% duty cycle delivers 50% of the supply voltage as an average
Duty Cycle: The percentage of one PWM period during which the signal is HIGH; 0% = always off, 100% = always on; controls LED brightness, motor speed, heater temperature, and servo position (within a specific pulse width range)
PWM Frequency: The number of complete PWM cycles per second; motor control: use 20 kHz+ to avoid audible noise; servo control: 50 Hz standard (20 ms period); LED dimming: any frequency above 200 Hz to prevent visible flicker
PWM Resolution: The number of discrete duty cycle steps; ESP32 LEDC peripheral: 1-16 bit configurable; Arduino Uno: 8-bit (256 steps); higher resolution provides finer control but requires more timer bits
analogWrite() / ledcWrite(): Arduino function (analogWrite) and ESP32-specific function (ledcWrite) for setting PWM duty cycle; Arduino Uno/Nano output 8-bit 490 Hz PWM on most pins; ESP32 uses the LEDC peripheral requiring channel configuration before use
Servo Pulse Width: Servo motors use PWM with a 20 ms period (50 Hz); pulse width controls position: 1 ms = 0 degrees (minimum), 1.5 ms = 90 degrees (center), 2 ms = 180 degrees (maximum); use the Servo.h library which handles this automatically
Dead Time: A brief delay inserted between turning one switch off and its complementary switch on in an H-bridge or inverter; prevents shoot-through (both high and low side switches on simultaneously), which would create a short circuit across the power supply
Soft Start / Ramp Control: Gradually increasing PWM duty cycle from 0 to operating value at startup rather than switching immediately to full power; reduces inrush current, mechanical shock, and EMI during motor startup
Learning Objectives
After completing this chapter, you will be able to:
Calculate PWM duty cycles for various actuator applications
Configure ESP32 PWM channels for different frequencies and resolutions
Use the interactive PWM calculator for design decisions
Analyze PWM timing parameters for servo position control
Optimize PWM frequency for different actuator types
Chapter Roadmap
Use this chapter as a PWM design pass:
First separate duty cycle, frequency, and average voltage so the actuator command is not just “a number”.
Then configure ESP32 PWM channels and translate percentages into 8-bit, 10-bit, or 12-bit timer values.
Next choose frequency from the load: LED flicker, DC motor whine, servo frames, heater thermal mass, or solenoid chatter.
Finally check the deeper motor details: ripple current, decay mode, MOSFET switching loss, and the quizzes.
The checkpoints below pause after each stage so you can verify the numbers before adding another control layer.
For Beginners: PWM Control
Imagine flicking a light switch on and off very rapidly – so fast that the light appears to be dimmed rather than blinking. That is essentially what PWM (Pulse Width Modulation) does. By controlling how long the power stays on versus off in each cycle, you can smoothly adjust a motor’s speed or an LED’s brightness using just a simple digital on/off signal.
How It Works: PWM Creates “Fake” Analog Voltage
Imagine you’re pushing a child on a swing. You can’t push continuously (analog), but you can push in pulses (digital). The faster and longer you push each time, the higher the swing goes.
PWM works the same way:
Microcontroller limitation: GPIO pins output only 0V (OFF) or 3.3V/5V (ON) - nothing in between
The PWM trick: Switch ON and OFF thousands of times per second
Motor/LED response: Physical inertia smooths the pulses - the device “sees” the average voltage
Example: 50% duty cycle = ON for 0.5ms, OFF for 0.5ms, repeat at 1kHz = motor sees ~2.5V average from a 5V supply
The key insight: By varying the ON time (duty cycle), you create any “analog” voltage from 0% (always OFF) to 100% (always ON).
8.2 PWM Fundamentals
PWM (Pulse Width Modulation) is a digital technique that simulates analog control by rapidly switching power ON and OFF:
Duty cycle = Percentage of time the signal is HIGH (ON)
Frequency = How many times per second the signal repeats
Average power = Supply voltage x Duty cycle percentage
Why use PWM? Digital microcontrollers can’t produce true analog voltages (like 2.5V from a 5V supply). Instead, they rapidly switch between 0V and 5V. A motor or LED responds to the average voltage over time.
Putting Numbers to It
At 5kHz PWM with 50% duty cycle, each period is \(T = 1/5000 = 200\) μs. The signal is HIGH for \(t_{on} = 0.5 \times 200 = 100\) μs and LOW for 100 μs. A motor with mechanical time constant \(\tau_m \approx 50\) ms cannot respond to individual 200 μs pulses (\(\tau_m / T = 250\) cycles per time constant), so it sees only the average voltage: \(V_{avg} = 0.5 \times 5 = 2.5\) V. This is why PWM “fakes” analog – the actuator’s inertia performs the averaging.
Phoebe’s Field Notes: Why PWM Becomes Smooth Motion
Phoebe’s Why
PWM does not lower the voltage while the switch is on. It delivers full-height pulses, then relies on physics to average them. A motor winding is an inductor, so its current cannot jump instantly. The rotor has inertia, so its speed cannot follow every pulse. An LED or heater averages energy over the eye or thermal mass, and an RC filter averages charge on a capacitor. Duty cycle sets the mean push; frequency decides how much ripple survives between pushes.
The Derivation
Let the PWM period be \(T\) and duty fraction be \(D\):
\[T = \frac{1}{f_{PWM}}\]
\[t_{on} = DT\]
The switch applies \(V_s\) during the on-time and \(0\) during the off-time, so the period-average voltage is
\[V_{avg} = \frac{1}{T}\int_0^{DT} V_s\,dt\]
\[V_{avg} = D V_s\]
For a DC motor winding, inductance turns voltage into a current slope:
\[v_L = L\frac{di}{dt}\]
During an on-pulse with back-EMF \(E_b\) and winding resistance \(R\),
\[\frac{di}{dt} = \frac{V_s - E_b - iR}{L}\]
For a short first estimate, hold \(iR\) nearly constant inside one pulse:
An RC or thermal smoother has the same first-order idea: large time constant compared with \(T\) means small pulse-to-pulse ripple.
Worked Numbers: This Chapter’s Fan
5 kHz, 50% command:\(T = 1/5000 = 0.000200\) s \(= 200\) microseconds. \(t_{on} = 0.500 \times 200 = 100\) microseconds, and a 5 V supply gives \(V_{avg} = 0.500 \times 5.00 = 2.50\) V. With the chapter’s \(\tau_m \approx 50\) ms, \(\tau_m/T = 0.0500/0.000200 = 250\) cycles per mechanical time constant.
75% quiz command on 12 V:\(V_{avg} = 0.750 \times 12.0 = 9.00\) V, which is why the quiz answer is 9 V.
20 kHz greenhouse fan at 35%:\(T = 1/20000 = 50.0\) microseconds and \(t_{on} = 0.350 \times 50.0 = 17.5\) microseconds. The ideal terminal average is \(12.0 \times 0.350 = 4.20\) V. For the 0.5 A full-speed fan, the rough average current is \(0.350 \times 0.500 = 0.175\) A and input power is \(12.0 \times 0.175 = 2.10\) W.
Ripple check: with \(L = 1.00\) mH and \(E_b = 4.00\) V, the on-pulse slope is \((12.0 - 4.00)/0.00100 = 8000\) A/s. At 20 kHz and 35% duty, \(\Delta i_{on} = 8000 \times 17.5\times10^{-6} = 0.140\) A. At 2 kHz, \(t_{on}\) is \(175\) microseconds, so the same estimate gives \(1.40\) A of current rise – ten times more torque ripple and a much better chance of audible vibration.
8.3 Try It: PWM Motor Speed Control
Concept Check: PWM Fundamentals
Checkpoint: Average Command
You now know:
Duty cycle is the percent of each period spent HIGH; at 50% duty and a 5 V supply, the average actuator voltage is 2.5 V.
Frequency sets how often the periods repeat; at 5kHz, each period is 200 microseconds, not a new voltage level.
The 75% duty quiz uses the same rule on a 12V motor: 12V x 0.75 = 9V.
With the command meaning settled, the next step is turning a percentage into the actual timer value the ESP32 writes.
8.4 Interactive PWM Calculator
Show code
viewof targetSpeed = Inputs.range([0,100], {step:1,value:50,label:"Target Output (%)"})viewof pwmResolution = Inputs.select( [8,10,12], {value:8,label:"PWM Resolution",format: x => x ===8?"8-bit (0-255)": x ===10?"10-bit (0-1023)":"12-bit (0-4095)"})viewof pwmFrequency = Inputs.select( [490,1000,5000,20000], {value:5000,label:"PWM Frequency",format: x => x ===490?"490 Hz (Arduino)": x ===1000?"1 kHz": x ===5000?"5 kHz (ESP32 default)":"20 kHz (Silent)"})
// Convert angle to pulse widthint angleToPulseWidth(int angle){return map(angle,0,180,1000,2000);// 1000-2000 microseconds}// Using ESP32Servo library (handles timing automatically)#include <ESP32Servo.h>Servo myServo;myServo.attach(pin,1000,2000);// min/max pulse widthmyServo.write(90);// Move to 90 degrees
8.7 ESP32 PWM Configuration
// ESP32 has 16 PWM channels (0-15)// Each channel can have different frequency and resolution// Motor control - high frequency for silent operationconstint motorChannel =0;constint motorFreq =20000;// 20 kHz (above human hearing)constint motorResolution =8;// 0-255// LED control - lower frequency acceptableconstint ledChannel =1;constint ledFreq =5000;// 5 kHzconstint ledResolution =10;// 0-1023 (higher resolution for smooth fades)// Servo control - must be 50 Hzconstint servoChannel =2;constint servoFreq =50;// 50 Hz (20ms period)constint servoResolution =16;// High resolution for precise anglesvoid setup(){// Motor PWM ledcSetup(motorChannel, motorFreq, motorResolution); ledcAttachPin(MOTOR_PIN, motorChannel);// LED PWM ledcSetup(ledChannel, ledFreq, ledResolution); ledcAttachPin(LED_PIN, ledChannel);// Servo PWM (use ESP32Servo library instead for easier control) ledcSetup(servoChannel, servoFreq, servoResolution); ledcAttachPin(SERVO_PIN, servoChannel);}
8.8 PWM Speed to Value Conversion
// Convert percentage speed to PWM valueint speedToPWM(int speedPercent,int resolution){int maxValue =(1<< resolution)-1;// 2^resolution - 1return map(speedPercent,0,100,0, maxValue);}// Examples:// 75% speed at 8-bit resolution:int pwm8 = speedToPWM(75,8);// = 191 (out of 255)// 75% speed at 10-bit resolution:int pwm10 = speedToPWM(75,10);// = 767 (out of 1023)// 75% speed at 12-bit resolution:int pwm12 = speedToPWM(75,12);// = 3071 (out of 4095)
Checkpoint: Timer Values
You now know:
ESP32 PWM setup chooses a channel, frequency, and resolution before ledcWrite() can set the output.
At 75% command, the chapter’s examples map to 191 on 8-bit, 767 on 10-bit, and 3071 on 12-bit PWM.
Servo control is the exception to the “average voltage” mental model: a 50 Hz frame carries 1 ms, 1.5 ms, or 2 ms position pulses.
Now use those timer settings only after the load tells you what switching frequency it can tolerate.
8.9 Why Duty Cycle Matters for IoT
Energy Efficiency: LED at 50% duty cycle uses approximately 50% power, extending battery life
Precise Control: Achieve 256 speed levels (8-bit) or 1024 levels (10-bit) from a simple digital pin
No Analog Hardware: Digital MCUs can control analog-like behavior without DAC chips
Thermal Management: Lower duty cycles reduce heat in motors and drivers
Key insight: The actuator “sees” the average voltage, smoothed by its physical response time. A 1kHz PWM signal switching between 0V and 5V at 50% duty looks like steady 2.5V to a motor!
8.10 Worked Example: Smart Greenhouse Ventilation Fan
A greenhouse uses a 12V DC fan (rated 0.5A at full speed) controlled by an ESP32 via a MOSFET driver. The system adjusts fan speed based on temperature.
Step 1: Power at each operating point
Temperature
Fan Speed
Duty Cycle
Average Current
Power Consumed
Below 22C
Off
0%
0 A
0 W
22-25C
Low
30%
0.15 A
1.8 W
25-30C
Medium
60%
0.30 A
3.6 W
30-35C
High
85%
0.425 A
5.1 W
Above 35C
Full
100%
0.50 A
6.0 W
Power = Voltage x Average Current = 12V x (Duty Cycle x 0.5A)
Step 2: Daily energy consumption
Assume a typical summer day: 6 hours off (night), 8 hours at 30%, 6 hours at 60%, 4 hours at 85%.
Energy = (6 x 0) + (8 x 1.8) + (6 x 3.6) + (4 x 5.1) = 0 + 14.4 + 21.6 + 20.4 = 56.4 Wh/day
Compare to running the fan at full speed 24 hours: 6.0W x 24h = 144 Wh/day. PWM-based variable speed saves 61% of the daily energy.
Step 3: Why 20 kHz for this fan?
At lower PWM frequencies, the fan motor produces audible hum. A DC motor’s coils vibrate at the PWM frequency, and humans hear 20 Hz to 20 kHz. Choosing 20 kHz pushes the hum above hearing range, making the fan appear to run silently at any speed. The trade-off: higher PWM frequencies increase switching losses in the MOSFET driver (typically adding 0.1-0.3W at 20 kHz versus 1 kHz), but the acoustic benefit outweighs the small efficiency loss in an occupied greenhouse.
8.11 Choosing PWM Frequency: Decision Factors
The PWM frequency is not arbitrary – it must match the actuator’s physical characteristics and the application’s requirements. Choosing wrong creates audible noise, poor control, or wasted energy.
Actuator
Recommended Frequency
Why This Range
What Goes Wrong Outside It
LED
200-1000 Hz
Human eye flicker fusion threshold is ~70 Hz; 200+ Hz eliminates all visible flicker. Higher than 1 kHz wastes switching energy with no visual benefit.
Servo decoder IC expects 20ms period. Position is encoded as pulse width (1-2ms) within this period.
Any other frequency: servo misinterprets position or jitters. Most servos tolerate 40-60 Hz but 50 Hz is the standard.
Heating element
0.5-2 Hz
Thermal mass smooths temperature. Fast switching is unnecessary because the element’s temperature changes over seconds, not milliseconds.
Above 10 Hz: relay contacts wear prematurely (if relay-controlled). No benefit – heaters cannot respond faster than their thermal time constant.
Solenoid valve
100-500 Hz
Must be fast enough that the valve plunger does not physically open/close each cycle (it “floats” at average position).
Below 50 Hz: valve chatters (audible clicking, mechanical wear). Above 1 kHz: increased eddy current losses in the solenoid core.
Checkpoint: Frequency Choice
You now know:
The greenhouse fan table uses 30%, 60%, 85%, and 100% duty points on a 12V, 0.5A fan.
The daily energy estimate is 56.4 Wh/day instead of 144 Wh/day, a 61% saving before the driver-loss caveat.
Frequency is chosen from symptoms: below 70 Hz can flicker an LED, below 1 kHz can whine a motor, and above 50 kHz can overheat the driver.
After this point, use the game and quick reference to practice selection. The deep dive then explains what the motor current and power stage are doing underneath the simple duty-cycle command.
8.12 Try It: Actuator Control Challenge
8.13 Quick Reference: PWM Formulas
Duty Cycle (%) = (ON time / Period) x 100
Duty Cycle (%) = (PWM value / Max value) x 100
Examples (8-bit PWM, 0-255):
- PWM = 0 = 0% duty = 0V average (OFF)
- PWM = 64 = 25% duty = 1.25V @ 5V supply
- PWM = 128 = 50% duty = 2.5V @ 5V supply
- PWM = 191 = 75% duty = 3.75V @ 5V supply
- PWM = 255 = 100% duty = 5V average (FULL ON)
Average Voltage = Supply Voltage x (PWM Value / Max Value)
For Kids: Meet the Actuator Crew!
“I have a superpower,” announced Max the Microcontroller. “I can make things go fast or slow, bright or dim, even though I can only say ON or OFF!”
“That doesn’t make sense,” said Sammy the Sensor. “How can you make something half-bright if you can only turn it fully on or fully off?”
Max grinned. “Watch this!” He started flicking Lila the LED on and off – really, really fast. “Lila, how do you feel?”
“I feel… kind of medium bright!” Lila said, glowing at about half her usual brightness. “But I can tell you’re flickering me!”
“That’s because I’m switching you on and off 5,000 times per second,” Max explained. “Your eyes and most actuators can’t see the individual flickers – they just see the average. If I keep you ON for 25% of the time, you glow at quarter brightness. 75% of the time? Three-quarter brightness!”
“So it’s like a really fast strobe light that tricks everyone into seeing smooth dimming?” asked Bella the Battery.
“Exactly! It’s called PWM – Pulse Width Modulation. And the best part is, I only use as much of Bella’s energy as needed. At 50% duty cycle, we use about half the power!”
“I like that,” said Bella, smiling. “More power saved means I last longer!”
Connection: PWM Control meets PID Feedback Loops
PWM sets the output to an actuator, but how do you decide what duty cycle to use? That is where PID (Proportional-Integral-Derivative) controllers come in. A PID controller continuously reads a sensor (e.g., temperature), compares it to the setpoint, and adjusts the PWM duty cycle to minimize the error. For example, a smart thermostat reads the room temperature, calculates the PID output, and adjusts the heater’s PWM duty cycle accordingly. PWM without feedback is open-loop control; PWM with PID is closed-loop control. See DC Motor Control for PID implementation examples with motors.
8.14 Deep Dive: Duty Cycle, Ripple Current, and Decay Mode
PWM is not a middle voltage. The output still slams between 0 V and the full supply; the actuator responds to the time average because it cannot react to every fast pulse. Duty cycle sets that average command, frequency decides whether the pulses are smooth enough, and resolution decides how many distinct command levels fit between off and full on.
Figure 8.1: PWM changes average actuator output by changing the high-time inside each period; with a 12 V supply, 25%, 50%, and 75% duty cycles ideally average to 3 V, 6 V, and 9 V.
Take a 12 V ventilation fan controlled by an ESP32 through a MOSFET. At 20 kHz, one PWM period is 1 / 20000 = 50 microseconds. A 35% command keeps the switch on for 0.35 x 50 = 17.5 microseconds and off for 32.5 microseconds. The ideal average motor terminal voltage is 12 x 0.35 = 4.2 V. On an 8-bit PWM channel the requested register value is round(0.35 x 255) = 89; on a 10-bit channel it is round(0.35 x 1023) = 358. The motor still receives 12 V pulses, not a smooth 4.2 V source, but its winding inductance and rotor inertia make the shaft respond mostly to average torque.
The same arithmetic explains why PWM is efficient. If a small fan draws 0.5 A at full speed, full electrical input is about 12 V x 0.5 A = 6 W. A rough 35% operating point averages 0.35 x 0.5 = 0.175 A and 12 x 0.175 = 2.1 W, before driver losses and non-linear motor behavior. A linear regulator or series resistor would burn the unused energy as heat, while a MOSFET PWM driver spends most of its time either fully on with low resistance or fully off with almost no current.
Parameter
What it controls
Getting it wrong
Duty cycle
Average level: brightness, speed, torque
Changes the command, not the switching rate
Frequency
How fast the output switches
Too low causes LED flicker or motor whine; too high raises switching losses
Resolution
Number of duty-cycle codes
Too coarse makes fades and low-speed control step visibly
Pick PWM settings from the actuator backward. An LED dimmer should avoid visible flicker, so 500 Hz to a few kHz is usually fine. A brushed DC motor in a quiet room is often set near 20 kHz so the switching tone is above normal hearing. A hobby servo is different: its electronics expect a control pulse inside a 20 ms frame, so the frame frequency stays near 50 Hz and the useful command is the pulse width, commonly about 1.0 ms to 2.0 ms. At 50 Hz, a 1.5 ms center pulse is only 1.5 / 20 = 7.5% duty, but changing that duty changes the decoded angle rather than average motor voltage directly.
Resolution is the practical limit on how fine the command can be. With 8-bit PWM there are 256 codes, so one step is 1 / 255 = 0.392%. On a 12 V motor that is about 12 x 0.00392 = 47 mV of ideal average-voltage change per step. With 12-bit PWM there are 4096 codes, so one step is 1 / 4095 = 0.0244%, or about 2.9 mV on the same supply. Higher resolution helps slow LED fades and low-speed motor tuning, but timer hardware usually trades frequency against resolution.
On a motor, the off-time is not empty. The winding is an inductor, and an inductor resists sudden current changes. During each on-pulse current ramps up; during the off-time it keeps flowing through a freewheeling path. In slow decay, the H-bridge shorts the motor terminals so current recirculates and decays gently, which improves low-speed smoothness. In fast decay, the driver applies reverse voltage or returns energy toward the supply, so current drops quickly; this tracks commands better but increases ripple. Many drivers use mixed decay.
A quick ripple estimate shows why frequency matters. Approximate a small motor winding as R = 6 ohm and L = 1 mH on a 12 V supply. If the shaft is already spinning so back-EMF is 4 V, the on-pulse applies roughly 12 - 4 = 8 V across the winding. The current slope is di/dt = V/L = 8 / 0.001 = 8000 A/s. At 20 kHz and 35% duty, on-time is 17.5 microseconds, so the current rises by about 8000 x 17.5e-6 = 0.14 A during the on-pulse. At 2 kHz with the same duty, on-time is 175 microseconds and the rise is about 1.4 A. That larger ripple can produce audible vibration, rough torque, and extra heating even though the average duty cycle is unchanged.
The power stage must also survive the switching. A MOSFET that drops only 80 mV at 1 A dissipates about 0.08 W while fully on, but if slow gate drive leaves it in the linear region for 1 microsecond on each edge, 20 kHz PWM creates 40000 switching edges per second and edge losses can become comparable to conduction loss. This is why motor boards include gate resistors, flyback paths, bulk capacitors near the driver, and thermal ratings. The waveform is digital at the pin, but the motor current, heat, and electromagnetic noise are analog consequences.
Checkpoint: Motor Driver Evidence
You now know:
At 20 kHz and 35% duty, the fan example has a 50 microsecond period, 17.5 microseconds on-time, and an ideal 4.2 V average from 12 V.
The same 35% command is about 89 counts on 8-bit PWM and 358 counts on 10-bit PWM.
Ripple depends on winding inductance and frequency: the chapter’s 1 mH example rises about 0.14 A at 20 kHz but about 1.4 A at 2 kHz.
Driver evidence includes decay mode, freewheeling path, gate drive, bulk capacitance, and thermal rating, not only the duty number.
8.15 Summary
PWM turns a digital pin into proportional actuator control by switching quickly and changing duty cycle. The correct design depends on matching frequency and resolution to the load: servos need timed pulses, DC motors need current smoothing and quiet switching, and LEDs need flicker-free brightness control.
Key Takeaway
PWM is the universal technique for controlling actuator output (speed, brightness, position) using digital microcontroller pins. The key parameters are duty cycle (controls power output), frequency (must match the actuator type – 50 Hz for servos, 1-20 kHz for motors, 500+ Hz for LEDs), and resolution (determines how many discrete control levels are available). The average voltage delivered to an actuator equals the supply voltage multiplied by the duty cycle percentage.
1. Using analogWrite() on ESP32 Without LEDC Configuration
The Arduino analogWrite() function does not work on ESP32. The ESP32 uses the LEDC (LED Control) peripheral which requires channel setup (ledcSetup(channel, freq, resolution)) and pin attachment (ledcAttachPin(pin, channel)) before ledcWrite() will function. Attempting analogWrite() on ESP32 silently produces no PWM output.
2. Wrong PWM Frequency for Servo Control
Standard RC servos require 50 Hz PWM (20 ms period). Using higher frequencies (e.g., 1 kHz from analogWrite()) causes the servo to jitter, overheat, or receive incorrect position commands. Always configure the PWM channel to exactly 50 Hz when using PWM to control servo motors — or better, use the Arduino Servo.h library which handles frequency automatically.
3. Keep Motor PWM Above 20 kHz
DC motor coils vibrate mechanically at the PWM switching frequency. PWM at 1 kHz or 5 kHz produces clearly audible tones from the motor. Set motor PWM frequency above 20 kHz (beyond human hearing range) to eliminate audible noise. This requires direct timer configuration on Arduino; the ESP32 LEDC peripheral supports frequencies up to 40 MHz.
4. PWM Voltage vs Driver Inputs
ESP32 GPIO outputs 3.3 V HIGH; many H-bridge driver ICs (L298N) have input thresholds designed for 5 V logic and may not reliably switch at 3.3 V. Verify the driver IC’s input HIGH voltage threshold against your microcontroller’s output voltage; some drivers require a logic level shifter or accept 3.3 V inputs directly (TB6612FNG, DRV8833).
8.20 What’s Next
If you want to…
Read this
Learn about servo motor control which uses specific PWM pulse widths