Over the past couple of weeks I have barely had any free time, due to projects, assignments and the usual college buzz. What spare time I did have, I used to work on a second version of my self-balancing robot. This new concept will be battery-powered, remote-controlled and will have an improved visual appeal! Today I want to cover the basics of powering a micro-controller using a battery.

Testing Batteries 1
A lithium quad-copter battery, powering a Galileo Gen2 Board


How to connect a battery to the Micro-controller

Batteries are a very tricky thing to get right. You would expect that simply buying one with the same voltage as the power adapter for the micro-controller would do the job, but this would be a very foolish thing to do! The issue with batteries is that their voltage does not remain constant. The voltage stated on the battery tells you the approximate max. voltage of the battery, when it is fully charged. Once you begin to drain the battery, its voltage starts to drop. Battery power indicators work by analysing this voltage and then deducing how much power is left.

Now when we look at the most common micro-controllers (Arduino’s etc.), we can supply power in five different ways. Through the (1) USB jack, the (2) Power Jack, the (3) 5v, the (4) 3.3v and the (5) Vin Pins. I would always avoid the USB jack to provide power, as you may want to use it to monitor/debug the controller. Providing power through the 5v or the 3.3v pins is a rather stupid thing to do, unless you know what you are doing. These pins bypass the voltage levelling circuitry, meaning that if your voltage deviates by as little as ±0.1v, you could potentially fry the board. I have already destroyed one of my micro-controllers by playing around with these power pins, and I don’t intend to do that again!

Finally  we can use the Power jack or the Voltage-In (Vin) pin. These are essentially the same thing as the Power jack is connected to the Vin circuit. These inputs are then passed through the crystals and voltage levelling circuitry, and power the 5v and 3.3v lines. As the voltage of a battery varies with use, I would always connect it through the Vin pin/jack as it will deal with any variances and prevent the battery from frying the board.

Frying the board isn’t the only danger when using a battery! As the battery is drained and its voltage drops below the micro-controllers min. voltage requirement, a brown-out can occur. Brown-outs happen when the micro-controller partially shuts-down due to a power shortage. These usually cause the controller to restart, but they could also potentially damage the controller!


Protecting your Micro-controller from Brown-outs

The best way to prevent a brown-out is to make sure that the voltage supplied is always above the min. required voltage for the controller. If the battery falls below this minimum voltage, the micro-controller should display a warning message, or switch itself off. A nice way of dealing with this is to make the micro-controller monitor its own power supply by using one of the analogue input pins. If the voltage of the battery is less than 5v, it can be connected directly into the analogue pin. Otherwise, we will have to use a potential divider circuit is order to reduce the voltage to a safe level.

For my second version of the self-balancing robot, I am using a 11.1v lithium quad-copter battery to power a Galileo Gen2 Board and two 12v motors. As the voltage of the battery is greater than 5v, I used the following circuit in order to monitor the battery as it is being used:

Testing Batteries 2
Potential divider circuit, using a 100K and a 47K ohm resistor

The code used to monitor the battery percentage looks something like this:


The serial output I got from the system then looked like this:

The actual voltage of the battery according to the Lithium battery charger was 11.3 v, so the value recorded by the micro-controller is relatively accurate.


Here is a quick summary of the points I discussed above:

> Never connect a battery directly into the 5v or 3.3v pins of the micro-controller.

> Always ensure that the battery is within  the controller’s specified voltage input range.

>Avoid brown-outs by monitoring the voltage of the battery and switching off the system if it drops below the min. working voltage.

> When monitoring the voltage, take caution that the voltage being measured does not exceed the reference voltage (5v). Reduce the voltage by using a potential divider circuit.

The next part of my Self-balancing Robot series is long-overdue, so you should expect to see the post released soon on this blog!

Leave a Reply

sixteen − 6 =