So you’d kind of like to know when the battery in your bike is getting a bit flat, but you’re unsure how to proceed. This will go over creating a bike battery gauge that will turn on a bunch of visual indicators depending on the voltage level of the connected battery. This project can be done with a few components lying around in your workbench. However, you will need a small Microchip PIC microcontroller as the core!
The PIC microcontroller, PIC12F675P, is available as an eight-pin chip, and even though it is tiny, it has 1,024 words of program memory, 64 bytes of RAM and 128 bytes of EEPROM, an internal oscillator, timers, a 10-bit ADC, and a comparator. This simple project uses the microcontroller’s internal oscillator, and you don’t need an external crystal, so there is even less to go wrong!
The circuit shown here utilizes four pins of the PIC12F675P (IC2) microcontroller to drive four visual indicators (LED1–LED4). The 1K resistors (R3–R6) provide current limiting for the LEDs, and the LM1117-5.0 (IC1) low-drop linear voltage regulator caters a regulated 5-V DC power supply for IC2. In a nutshell, IC2 monitors the voltage at its analog input AN0 (pin 7) and drives the LEDs as a small bargraph display with corresponding dimensions. As it’s required to monitor a battery voltage of above 5 V, two 1% resistors (R1–R2) are added to form a potential divider showing a fixed proportion of the battery voltage at the input of IC2. The rest of the components are used deliberately as the decoupling and protection elements.
The ADCs on PIC12F675 have a maximum input of +5 V, but here, we wanted to monitor a battery that is greater than +5 V. The 12-V bike battery, when fully charged, gives an output of about 14.2 to 14.4 V, and hence, we need to lower (here, to about 4.5 V @ 14.4 V) the maximum voltage that the microcontroller will receive. This can be done by using a voltage divider as stated above. For me, the ratio of my potential divider is 2:2. I have a bunch of 10-KΩ and 12-KΩ resistors lying around, so I used 22 KΩ for R1 and 10 KΩ for R2. A nice trick that I followed in my prototype (because I have a 2:2 ratio) is placing 12-KΩ and 10-KΩ resistors in series to get the needed value of 22 KΩ (R1).
Because the PIC12F675 has a 10-bit ADC, when divided by 5 (1,023/5) returns 204 for each slot. Here, the four slots (1–4) out of the total five (0–4) are used to drive four LEDs to display the battery health in percentage (25–50% and 75–100%). Just go through the given experimental source code to get a deep insight on this, and copy-paste/customize the code if you want to re-compile/modify or just try the ready-to-use hex code to complete the project. The source code can be found at this link, and the hex file can be found at this link. Needless to say, you will need a suitable PIC-Programmer (like the PICkit 2 or 3) to burn the hex code into the microcontroller. I don’t really want to go into the details of software inner workings or how to program the microcontroller. If you have any doubt, just ask in the comments, or keep poking at it till you get it figure out on your own!
An idea for a modification on this project would be outputting the level voltages to a small, multi-color, four-LED bargraph display. However, note that the circuit is not designed as a precision DC voltmeter (it’s just a battery-level gauge), and it will not work well if the battery voltage drops to 7 V or so (a rare case in real life). The prototype was tested with a digital variable DC lab power supply initially dialled to 14.4 V, and the total current consumption observed at that time was roughly 60 mA.
No matter how much we have, we always want more. Well, I’m happy to offer advice and support on stuff that I’ve scripted. If I can help in any way, just let me know, but please don’t ask me to write customized “free” codes for you. If you want to program and can’t this is a great time to start. There are some great resources on Google that I or the editors can point you to!