Battery Monitor for Pi using Picaxe

Small, low cost Picaxe chips are ideal for developing or enhancing control system functionality.

Battery powered computer systems really need some warning when the supply is failing or lacks the level of charge required to safely start.

The low power consumption of an 8 pin Picaxe makes the 08M2 a good candidate for this task.
I included a Picaxe in this seasons bird box design to control powering on/off the Raspberry Pi, which is at the heart of the system. I now want to use more of the functionality of the 08M2 by using the analogue to digital converter (ADC) feature
The bird box system uses a 12V lead-acid battery which supplies power through a silicon diode to provide protection, just in case I'm careless enough to connect it the wrong way around.

Battery Monitor for Pi using Picaxe

Scaling the input voltage

The Picaxe runs from 5V derived from a linear regulator. So the ADC input range must be limited to 0-5Volts. My basic circuit just uses a voltage divider, like this:-

This should give me:-

Vpin3 = (14-0.7) x 10k/(18k+10k) = 4.75Volts

…for a fully charged battery, where the 0.7V represents the volt drop across the silicon diode. As an additional precaution I could fit a protection diode between the ADC input pin on the Picaxe and +5Volts like this:-

Picaxe test code

My test program for the Picaxe is very simple:-

‘ADC test
‘read adc 10 bit value and send via serial link

main:
readadc10 C.4,w1
SerOut 0,N4800,(#w1,10)    '10bit adc value & <CR>
pause 5000
goto main

I can test this on my Picaxe/Pi test rig either using minicom or a simple program (e.g. written in Gambas, Python or whatever).

Battery Monitor for Pi using Picaxe schematic

I went one stage further and modified my BirdBox2015 controller, so that I could test performance with the final hardware configuration

Since this circuit is designed to power the Pi on/off, I had to fit a manual over-ride to keep the Pi running. As the ULN2003 drivers are open collector Darlingtons, I just needed a link from IC1b pin 15 to 0V.

I also wrote a test program in Gambas to display individual ADC readings, equivalent voltages, and an average based upon 10 readings. Although I initially calculated the ADC reading-to-voltage conversion factor, I tweaked this by making small changes to the value until I had a reasonably close result, when compared to my digital voltmeter readings.

 

For more detail: Battery Monitor for Pi using Picaxe


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top