Hi,
I'm using 4AA 1.5v batteries connected to vin pin of an Arduino Nano to power a Simon Says game .
Would like to use a 5 pack NI-MH AA 6V 2400mAh instead
and have a low battery signal on the oled display.
All the post I have read talk about 9v or 12 v batteries making use of a voltage divider.
My question is:
Using 6v do I still need a voltage divider ? If yes, which
resistors ?
If no, how to setup the wiring ?
You can use 4xAA NiMH to power Nano through the 5V pin. Even when fully charged, 4xAA NiMH should be less than 5.5V which is the limit for 5V pin.
Please understand there is a risk to this idea. If you forget and put non-rechargeable batteries in by mistake, you might fry the Arduino.
However you choose to power the Nano, it's best to use the internal 1.1V analog reference rather than the default 5V external reference, to measure the battery voltage against. So you will need a voltage divider to reduce the battery voltage down to 1.1V or less.
If you search the web for voltage divider calculator, you will find several pages that will help you calculate the correct resistor values. With a Nano, you want the total of the two resistors to be around 5K to 20K Ohms.
You may find that the battery life isn't great because the Nano's regulator will drop about 1.5V, so even when the pack is fully charged it's only just enough input voltage to output 5V. As the battery discharges, the voltage may drop to the point where the circuit no longer works long before the battery pack is empty.
If you need to extend the battery life, you might consider a 3.3V Arduino like a Pro Micro. These run at 8MHz rather than 16MHz, but that is rarely a problem.
The wiring is correct, but those resistor values may not be ideal because they are for 12V, not 6.4V, but they would work well enough.
One advantage of connecting a less-than-5.5V supply directly to the 5V pin of the Nano is that you can measure battery voltage directly without needing any voltage divider or other external parts. You do this by setting Vcc as the reference range for ADC, and then select the 1.1V bandgap source as the target. So in other words, you're measuring the voltage of the bandgap with reference to Vcc (which is also the battery voltage).
The result is a bit strange because as the battery discharges, the ADC reading goes up. And because the bandgap voltage can vary a bit between parts, you have to calibrate it in the beginning.
I found this code somewhere:
// Function created to obtain chip's actual Vcc voltage value, using internal bandgap reference
// This demonstrates ability to read processors Vcc voltage and the ability to maintain A/D calibration with changing Vcc
// Now works for 168/328 and mega boards.
// Thanks to "Coding Badly" for direct register control for A/D mux
// 1/9/10 "retrolefty"
int battVolts; // made global for wider avaliblity throughout a sketch if needed, example a low voltage alarm, etc
void setup(void)
{
Serial.begin(9600);
Serial.print("volts X 100");
Serial.println( "\r\n\r\n" );
delay(100);
}
void loop(void)
{
battVolts=getBandgap(); //Determins what actual Vcc is, (X 100), based on known bandgap voltage
Serial.print("Battery Vcc volts = ");
Serial.println(battVolts);
delay(1000);
}
int getBandgap(void) // Returns actual value of Vcc (x 100)
{
// For 168/328 boards
const long InternalReferenceVoltage = 1059L; // Adjust this value to your boards specific internal BG voltage x1000
// REFS1 REFS0 --> 0 1, AVcc internal ref. -Selects AVcc external reference
// MUX3 MUX2 MUX1 MUX0 --> 1110 1.1V (VBG) -Selects channel 14, bandgap voltage, to measure
ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
delay(50); // Let mux settle a little to get a more stable A/D conversion
// Start a conversion
ADCSRA |= _BV( ADSC );
// Wait for it to complete
while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
// Scale the value
int results = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L; // calculates for straight line value
return results;
}
However, this option depends on any sensors, displays, or other devices connected to the Nano also being able to run on something other than a regulated 5V supply.
@PaulRB Maybe I should use a 9v battery pack.
I found and used the resistance calculator you suggested it gave me 8 and 2 Ohms for my setup.
@ShermanP Thanks for posting that code, it answered my original question i.e. whether I needed a voltage divider.
However, I set up your code in "void setup()" , prints voltage when I start the game. At game over and a Soft Reset, it prints voltage again but the values are strange and I can't see how they can be used to signal low battery. Here's an example:
So you will need to adjust those values you have by a factor of 1000. If you adjust them both the same, the result (the output voltage) will be the same, but far less current will flow through, wasting less power.
But 8K and 2K would not be right either. 6.4V would be reduced to 6.4*2000/(8000+2000)=1.28V, which is above the 1.1V interval reference.
Well, remember that those numbers are 100 times the actual voltage. So 466 means 4.66V.
There is some jitter in the measurement. When I run the code I posted on a Nano powered by USB, the number fluctuates between 465 and 467. My meter says it's 4.68V, which is pretty close. If I wanted to calibrate it, I could just change the default value for the bandgap voltage until the readings match my meter:
const long InternalReferenceVoltage = 1059L;
But if you are on a battery, then you should also expect some variation in battery voltage caused by variation in load current. So you would need to be consistent as to when you take the reading.
I agree. The brownout detector is usually set at 2.8V on a Nano, so it won't operate below that unless you change the BOD voltage fuse setting. But you also have to consider at what voltage other devices connected to the Nano stop working.
2v. was just a wrong guess. My noob idea was to keep playing until something, buttons, oled, Arduino stopped responding. Then I'd measure the battery output. But will use the code to see how those values behave in a certain time lap.
By then it's too late. If the Arduino is not functioning properly then how do you expect it to make an accurate voltage reading.
However, that is besides the point right now. As other have pointed out, powering the Nano with 6V to the Vin pin is not a good idea. For reliable operation and without risk of damage to the Nano the input should be between 7V and 12V.
It may seem like it's workink OK but you are violating the specifications, and what happens is undefined.
You may also find that you will be re-charging more often that expected.
I know you did but certain things were not clear in that turorial and yes sometime it will work with only 6V but just because it's on the internet (including this forum) does not make it right.
So now you need to find the minimum voltage that the 9V rechargeable is allowed to drain down to and if it's above 7V that will be your battery low voltage.