A TTiny Curr8nt Moni5or

by mars91 in Circuits > Sensors

318 Views, 8 Favorites, 0 Comments

A TTiny Curr8nt Moni5or

IMG_9359.jpg
IMG_9376.jpg

A pocket sized board that easily measures a test circuit’s current usage and comes with a convenient onboard 5V and 3.3V power supply. Calculating power is as simple as P = VI. This board is also not limited to the provided 3.3V and 5V and can measure current from much higher voltages (from some outside supply).


In the second image above, we are using a theoretical 3.3 volts over a 220Ω resistor, so I_theoretical = 3.3/220 = 15mA. I'll say 14.95mA is close enough!


I wanted to build a circuit without any breakout boards or messy mix of semi-permanent parts. So instead, I `borrowed` from the experts and looked at their schematics to build this current monitoring board.

Supplies

Screen Shot 2025-02-25 at 10.26.50 PM.png

All prices are USD at the time of writing this. There is a PCB provided below, so matching sizes is important. I personally chose SMT pieces that can be hand-soldered.


One USB - micro B ~ $0.38

One 3.3V Linear Voltage Regulator ~ $0.58

One ATTINY85 ~$1.50

One PT2512FK 0.1Ω 1% Resistor ~$0.54

One INA219AIDR Monitor ~$1.78

One 2.54mm Two Pin Terminal Block

Four 10kΩ 0805 Resistors

Two 0805 LEDs ~$0.34

One SOD-123FL Schottky Diode ~$0.41

Two 10Ω 0805 Resistors

Two 10uF 0805 Capacitors

Three .1uF 0805 Capacitors

0.96 Inch OLED I2C IIC Display Module 128*64 ~$2.96 (link has a pack of 5 tho)

**Lastly, I used an Arduino Uno, 10µF electrolytic capacitor, and jumper wires to program the chip**

Why These Supplies

Screen Shot 2025-02-20 at 10.48.09 AM.png
OLED0.96_inch.jpg

The Two Main Players


  1. Texas Instruments' INA219 Current Monitor
  2. Microchip Technology's Attiny85


Both of these have excellent documentation and community support.

From my understanding, there are cheaper and better chips than the Attiny85, but this chip has an abundance of community support, code, and can be easily programmed using the Arduino IDE with an Arduino Uno.

For the INA219, I came across it thru Adafruit's INA219 High Side DC Current Sensor. If you're looking for a professional breakout board with supporting code, you can stop here.

The INA219, from Texas Instruments, only requires:

  1. A power filtering capacitor
  2. Pull-up resistors for I2C communication
  3. A PT2512FK 0.1Ω 1% precision resistor

Power


A 3.3V Linear Voltage Regulator powers both the Attiny85 and INA219. Both could run directly off the USB 5V supply (I think), but many of my DIY circuits use 3.3V, so I wanted a 3.3V onboard supply. I chose this regulator because it can handle medium-sized currents (800mA to 1000mA), and I’ve seen it used in other schematics.

⚠ I think it's safe to say that when using the onboard 3.3V supply, you should not exceed 800mA.

The MBR120V Schottky Diode is a blocking diode (I think) protecting everything upstream from voltage surges up to 20V and it allowing 1A continuous forward current.

⚠ Again, I think it's safe to say when measuring 5V circuits using the onboard 5V supply, do not exceed 1000mA.

This board also supports external voltage/current supplies. It is rated to handle up to 3.2A and 26V! (these values depend on our PT2512FK 0.1Ω precision resistor)

Screen


We’ll be using a 0.96-inch OLED screen. Because when I searched "Attiny85 I2C screens" I found several working examples using this screen. 🙂

USB


The USB is only used as a convenient power source. While it is possible to program this board via USB (which would probably be a better), it would need additional components/routes to support USB onboard programming.

Maybe a version 2 can use a chip with native USB support or have onboard programming options. For now, programming with an Arduino Uno seemed easiest.

