# Reading millivolts VCC on BabyO

Hello

Will this libray function work with baby O

I am using a 7.4volt (7400 milivolts) source, I would like to be able to sense when the voltage is getting too low ( the input voltage or VCC )

Hello,

Yes, that function should work just fine on the Baby Orangutan, and it should let you know when your input voltage drops below about 5V. However, if you want a more accurate way to estimate battery life, you should use a voltage divider to connect, say, 50% of the battery voltage to a spare analog input.

-Paul

Hello.

Note that if you follow Paul’s suggestion, you should also put the following line in your main loop:

That way, if your battery voltage drops enough so that Vcc becomes less than 5V, you will continue to get an accurate measure of the battery value.

- Ben

Sorry guys i have been away the past couple of days

Thank you for getting back.

Paul,

I do not quite understand what a voltage divider is , can they be made, please explain.

Ben,

``````set_millivolt_calibration(read_vcc_millivolts());
``````

so this reads and sets the calibration , is the calibration a sort of threshold of sorts?
I would have to set this at the start of the routine. Then I would at certain times call the

``read_vcc_millivolts``

guys,

i think I should also explain that I am using 7.4volt LiPo batteries. Very Dangerous.
Actually not dangerous as long as they are balanced during charging. These Lithium Polymer types
will completely die if the voltage gets too low. This is why I desperately need a low voltage warning routine.

Is 5volts a good cut off. EX: above 5volts good. Below 5volt give a warning?

many thx

Dave

A voltage divider is a simple circuit that uses two resistors to obtain an output voltage that is known fraction of the input voltage. Since your battery voltage is too high to safely connect directly to an analog input on your Baby Orangutan, you should connect it via a voltage divider with an output that will never exceed 5V. A voltage divider that divides the input voltage by two (i.e. one that uses two resistors of the same value) would be safe. If your analog input then reads 3000 mV, you know your battery voltage is twice that, or 6V.

I think a low-voltage cutoff of 5V is too low, so you don’t need to worry about measuring Vcc or setting the millivolt calibration. I think a good cutoff would be 6V, or maybe 5.5V if you want to live on the edge, which means you should set up a voltage divider circuit to monitor a safe fraction of your battery voltage using one of your analog inputs.

- Ben

Ben

What value of resistor do you recommend for the Voltage Divider?
my power is 7.4volts at 4000mah. Dividing 7.4 would be 3.2volts.

I’m not sure I understand your question. What do you mean by “enough for the analog input”? Dividing by two is safe, although if you divide by less you can get a higher resolution reading of your battery voltage. You don’t need a lot of resolution in your battery voltage measurement, though, given your application, so I’d go with something easy and safe.

- Ben

Ben

Forget that comment I get the basic idea

Can you recommend the resistor values for my 7.4volt ??

So I would wire battery to resistor (5v or under ) to an Analog input of the Baby O, the other to ground.

how can I set the function to look at a specific Analog inputs (PC0 – PC5 analog) ??

Have a look at the following link http://www.raltron.com/cust/tools/voltage_divider.asp, it gives the values for voltage divider resitors, you want to go with K values …

I am using 15k R1 to posative, 4.7k R2 to negative gives me 20.957 input voltage & 5V out, which code i use…

(test code)

``````  uint16_t bv = OrangutanAnalog::readMillivolts(0); // PC0
uint16_t volt =  bv * 4.1914; // 20.957 input / 5v output
Serial::printf_P(c_BVp,bv,volt);
``````

I recommend you use two of the same value resistor to make your divider, and use a resistor value between 10k and 100k (if you use small resistors, you still get a functional voltage divider, but you lose more power through it since there’s a low-impedance path from your battery’s positive terminal to ground). You should connect one resistor from your battery’s positive terminal to the analog input and the second resistor from the analog input to ground.

Your code can be something simple:

``````// get the battery voltage (in millivolts) from 1/2 voltage divider connected to PC3
unsigned int battery_voltage = 2 * analog_read_millivolts(3);

// check if battery voltage is less than 6V
if (battery_voltage < 6000)
{
... // do something to prevent draining your battery further
}``````

The above code reads the voltage on pin PC3 and multiplies by 2 to obtain the battery voltage (since you are measuring the battery voltage divided by 2) You should put it in your main loop so it gets run often. If you want to use a different analog input, change the argument to the analog_read_millivolts() function. See the analog section of the Pololu AVR Library command reference for more information. Since your battery voltage will always be above 5V, you do not need to set the millivolt calibration (though doing so won’t hurt anything).

- Ben

Guys

this is really great thank you

Only one thing, what is printf_P suppose to do - I probably won’t be printing anything,
I will most likely utilize the babyO’s LED to signal a low voltage warning.

thank you

Dave

If you want to be really safe, you can connect your battery to your system through a Pololu pushbutton power switch. The switch would make it easy to manually turn the system on and off, and it would let your Baby Orangutan shut off its own power if the voltage drops too low (just connect the OFF pin to one of your Baby Orangutan’s I/O lines and drive it high to shut off power). You could do a multi-step approach where you could turn on a “low battery LED” as a visual warning if the battery voltage falls below something like 6.5V, and you could shut off system power entirely if the battery voltage falls below something like 6V.

- Ben

Ben,

Yes I think I understand, this is very interesting. This little robot can do some amazing things.

How about taking to another level - Instead of a complete shut down, could this switch be used to switch to an AUX power supply or AUX battery?

I have plenty of room in my robot for an AUX battery.

Unfortunately, that isn’t something you could do with the pushbutton power switch. You could do something like this, but the circuit to do it would be more complicated than what I was suggesting.

- Ben

Got It Ben

I will try the shut off first then maybe later I will try a switch over circuit.

Dave

Bennn

well ok, I tried the 2 resistor method using this code

``````nsigned int battery_voltage = 2 * analog_read_millivolts(3);
// check if battery voltage is less than 6V
if (battery_voltage < 6000)
{  do something; }
``````

It works pretty good. For testing I am using a 9volt 650mah battery, and I used 2 - 100k resistors as was advised.

I did notice a slight power drop on M1 ( motor 1 ). The Motor seemed a bit more sluggish then usual.
For some reason M1 did not travel its full distance as usual using a setting of - set_motor(70, 0)
and delay_us(1800).

What could this mean? I am losing Power? or maybe the battery is running down or not sufficient enough.
Do i need to boost the “mah”

Let me Know

Thx

Dave

When you say a 9V battery, do you mean this kind of thing? 9V batteries are poor choices for applications that require a lot of current, such as driving motors, because they cannot deliver much current. You should have better results with NiMH packs or even AAA or AA alkaline cells.

Also, make sure you don’t put more than 5.5V on your Baby Orangutan’s inputs by picking a battery with a voltage above 11V. Note that new or freshly charged batteries can have voltages significantly higher than their nominal voltages. If you want to use higher input voltages, you should consider using a bigger voltage divider.

- Ben

Ben,

Yes I am using a 9volt, but i see now this is clearly the wrong choice for testing or even for live purposes.

I just got a 7.4volt 1200mah lipo battery, this will be my testing battery. I will of course let you know how things
went.

7.4 volts freshly charged could come out to be almost 8volts or a little over 8 volts. But with 8volts I should be
ok 8/2 = 4, and 4v is still under the 5volt limit.

I do not see going beyond 7.4volts at this time unless maybe in the future i decide to add a more complex robot control which may require more voltage and more amps.

Dave