Defining our design requirements and objectives
Okay, we need to measure current, and we want to do it cheap, nice, and gently. Fortunately, I’ve come up with some ideas that might be the answer to your prayers! We are building today an automatic and battery-operated current/power logger using an INA219 (Datasheet here) from Texas Instruments integrated circuit.
Our goal is to make a multimeter-like device which is able to display the current reading through an LCD display, send it over USB-Serial to a connected computer, and log the data on to an SD card (by using its SPI interface). On the right you will find the 3D prototype design I’ve been working on.
The cheapest (and most similar) device with the following specs I’ve been able to find on eBay costs 207$. So that should quite tilt the balance in favour of the DIY option vs the “buy” one.
Nice, huh? Well let’s have a look at its specs:
|Interface||Color TFT-LCD screen|
|Power source||External / Battery 9V|
|Data Storage||SD Card (CSV)|
|Connector||10-pin PCB (Front)|
|Size||125x65x12 mm (H x W x D)|
|Screen Size||2.8 inches|
|Battery Type||9V LR61|
|Max. operation time||16.5 hours (Min. Brightness)|
In order to make this device, there are several issues we need to tackle:
- Due to the limited size of the device and the fact that is battery-operated, we have to include a digital control circuit for the LCD brightness
- We have to fit everything into a 125x65x12 mm box
- We need to find a way for translating 3.3V logic to 5V and the other way arround at a proper speed for the SPI
- The code (along with a huge bunch of libraries) should fit into the 32k flash memory of the ATMega328-PU
- The user interface should be clear enough
- The fabrication process should be easy: quick assembly, few (or none) screws, …
So the approach followed here was pulling appart the electrical kind issues from the physical/3D design ones, then lock one of them to the specs, and see how we can do to make the other one fit into the puzzle. As Julius Caesar said, “divide and win”; so we will take care of the electrical part first of all:
As always, we start attaching the software and breadboard-tested solution:
Understanding the schematic
There are several parts to comment here. The circuit connected to the 14th pin of the ATMEGA is a digital TFT-LCD brightness regulator controlled by PWM. The PWM signal is filtered out by an RC low-pass filter and its output connected to the base of the Q2 BJT transistor. As the PWM duty cycle is increased, the tension rises at the RC output, and more current flows through D1. Under these assumptions we achieve an almost linear control on the current flow by means of the PWM duty cycle (which, in this case can go from 18/255 (7%) to 30/255 (12%). Less than 18/255 and more than 30/255 of duty cycle causes the circuit to saturate.
The control range is not huge, but is sufficient to implement a brigthness control circuit with 5 steps of resolution (Very Low, Low, Medium, High and Very High). This is a quick and cheap way to obtain the desired result with common and general use components. The 2N2222A and the 2N3906 transistors can be replaced by BC547 and BC557 respectively.
Buttons don’t need an external pull-up resistor because we will activate the ATMEGA328-PU internal ones by code.
The battery is monitored through the 13rd pin (Arduino Analog 0 or A0 pin) and compared through a 50% voltage divider (R16 = R17) so that the voltage always remains below 5V (anything more than that could (and would) damage the microcontroller). If the voltage drops below a minimum control point set by software, we warn the user so that they can replace the battery by a new one.