Go Down

Topic: analogWrite() to analogRead() (Read 736 times) previous topic - next topic

NikolaM

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?

Thanks!

CrossRoads

#1
Feb 18, 2016, 01:52 am Last Edit: Feb 18, 2016, 01:52 am by CrossRoads
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:
http://sim.okawa-denshi.jp/en/CRlowkeisan.htm
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

NikolaM

How would I make that circuit?

CrossRoads

Did you try looking at the link I posted? Is not a difficult circuit.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up