As long as the drive to the RC filter is symmetrical in nature and a square wave, then the smoothed DC output will be the average voltage
What do I mean by "the drive ... is symmetrical in nature"?
I mean that it must charge and discharge it equally well.
So let's say you had a single-ended drive, maybe a low side driver such as a MOSFET with an On resistance of 50mOhms. But the load is only 1k. You then have a 3.3k resistor and a 100uF capacitor RC filter.
When the MOSFET is On, the total resistance discharging the capacitor is through the MOSFET. 3.3k + 50mOhm = 3.30005K.
When the MOSFET is Off, the total resistance charging the capacitor is through the load resistance. 3.3k + 1k = 4.3k.
So the voltage across the capacitor will NOT be the average voltage. It will be quite a bit lower.
But let's make the ratio between the smoothing resistance and the other resistances much greater.
MOSFET 50mOhm
Load 10 Ohm
RC 100k and 3.3uF (same time constant as above)
Now the discharging resistance is 100.010K, charging resistance 100.00005k. Very little difference, so the smoothed voltage will only be very slightly lower than the actual average voltage.
Again, this is only true for a square wave.
Well, to be clearer, it -will- work for a pulsed sine wave or other waveform, but ONLY with symmetrical drive. In other words, the waveform must be coming from something like an Op Amp that can source and sink to maintain the waveform.
Clearly, a power supply with a transformer and rectifier diodes is not averaging the voltage with its capacitor. It is smoothing to the peaks, because the diode only sources current.
Still, if the PWM is coming from the same Arduino that is "measuring" the average voltage on the load, why not just calculate it from the PWM?