Table of Contents
Introduction
This project uses one of the analog to digital converter (ADC) channels on the TINKERplate to measure and evaluate the capacity of a standard 1.5V alkaline battery.
Required Parts
This project only requires a TINKERplate connected to a programmed Raspberry Pi and two wires
Steps
Assembly
The assembly consists of simply attaching a pair of wires to the Analog Input block as shown here:
When testing, place the red wire pn the positive terminal and the black wire on the negative terminal.
Code
We used the code shown below for our tester. In our program we sit in a loop that samples the voltage on analog channel 1 twice every second and display the data to a panel meter. To make it a little interesting, we base the color of the meter and the wording in the label on the battery voltage.
The output from a GOOD battery:
The output from an OK battery:
And the output from a BAD battery:
Note that you could modify the threshold voltages in the above code to test 9V alkaline batteries, lithium batteries, and 6V lead acid batteries.
Here is the code ready for copy and paste:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import piplates.TINKERplate as TINK import time #create battery state thresholds VL=1.2 VH=1.4 TINK.openMETER(1) #Create a panel meter on the screen #Change window title: TINK.setTITLE("TINKERplate Battery Tester") #TINK.setCOLOR((255,0,0)) #start with red text while(True): bat=TINK.getADC(0,1) #read analog chanel 1 if (bat >= VH): TINK.setCOLOR((0,255,0)) #show green text TINK.setMETER(bat,'Volts','GOOD',1) #indicate a GOOD battery if ((bat >= VL) and (bat < VH)): TINK.setCOLOR((255,255,0)) #show yellow text TINK.setMETER(bat,'Volts','OK',1) #indicate an OK battery if (bat < VL): TINK.setCOLOR((255,0,0)) #show red text TINK.setMETER(bat,'Volts','BAD',1) #indicate a BAD battery time.sleep(.5) #delay and repeat |
The above code can be downloaded from github by typing the following instructions on the command line:
- git clone https://github.com/pi-plates/TINKERplate-Projects.git
- cd TINKERplate-Projects
- python3 BatteryTester I.py
Theory
We based our threshold voltages on the blue line in the chart below.