PWM is not a voltage
An Uno pin is digital: 0 V or 5 V, nothing between. Yet a sensor test, a motor driver or an audio circuit may want 2.0 V. We make 2.0 V two ways: filtered PWM on an Uno, then a real DAC on an ESP32.
analogWrite(9, 102) does not make a voltage. A hardware timer switches pin 9 on and off 490 times a second. In each 2.04 ms cycle it is high 102/255 = 40% of the time: the duty cycle.
Averaged over a cycle the pin gives duty × 5 V = 0.4 × 5 = 2.0 V. An LED or a motor averages by itself. A circuit that needs a steady voltage does not: at any instant it sees 0 V or 5 V.
Filter it
Add a 10 kΩ resistor and a 10 µF capacitor to ground: a low-pass filter. While the pin is high, C charges a little through R; while it is low, C gives a little back. C cannot follow fast pulses, so it holds the average.
The filter's time constant is τ = RC = 10 kΩ × 10 µF = 0.1 s. Its cut-off is 1/(2πRC) ≈ 1.6 Hz. The 490 Hz pulses are about 310 times faster, so most of them are filtered out; the steady average passes.
After analogWrite, the output climbs like a charging capacitor: 1.26 V (63%) after one τ, 1.99 V after 5τ = 500 ms. So filtered PWM cannot change faster than about half a second. A smaller RC is faster.
Each pulse still nudges C up and down: about 24.5 mV peak to peak, 1.988 to 2.012 V. A bigger RC means less ripple but a slower output; a smaller one, the reverse. That trade-off is the price of filtered PWM.
A real DAC
A DAC, or digital-to-analog converter, turns a number straight into a voltage. The ESP32 has two 8-bit DACs, on GPIO25 and GPIO26. dacWrite(25, 155) gives 3.3 V × 155/255 ≈ 2.006 V: no pulses, so no filter to wait for.
8 bits give 256 levels, 0 to 255. One step is 3.3/255 ≈ 12.9 mV on the ESP32 and 5/255 ≈ 19.6 mV for Uno PWM. So exactly 2.000 V is out of reach: 154 gives 1.993 V, 155 gives 2.006 V.
What happens
;; step 1/9 · on-off pin digital: LOW = 0 V or HIGH = 5 V goal a steady 2.0 V way 1 PWM + RC filter (Arduino Uno R3, pin 9) way 2 a real DAC (ESP32, GPIO25)
The output plot shows the average voltage. The real trace also carries 24.5 mV of ripple at 490 Hz, about one pixel at this scale. The filter output comes through 10 kΩ, so anything that draws current from it pulls the voltage down: a 10 kΩ load would halve it. Put an op-amp voltage follower after the filter (see the Circuits lesson “Op-amp circuits”), or use a DAC with a buffered output.