user13502: I want to get a low voltage on output pin of Arduino mega. I have connected Pin 46 to A3, and wrote 120 value to 46 port. Expected was to get 2-3v on A3 input pin. Instead I always get 1023 values as input. Am I doing something wrong ?
void setup(){
  Serial.begin(9600);
  pinMode(46, OUTPUT);
  pinMode(A3,INPUT);
  }

void loop(){
  analogWrite(46,120);
  Serial.println(analogRead(A3));
  }


user4143: The analog outputs aren't real analog outputs, they are PWM.
That means that they rapidly switch from OFF to ON and back to OFF again.  The analog value is the ration of OFF time to ON time, known as the Duty Cycle.
You can convert that rapid switching to a real voltage by passing the signal through a low pass filter.  The simplest form is the RC filter:


13502: 

<p>I want to get a low voltage on output pin of Arduino mega. I have connected Pin 46 to A3, and wrote 120 value to 46 port. Expected was to get 2-3v on A3 input pin. Instead I always get 1023 values as input. Am I doing something wrong ?</p>

<pre class="lang-C++ prettyprint-override"><code>void setup(){
  Serial.begin(9600);
  pinMode(46, OUTPUT);
  pinMode(A3,INPUT);
  }

void loop(){
  analogWrite(46,120);
  Serial.println(analogRead(A3));
  }
</code></pre>
 4143: <p>The analog outputs aren't real analog outputs, they are PWM.</p>

<p>That means that they rapidly switch from OFF to ON and back to OFF again.  The analog value is the ration of OFF time to ON time, known as the <em>Duty Cycle</em>.</p>

<p>You can convert that rapid switching to a real voltage by passing the signal through a <em>low pass filter</em>.  The simplest form is the RC filter:</p>

<p><a href="https://i.stack.imgur.com/YALYT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YALYT.png" alt="enter image description here"></a></p>
