user26717: I have been using Arduino Nano Analog input to measure voltages, in the range between 22-30 Volts.   
I want to measure it down to a tenth of a volt.
Following the instructions found here:
Read Analog Voltage (www.arduino.cc)
Which basically states that all I need is this code:
int sensorValue = analogRead(A0);
float voltage= sensorValue * (5.0 / 1023.0);

5.0/1023 = 0.004888 volts per increment in analog readings.  Turning that around, voltage input divided by this value should give me the sensor value.
Clearly they are presuming an input of 0-5 Volts.
My voltage divider is 1 Mohm (R1) between the voltage input and A2, then 200K (R2) from A2 to ground
30 Volts measures as 4.2 Volts.  22 Volts measures as 3.1 Volts.  
I think the range between 22 volts and 30 Volts doesn't present enough variation to the ADC - every single-digit change in the analogRead really make a big difference.  
The result is that it is giving me some crazy readings.  It is definitely nonlinear, so I am having real trouble trying to get it to be accurate at both ends of my measurement range.  Each slight ADC increment makes too much of a difference in the measured voltage because I am not using the full 0-5V input range.  
So I have been taking 10 readings in a row, at 500 ms intervals, then averaging.  
And yet it is not working well enough.  
(The biggest problem was the reference voltage and resolution were assumed to be 5/1024 which is completely incorrect.  Unless, as someone pointed out, I fed the Nanos directly at the 5V pin - which is still on the table - then it would be 5/1023)
I changed my resistor network to be 147K/23.5K
(Parts list:  1x 100K, 3x 47K)
R1 = 47K / 47K = 23.5K
R2 = 100K + 47K = 147K 
Also added a 100uF 50V electrolytic across the input from the battery bank I am monitoring.
I am feeding 5V to Vin.  And have figured out that the reference is measurable on the 5V pin, after the regulator, as 4.6V.  
Knowing that 
Resolution/Vref = ADC/Vin
I turned that around to be 
Vin = ADC * (Vref/Resolution)
Or, Vin = A2 * (4.6/1023)
Using a laboratory power supply I was able to confirm that with those settings 22 Volts came in at 3 Volts, and 29.98 came in right at 4 Volts.  
So
Vbat = A2 * (4.6/1023) / (R2/(R1+R2)) 
Vbat = A2 * (4.6/1023.0)/(147000/170500)
It is now operating reasonably well.  

(Yellow means the inverter is on)
--UPDATE--
  Changed resistors to 100K/20K for the divider and brought power to the 5V pin, bypassing the regulator for a reference.  It measures at 5.02 and is stable.
Results:
Charge controller meter says I am at 24.5 Volts.
Program says 24.64  (in the serial monitor).  

--ADDENDUM:  I want to pursue the Op-Amp setup.  But if 741 won't work will need a suggestion.  

Similarly, I went to 147K/47K for the 11-15 Volt circuit, and moved a higher-quality P/S over to the 5V pin, where it measures 5.03V; the results are better there, too. Just very slightly high.

So anyway, I'll put this to rest until I can figure out an op-amp circuit.
Thank you all for your help

user30198: In my opinion, this is a very Arduino specific question.
First of all, you can't map 22-30V to 0-4.4V with a voltage divider (unless you have a negative voltage available). A opamp introduces a little more inaccuracy but can map the voltage which increases the accuracy. I suggest to first get the maximum out of the voltage divider. If that is not enough, then you can try a opamp.
The impedance of the circuit at a analog pin should be 10k or less for a accurate ADC conversion. You can add a small capacitor (1nF to 100nF) from the analog pin to GND, to keep the value stable during the ADC conversion.
The 5V VCC as a reference is a pain. The best option is to use an external voltage reference, for example a LM4040. The second best option is the internal voltage reference of 1.1V. That voltage is never 1.1V, and you have to determine the actual voltage. That 1.1V also depends on the temperature and a little on VCC.
Only 10 readings for an average is a small number. Sometimes I use 5, sometimes I use thousands.
Is the Arduino Nano used indoors, with only a small variation in temperature ? Then select the analogReference(INTERNAL). Use for example 10k and 270k for the voltage divider and 10nF parallel with the 10k. Use the average of 100 samples. An accuracy to measure the 24-30V with 0.1V resolution should be easy to achieve and 50mV resolution should be possible.
If you prefer the 1M to measure the voltage, you can also use 1M and 33k. With the 10nF parallel to the 33k, the ADC conversion is probably still accurate enough.
[ADDED] You have not told us yet how accurate you want to read the battery voltage. Is ±500mV okay, or must you have ±20mV ? I say it again: 0.1V resolution is easy. But it all depends on a good reference. A bad reference means even worse results. Dit you take a look at analogReference to see what the INTERNAL reference is about ?