Two LEDs


  1. LED_BUILTIN – Used for a sanity check. If the board wasn’t working, at least I could blink an LED from the Attiny85. Maybe you could program it to light up at certain current or voltage levels.
  2. Power Indicator LED – Turns on when the board is powered on.

Cs & Rs


Everything else is for power filtering, pull-ups, and LED current limiting.

Board Its Programmer

Screen Shot 2025-02-20 at 11.49.06 AM.png
unnamed (1).jpg
unnamed.jpg
Screen Shot 2025-02-20 at 11.57.26 AM.png
Screen Shot 2025-02-20 at 11.50.20 AM.png
Screen Shot 2025-02-20 at 12.02.49 PM.png
Screen Shot 2025-02-20 at 11.53.35 AM.png

Board


This board easy measures current usage from 3.3V and 5V devices! Use a male-to-female jumper, connect the 3.3V or 5V voltage to V+, then connect V- to the input voltage of the device you're measuring. Lastly, connect the board’s ground to the device’s ground, and voilà!

You can also measure devices with separate power supplies. Just plug their power supply into V+, connect V- to the device’s input, and tie grounds together.

You can order the board here:

https://www.pcbway.com/project/shareproject/W775378ASH77_attiny_currnet_sensor_caaa88b1.html

Programmer

There are several ways to program an ATtiny85, but here’s how I (and my cat) did it using an Arduino Uno:

1) Turn your Uno into a programmer

  1. Open the Arduino IDE
  2. Plug in your Uno
  3. Go to File → Examples → ArduinoISP
  4. Upload the ArduinoISP sketch to your Uno


2) Connect the ATtiny85 to the Arduino Uno

  1. Connect the boards 13-11 pins to Arduino Uno pins 13-11
  2. Connect the board’s pin 10 to Arduino pin 10
  3. Place a 10µF to 22µF electrolytic capacitor between the Arduino Uno’s GND and RESET pin (long leg in RESET).
  4. Connect the Arduino 5V to the board's A+ pin. **It's important to match voltages between the Arduino and the ATtiny85 when uploading code, or you could damage the ATtiny85, use the uno's 5volts**.


2.5) Install ATtiny board support in Arduino IDE

  1. Add the ATtiny board package by going to Arduino IDE → Preferences → Additional Boards Manager URLs
  2. Paste in: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
  3. Library found here https://github.com/damellis/attiny.
  4. You can see in my provided picture that I have a few others installed as well.
  5. For more details, check out this instructables


3) Upload your code (provided below) to the ATtiny85

  1. Open your code in the Arduino IDE
  2. Go to Tools → Programmer → Arduino as ISP
  3. Set Processor to ATtiny85
  4. Set Clock to 1MHz
  5. Select Board as ATtiny25/45/85
  6. Upload your code!

Code

mitchell-luo-FWoq_ldWlNQ-unsplash.jpg

Libraries Used


Here are the libraries I used:

  1. ATtiny by damellis
  2. Tiny4kOLED
  3. ATtiny Power Meter

I'm also using TinyWireM.h from Adafruit.

OLED Code


The OLED display uses the Tiny4kOLED library, which can be found in the Manage Libraries tab in the Arduino IDE.


INA219 Code


Everything was running smoothly until I couldn't get Adafruit’s INA219 current sensor example code to work. Looking back, its obvious since it's not was designed to support the ATtiny85. But at the time, I was in unknown territory. I'm no expert in C++ I2C hardware code, and I wasn’t sure how to modify it.

After Googling, I found a great instructables also using the INA219 with the ATtiny85! great minds think alike... :|

The author has written custom INA219 C++ code for the ATtiny85, which also uses the TinyWireM.h from Adafruit. I tried his code and it worked, perfectly! His code is great and honestly seems like a solid example on how to write custom C++ code using hardware datasheets like the one from Texas Instruments.

Demo

current sensor demo

Here’s a cool GIF player from an Instructables I found! Sorry for the shaking camera, filming with a phone in one hand and flipping switches with the other.

See the difference in current pull with the speaker turned on... About 50mA.


Now with this board, whenever I build a project, I can quickly pull it out and get an estimate of its current consumption!