2.2
Battery Tester
Battery Tester
What to expect
During the next several activities, we will build a model dragster race car that is controlled by the micro:bit. The race car will be powered by rechargeable AA batteries. For those activities, it might be helpful for you to know whether the batteries in your car are fully charged, or if they are almost depleted. During this week’s activity, you will build a battery tester that can tell you whether a rechargeable battery is charged or not.
The state of charge in a battery can be estimated by measuring the battery's output voltage. Different kinds of batteries (e.g. alkaline, lead-acid, lithium-ion, NiMH, etc.) have different output voltages. The batteries that are provided as part of the SUPERCHARGE project are NiMH - Nickel Metal Hydride - rechargeable batteries. So, the battery tester that we build today will be customized to determine whether a NiMH battery needs to be recharged.
Connections
Since you will use lots of rechargeable batteries in the next several activities, it will be helpful to analyze the condition of the batteries you use. You can sort out the batteries based on the condition of the batteries so that you can charge them accordingly for the next session's activities.
What does it mean to recharge a battery?
Materials
1 micro:bit with the battery pack connected
(2) alligator clip wires
Battery holder (to hold the battery being tested)
NiMH batteries for testing
Instructions
This activity will use a micro:bit to read the voltage of NiMH batteries to see if they need to be recharged.
Go to the code for this circuit by clicking here: MakeCode Battery Tester. Click “Edit” in the upper right corner of the screen. Pause here, and take a moment to think about what this code will do.
2. The "on start" event will display the title and purpose of the micro:bit in all caps, “BATTERY TESTER.’ The text is put in the "show string" block. When the micro:bit is started up, it will show this string of words.
3. The "on button A pressed" event will be used to read the voltage between the GND and pin0 and display it on micro:bit LED display.
4. The code for "on button B pressed" is designed to return a value for the battery’s voltage measured in millivolts (Note, 1 volt = 1000 millivolts).
5. Under the "on button B pressed" loop, a variable called "reading" is created and given a value from the analog reading of the micro:bit's pin P0. The line is created with the "Variables" menu in MakeCode, using the "set [variable] to [value]" command. The reading variable is then multiplied by 1000 and divided by 340 and stored as a variable called "voltage", which is the voltage in millivolts.
Why does it need to divide by 340?
The micro:bit measures the voltage on P0 as a digital reading between 0 and 1023, with 1023 = 3 volts as the upper limit. So in this system, 1 volt should read around 340, because 1023/3 is about 340 (actually 341, but 340 is close enough). Using this ratio and multiplying the number by 1000 will convert the number to millivolts. Micro:bits only do integer math, so the voltage is multiplied by 1,000 before doing the division by 340.
6. Now you are ready to test a NiMH rechargeable battery. Connect one wire from P0 on the micro:bit to the positive side of the battery. Connect the other wire from GND on the micro:bit to the negative side of the battery.
7. Now you are reay to test a NiMH rechargeable battery. Connect one wire from P0 on the micro:bit to the positive side of the battery. Connect the other wire from GND on the micro:bit to the negative side of the battery.
Simple battery tester using icons
8. Now add a simple display to show whether the battery is charged, or needs to be recharged. As shown in Figure 3, we will add a check mark or an “X” to quickly tell you the condition of the battery that you are measuring. The batteries supplied by SUPERCHARGE are NiMH batteries, which have a normal fully-charged voltage of about 1.2V. When the battery's voltage drops to about 1.1V, the battery needs to be recharged. So, here we use 1100 mV (=1.1 V) as a marker to check the battery . If the battery has a voltage below that level, it will soon run out of energy, and should be recharged.
Think about it
Today you programmed the micro:bit to create a battery tester that you can use to test the rechargeable AA batteries that you will use for many of the activities this year.
Did the program work as expected? Why or why not?
How many batteries were good or bad?
How would you improve the program?
Are all the batteries good for the next sessions? How many batteries didn’t pass the test and need to be recharged?
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
Next Activity
In the next few weeks we will work on the car activities, through which you will craft a car and learn how the car can be controlled using a micro:bit program.
References
[1] Electricity - Battery Tester https://docs.google.com/document/d/15Xry9jFsIzHHG7RpaIomLodl9pBjTiKDvtjkd227b7Y/edit
Calibrating your battery tester
The sample data below from batteries with a voltmeter gives a way to “calibrate” the micro:bit’s program. You can do this calibration if your school has multimeters. You can go to this document and find the information in the “Setup and Procedure” section.