user30005: 
Changed resistors to 100K/20K for the divider 

you probably want to read the datasheet about the impedance requirement on the source and potential solutions there.

user3917: Rather than mapping to a range of 0 to 4.4 V, map to the range 0 to 1.1 V and use analogReference(INTERNAL) to select the internal band-gap 1.1 V reference source.  This reference voltage might vary a small amount as Vcc varies, but the variation is likely to be just a few millivolts.
To get your input voltage into the range  0 to 1.1 V, use a voltage divider and a voltage subtractor.  The voltage divider ratio should map the 8-volt range of 22 to 30 V to a 1.1 V range, ie, should have a ratio of 8:1.1, and should map 30 V to 4.125 V and 22 V to 3.025 V.
If you use a Unity Gain Differential Amplifier as described at electronics-tutorials.ws, the divider can use large resistors, ie, need not provide the under-10 KΩ resistance needed for ADC input; instead, the UGDA's low output impedance will meet that requirement when used as ADC input.  For example, you could have 1 MΩ in series with 160 KΩ for the main divider.
Feed that divided voltage into V1 in the diagram below.  Use a pot or another voltage divider to create a 3.025 V reference to feed into V2, perhaps based on the board's 3.3 V regulator output.
Note, use R1 = R2 = R3 = R4, with all of them some value like 10 KΩ or 20 KΩ.


26717: <p>I have been using Arduino Nano Analog input to measure voltages, in the range between 22-30 Volts.   </p>

<p>I want to measure it down to a tenth of a volt.</p>

<p>Following the instructions found here:</p>

<p><a href="https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage" rel="nofollow noreferrer">Read Analog Voltage</a> (www.arduino.cc)</p>

<p>Which basically states that all I need is this code:</p>

<pre><code>int sensorValue = analogRead(A0);
float voltage= sensorValue * (5.0 / 1023.0);
</code></pre>

<p>5.0/1023 = 0.004888 volts per increment in analog readings.  Turning that around, voltage input divided by this value should give me the sensor value.
Clearly they are presuming an input of 0-5 Volts.</p>

<p>My voltage divider is 1 Mohm (R1) between the voltage input and A2, then 200K (R2) from A2 to ground</p>

<p>30 Volts measures as 4.2 Volts.  22 Volts measures as 3.1 Volts.  </p>

<p>I think the range between 22 volts and 30 Volts doesn't present enough variation to the ADC - every single-digit change in the analogRead really make a big difference.  </p>

<p>The result is that it is giving me some crazy readings.  It is definitely nonlinear, so I am having real trouble trying to get it to be accurate at both ends of my measurement range.  Each slight ADC increment makes too much of a difference in the measured voltage because I am not using the full 0-5V input range.  </p>

<p>So I have been taking 10 readings in a row, at 500 ms intervals, then averaging.  </p>

<p>And yet it is not working well enough.  </p>

<p>(The biggest problem was the reference voltage and resolution were assumed to be 5/1024 which is completely incorrect.  Unless, as someone pointed out, I fed the Nanos directly at the 5V pin - which is still on the table - then it would be 5/1023)</p>

<p>I changed my resistor network to be 147K/23.5K</p>

<p>(Parts list:  1x 100K, 3x 47K)</p>

<p>R1 = 47K / 47K = 23.5K</p>

<p>R2 = 100K + 47K = 147K </p>

<p>Also added a 100uF 50V electrolytic across the input from the battery bank I am monitoring.</p>

<p>I am feeding 5V to Vin.  And have figured out that the reference is measurable on the 5V pin, after the regulator, as 4.6V.  </p>

<p>Knowing that </p>

<p>Resolution/Vref = ADC/Vin</p>

<p>I turned that around to be </p>

<p>Vin = ADC * (Vref/Resolution)</p>

<p>Or, Vin = A2 * (4.6/1023)</p>

<p>Using a laboratory power supply I was able to confirm that with those settings 22 Volts came in at 3 Volts, and 29.98 came in right at 4 Volts.  </p>

<p>So</p>

<p>Vbat = A2 * (4.6/1023) / (R2/(R1+R2)) </p>

<p>Vbat = A2 * (4.6/1023.0)/(147000/170500)</p>

<p>It is now operating reasonably well.  </p>

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

<p>(Yellow means the inverter is on)</p>

<p>--UPDATE--
  Changed resistors to 100K/20K for the divider and brought power to the 5V pin, bypassing the regulator for a reference.  It measures at 5.02 and is stable.</p>

<p>Results:</p>

