analogWrite() to analogRead()

I want to write an analog value (e.g. analogWrite(128)) and then bring it through switches, buttons, etc. and have it come back to the analog pins so I can read the value.

Is there anything wrong with connecting one of the pins directly to an analog pin? If so, how should I do it instead?


At some point you’ll need to put a low pass filter on the 5V, 490/980 Hz square wave so it’s DC-ish for the analogRead. 10K and 4.7uF work well. This picture went from analogWrite(pin, 0) up to 250 in steps of 25.
You can try other values as well, say a lower R if you want more current to go thru:

How would I make that circuit?

Did you try looking at the link I posted? Is not a difficult circuit.