user37426: I would like to calculate the amount of voltage from my A0 pin. I am using a 9v battery to power my load in my circuit. The formula to calculate voltage from the A0 pin is: 
    sens = analogRead(A0);
    vol = sens * ( 5.0 / 1023.0);

If my power source is 9v, should i replace the 5.0 to 9.0?

user27653: The analog input pins are 0V-5V strictly. If you need to measure a 9V input, you need to scale the voltage to test so that it is within a 0V-5V range. Often this is done with a voltage divider circuit.
In the example below, the 9V test voltage is divided in half, so the scale is 0V-4.5V, which is within range of the input pin.
Then your algorithm is
vol = sens * (2.0) * ( 5.0 / 1024.0);


simulate this circuit – Schematic created using CircuitLab

37426: <p>I would like to calculate the amount of voltage from my A0 pin. I am using a 9v battery to power my load in my circuit. The formula to calculate voltage from the A0 pin is: </p>

<pre><code>    sens = analogRead(A0);
    vol = sens * ( 5.0 / 1023.0);
</code></pre>

<p>If my power source is 9v, should i replace the 5.0 to 9.0?</p>
 27653: <p>The analog input pins are 0V-5V strictly. If you need to measure a 9V input, you need to scale the voltage to test so that it is within a 0V-5V range. Often this is done with a voltage divider circuit.</p>

<p>In the example below, the 9V test voltage is divided in half, so the scale is 0V-4.5V, which is within range of the input pin.</p>

<p>Then your algorithm is</p>

<pre><code>vol = sens * (2.0) * ( 5.0 / 1024.0);
</code></pre>



<p><img src="https://i.stack.imgur.com/mTaiH.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fmTaiH.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>