<p>Charge controller meter says I am at 24.5 Volts.</p>

<p>Program says 24.64  (in the serial monitor).  </p>

<hr>

<p>--ADDENDUM:  I want to pursue the Op-Amp setup.  But if 741 won't work will need a suggestion.  </p>

<hr>

<p>Similarly, I went to 147K/47K for the 11-15 Volt circuit, and moved a higher-quality P/S over to the 5V pin, where it measures 5.03V; the results are better there, too. Just very slightly high.</p>

<hr>

<p>So anyway, I'll put this to rest until I can figure out an op-amp circuit.</p>

<p>Thank you all for your help</p>
 30198: <p>In my opinion, this is a very Arduino specific question.</p>

<p>First of all, you can't map 22-30V to 0-4.4V with a voltage divider (unless you have a negative voltage available). A opamp introduces a little more inaccuracy but can map the voltage which increases the accuracy. I suggest to first get the maximum out of the voltage divider. If that is not enough, then you can try a opamp.</p>

<p>The impedance of the circuit at a analog pin should be 10k or less for a accurate ADC conversion. You can add a small capacitor (1nF to 100nF) from the analog pin to GND, to keep the value stable during the ADC conversion.</p>

<p>The 5V VCC as a reference is a pain. The best option is to use an external voltage reference, for example a LM4040. The second best option is the internal voltage reference of 1.1V. That voltage is never 1.1V, and you have to determine the actual voltage. That 1.1V also depends on the temperature and a little on VCC.</p>

<p>Only 10 readings for an average is a small number. Sometimes I use 5, sometimes I use thousands.</p>

<p>Is the Arduino Nano used indoors, with only a small variation in temperature ? Then select the <a href="https://www.arduino.cc/en/Reference/analogReference" rel="nofollow noreferrer">analogReference(INTERNAL)</a>. Use for example 10k and 270k for the voltage divider and 10nF parallel with the 10k. Use the average of 100 samples. An accuracy to measure the 24-30V with 0.1V resolution should be easy to achieve and 50mV resolution should be possible.</p>

<p>If you prefer the 1M to measure the voltage, you can also use 1M and 33k. With the 10nF parallel to the 33k, the ADC conversion is probably still accurate enough.</p>

<p>[<strong>ADDED</strong>] You have not told us yet how accurate you want to read the battery voltage. Is ±500mV okay, or must you have ±20mV ? I say it again: 0.1V resolution is easy. But it all depends on a good reference. A bad reference means even worse results. Dit you take a look at <a href="https://www.arduino.cc/en/Reference/analogReference" rel="nofollow noreferrer"><code>analogReference</code></a> to see what the INTERNAL reference is about ?</p>
 30005: <blockquote>
  <p>Changed resistors to 100K/20K for the divider </p>
</blockquote>

<p>you probably want to read the datasheet about the impedance requirement on the source and potential solutions there.</p>
 3917: <p>Rather than mapping to a range of 0 to 4.4 V, map to the range 0 to 1.1 V and use <a href="https://www.arduino.cc/en/Reference/AnalogReference" rel="nofollow noreferrer"><code>analogReference(INTERNAL)</code></a> to select the internal band-gap 1.1 V reference source.  This reference voltage might vary a small amount as Vcc varies, but the variation is likely to be just a few millivolts.</p>

<p>To get your input voltage into the range  0 to 1.1 V, use a voltage divider and a voltage subtractor.  The voltage divider ratio should map the 8-volt range of 22 to 30 V to a 1.1 V range, ie, should have a ratio of 8:1.1, and should map 30 V to 4.125 V and 22 V to 3.025 V.</p>

<p>If you use a <a href="http://www.electronics-tutorials.ws/opamp/opamp_5.html" rel="nofollow noreferrer">Unity Gain Differential Amplifier as described at electronics-tutorials.ws</a>, the divider can use large resistors, ie, need not provide the under-10 KΩ resistance needed for ADC input; instead, the UGDA's low output impedance will meet that requirement when used as ADC input.  For example, you could have 1 MΩ in series with 160 KΩ for the main divider.</p>

<p>Feed that divided voltage into V<sub>1</sub> in the diagram below.  Use a pot or another voltage divider to create a 3.025 V reference to feed into V<sub>2</sub>, perhaps based on the board's 3.3 V regulator output.</p>

<p>Note, use R<sub>1</sub> = R<sub>2</sub> = R<sub>3</sub> = R<sub>4</sub>, with all of them some value like 10 KΩ or 20 KΩ.
<a href="https://i.stack.imgur.com/wDQlO.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wDQlO.gif" alt="enter image description here"></a></p>
