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. It then sends that information to the 8 channel LED strip that is included with the TINKERkit.
Required Parts
This project uses a few items from the TINKERkit:
- the TINKERkit board connected tot the Raspberry Pi
- the mini breadboard
- nine male to male jumper wires
- the 74HCT125 integrated circuit
- the eight channel RGB LED strip
Steps
Assembly
Gather the materials above and connect everything together as shown in the diagram below:
When testing, place the red wire pn the positive terminal and the black wire on the negative terminal.
Code
Enter the following program into Thonny or copy the code below into you Home folder on your Raspberry Pi. The estimaed battery capacity will control how many LEDs are turned on. In addition, their colors will be set to indicate whether they are in the GOOD, OK, or BAD zone. The BAD zone is the bottom 4 LEDs which will be red. The OK zone will be two yellow LEDs in positions 5 and 6. And the GOOD zone will be the two green LEDs in positions 7 and 8.
For downloading:
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 26 27 28 29 |
import piplates.TINKERplate as TINK import time #create battery state thresholds VL=1.2 VH=1.4 TINK.setDEFAULTS(0) TINK.setMODE(0,1,'rgbled') #set Digital I/O port to display Neopixels red=[255,0,0] #define the red color mix yel=[255,255,0] #define the yellow color mix grn=[0,255,0] #define the green color mix off=[0,0,0] #define an off LED blank=off+off+off+off+off+off+off+off #create a set of OFF LEDs strip=red+red+red+red+yel+yel+grn+grn #create the battery status lights while(True): bat=TINK.getADC(0,1) #read analog channel 1 #scale the data to an integer in the range of 0 through 7 temp=bat-0.8 #we will only look at the range from 0.8 volts to 1.6 if (temp<0): index=0 #if the measured voltage is negative, set index to 0 else: #otherwise, convert the voltage to a list index index=int(temp*10) if (index>7): #limit the maximum index to 7 index=7 batstrip=strip[0:3*(index+1)]+blank[0:3*(8-index)] #assembled string TINK.setRGBSTRING(0,1,batstrip) #send string data to TINKERplate 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 II.py
Output
Running the above code will drive the LEDs in the strip to a hight proportional to the battery capacity. The image below shows the ouput of a -mostly- GOOD battery. Note how the top LED is off? A brand new battery would illuminate all eight LEDs.