I am using a UnoR4 Wifi, powered by 4AA batteries. How can I check/display the battery level? I have an 1620 I2C lcd, and the R4 matrix for display.
I have found several battery monitor programs, but they get a bit complex, use a ref voltage etc.. Could use some advice, as I just want to add a simple batt check/display to an already complex program. It can be a subprogram, but need help adding that too. This is my first project.
A voltage reference is always used when using analog inputs. You may not realise that, because it defaults to using the Arduino's 5V pin as the reference voltage.
When the battery voltage is more than 5V when fully charged, you cannot connect it directly to an analog input. Anything over 5V would damage it. So you need to reduce the voltage down to less than 5V. A voltage divider, which is very simple and consists of 2 resistors, will do this for you.
But you may also have a problem when the battery voltage drops to below 5V. I'm not sure what circuits the R4 has. It may have a buck-boost circuit which maintains the 5V pin's voltage when when the battery is below 5V. If not, the 5V pin will drop to less than 5V and your measurements of the battery voltage will no longer be accurate.
This is why it is better to change to use a different voltage reference, one that is lower than the voltage of the battery when it is fully discharged. Fortunately most Arduino have another voltage reference built-in, so you can just switch to using that. Again, I'm not sure what the R4 has.
When using that lower voltage reference, don't forget to adjust your voltage divider so that the voltage of the battery when fully charged is reduced down to below the voltage of the voltage reference.
But this is a complex problem. As this is your first project, you don't yet have the knowledge required to know this.
When using a Uno R4 Wifi you have another set of problems, as the internal address structures are different than any early Uno.
Is this a real R4 or some sort clone? If it is a real R4 you need to post in the appropriate section, not this one. I can move it if you wish.
I would start by writing a sketch that just concentrates on this one aspect of the project. Once you have this working then you can try and incorperate it into your "complex" sketch.
That should be called a function not a subprogram when talking about C/C++.
This makes sense. Can you or someone point to some simple code that does this? I have found some examples, but are over my head, or designed for a more complex voltage measuring/warning project.
I just want to read nominal voltage and display it.
Give it 7V as input, 1.5V as output and select E24 as the resistor series (resistors that have a choice of 24 values in each decade, for example between 1000 Ohm and 10000 Ohm).
You want the total of the 2 resistors to be somewhere in the ball-park of 5K to 20K Ohms, so put 5000 and 20000 in the range for Rtot.
Hit 'Calculate' and it will give you a list of suitable pairs of resistor values, with the best at the top.
I got 3K and 11K. See if you get the same.
If so, find or buy those resistors. (No need for high power, standard 1/4 or 1/8 Watt is fine.)
The minimum input voltage is 6V for the R4. The R4 will stop working long before the entire battery capacity is used up. You will find that you need to replace the batteries quite often.
Using a battery to directly power a device that operates close to its voltage limits is not a good idea. However, you can insert a step-up converter capable of providing, for example, a constant 9V. Even if the battery voltage drops, the 9V supply remains stable.
I can port my code over to a lower current Arduino (like maybe a Nano ?). But not quite ready to do that.
I do not have room in my device for a higher capacity battery source, as I expected the 4AA's would be sufficient, short term. At this point need to get some measurements on the current draw to figure out what "quite often" is.
The first step is calibration: you apply the voltage you want to measure, measure it with the most accurate voltmeter you have, and check what value the ADC reads in Arduino. The calibration factor is simply:
cal = V(voltmeter) / ADC
At this point, you can measure the voltage simply by calculating:
ADC * cal
The calibration factor obtained in this experimental way not only already accounts for the attenuation introduced by the voltage divider, but also compensates for all the tolerances in the resistors and the internal reference.
If you change the Arduino or even just one of the resistors (even with one of the same value), the calibration needs to be redone. In fact, it's better to perform the calibration with the resistors already soldered in place.
Yes, is a real R4. Sure move it to the correct section. Was not aware it was the wrong one, or that R4 was different.
I figured battery check was fairly generic among arduino. I can use an AC adapter, just really liked the option/convenience of battery power.
I have not understood yet how functions get incorporated, but will start working on the battery check as a separate program. Could use some help with how to add a function.
The issue is the 6V requirement for the R4.
AA batteries like most batteries will drop in voltage as they are used. They can start out at 1.6V but will quickly drop to 1.5 and at that point you may have used only 20% of the battery capacity.
A nano actually have a higher voltage requirement.
With the battery pack plugged into the UNO R4 barrel connector, what Arduino Pin am I measuring the battery voltage from? Or do I need to connect a separate wire from battery + to an analog input pin?
It seems to me that anyone using a battery powered Arduino would need this battery check function by default. I could probably run my entire project at 3.3V, but the motor controller I am driving needs 5V, ideally. Not sure about the I2C 1602 LCD .
I've done some tests using a power supply to determine at what voltage an Arduino Uno R4 WiFi actually stops working.
I used an Arduino Mega 2560 to send SCPI commands via RS232 to the power supply to control it's output voltage. I got the voltage to ramp down from 10V to 2V, at a rate of 0.1V/s.
int buttonPin = 7; // start button
int maxVoltage = 1000; // voltage in units of 0.01V
int minVoltage = 200;
float voltageValue = 0;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
Serial1.print("VSET1:0.00");
delay(100);
Serial1.write("OUT0");
delay(100);
}
void loop() {
while (digitalRead(buttonPin)) {
// wait for start button to be pressed
}
Serial1.print("VSET1:");
Serial1.print(maxVoltage / 100);
delay(100);
Serial.println("OUT1");
Serial1.write("OUT1");
delay(5000);
for ( int i = maxVoltage; i >= minVoltage; i--) {
voltageValue = i / 100.0;
Serial1.print("VSET1:");
Serial1.print(voltageValue);
Serial.print(voltageValue, 2);
Serial.println("V");
delay(100);
}
Serial1.print("VSET1:0.00");
delay(100);
Serial.println("OUT0");
Serial1.write("OUT0");
delay(100);
}
On the Arduino Uno R4 WiFi, I ran the 'Blink' example, modified to give a 1kHz output.
Here are the results on an oscilloscope:
Channel 1 - yellow trace - Power Supply Voltage, falling from 10V to 2V.
Channel 3 - blue trace- 1kHz output from pin 13 of Arduino Uno.
At an input voltage of 5.5V, the Uno is still working, with a 5V, 1kHz signal on pin 13.
For input voltages between 5.5V and 3.0V, the output is no longer 5V, indicating that the buck converter is no longer giving out a 5V output.
Zooming in on the trace shows that the Uno R4 WiFi is still generating a 1kHz (nominal) output, but with diminishing output right up until the input voltage has fallen to 3V.
Nice test!
Interesting to see how it behaves out of arduino specs.
Considering that there is diode between Vin and the buck, looks like this can regulate almost down to Vin=Vout.
Perhaps you have tested similarly other boards as well?
So basically (with your example), what you are saying is the R4 will work to 3v? I am using it to create a 20khz PWM signal for a motor controller, blink some Led's, and drive and LCD.