Adafruit INA219 Current Sensor Breakout Created by lady ada Last updated on 2018-01-17 05:25:30 PM UTC
Guide Contents Guide Contents Overview 2 3 Why the High Side? How does it work? 3 3 Assembly 5 Addressing the Boards 5 Wiring 7 Connect to the microprocessor Connect to the circuit Arduino Code 11 Install the Library Load the Example Run it! Customize it 11 11 12 12 Library Reference Construction and Initialization Functions: Sensor Reading Functions: CircuitPython Code Usage Downloads Datasheets & Files Schematic & Fabrication Print © Adafruit Industries 7 8 https://learn.adafruit.
Overview The INA219B breakout board will solve all your power-monitoring problems. Instead of struggling with two multimeters, you can use this breakout to measure both the high side voltage and DC current draw over I2C with 1% precision. Why the High Side? Most current-measuring devices such as our current panel meter are only good for low side measuring. That means that unless you want to get a battery involved, you have to stick the measurement resistor between the target ground and true ground.
inductive spikes. © Adafruit Industries https://learn.adafruit.
Assembly The board comes with all surface-mount components pre-soldered. Additional parts are included to help integrate the INA219 breakout board into your project. Wires can be soldered directly to the holes on the edge of the board. But for breadboard use, you will want to solder on the included 6-pin header. The load can be connected via the header, or using the included 2-pin screw-terminal.
To program the address offset, use a drop of solder to bridge the corresponding address jumper for each binary '1' in the address. Up to 4 boards may be connected. Addressing is as follows: Board 0: Address = 0x40 Offset = binary 00000 (no jumpers required) Board 1: Address = 0x41 Offset = binary 00001 (bridge A0 as in the photo above) Board 2: Address = 0x44 Offset = binary 00100 (bridge A1) Board 3: Address = 0x45 Offset = binary 00101 (bridge A0 & A1) © Adafruit Industries https://learn.adafruit.
Wiring The INA219 breakout board can be powered by the 5v pin on your Arduino and communicates via I2C. Connect to the microprocessor Connect GND to GND Connect VCC to 5v Then connect SDA to SDA (Analog pin 4 on pre-R3 Arduinos) And connect SCL to SCL (Analog pin 5 on pre-R3 Arduinos) On R3 and later Arduinos, you can connect to the new dedicated SDA & SCL pins next to the AREF pin. On pre-R3 Megas, SDA & SCL are on pins 20 & 21. © Adafruit Industries https://learn.adafruit.
Next we must insert the INA219 current sensor into the circuit we want to measure: Be careful inserting noisy loads that can cause a sharp current draw, such as DC motors, since they can cause problems on the power lines and may cause the INA219 to reset, etc. When using a DC motor or a similar device, be sure to include a large capacitor to decouple the motor from the power supply and use a snubber diode to protect against inductive spikes.
Connect V- to the positive terminal or lead of the load. This puts the sense resistor in-line with the circuit. Finally, connect a wire from the negative terminal of the power supply to GND. This allows the sensor to measure the load voltage as well as the load current. The photo below shows an INA219 breakout board configured to measure the motor supply current on an Adafruit Motor Shield. © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Arduino Code Programming the Adafruit INA219 breakout board is simple using our library: Install the Library Download the library from the Downloads button below Download Adafruit_INA219 https://adafru.it/rMD Expand the .zip file to the Libraries folder in your Arduino Sketchbook folder (If you don't know where this is, open File->Preferences in the IDE and it will tell you the location of your sketchbook folder).
Run it! Click on the upload button in the IDE. When it is "done uploading" Open your Serial Monitor and set the speed to 115200 baud. The output should appear similar to the sample below: Customize it You can adapt, expand or modify the example code to suit your project requirements. For a detailed description of the available library functions, see the Library Reference on the next page: © Adafruit Industries https://learn.adafruit.
Library Reference Construction and Initialization Functions: Adafruit_INA219(uint8_t addr = INA219_ADDRESS); Constructs an instance of the Adafruit_INA219. If no address is specified, the default address (0x40) is used. If more than one INA219 module is connected, it should be addressed as shown on the Assembly page and the configured address passed to the constuctor. void begin(void); Initializes I2C communication with the Adafruit_INA219 device using the default configuration values.
float float float float shuntvoltage = 0; busvoltage = 0; current_mA = 0; loadvoltage = 0; shuntvoltage = ina219.getShuntVoltage_mV(); busvoltage = ina219.getBusVoltage_V(); current_mA = ina219.getCurrent_mA(); loadvoltage = busvoltage + (shuntvoltage / 1000); Serial.print("Bus Voltage: Serial.print("Shunt Voltage: Serial.print("Load Voltage: Serial.print("Current: Serial.println(""); © Adafruit Industries "); "); "); "); Serial.print(busvoltage); Serial.println(" V"); Serial.
CircuitPython Code It's easy to use the INA219 sensor with CircuitPython and the Adafruit CircuitPython INA219 module. This module allows you to easily write Python code that reads the current and more from the sensor. First wire up a INA219 to your board exactly as shown on the previous pages for Arduino using an I2C interface.
You can also download the adafruit_ina219.mpy from its releases page on Github. Before continuing make sure your board's lib folder or root filesystem has the adafruit_ina219.mpy, and adafruit_bus_device files and folders copied over. Next connect to the board's serial REPL so you are at the CircuitPython >>> prompt. Usage To demonstrate the usage of the sensor we'll initialize it and read the current and more from the board's Python REPL.
import board import busio import time import adafruit_ina219 # Initialize I2C bus and sensor. i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_ina219.INA219(i2c) # Main loop prints voltage and current every second. while True: print('Shunt voltage: {} mV'.format(sensor.get_shunt_voltage_mV())) print('Bus voltage: {} V'.format(sensor.get_bus_voltage_V())) print('Current: {} mA'.format(sensor.get_current_mA())) time.sleep(1.0) © Adafruit Industries https://learn.adafruit.
Downloads Datasheets & Files Eagle PCB files for the INA219 breakout board Arduino driver library Data Sheet for the INA219 chip Fritzing object in the Adafruit Fritzing library Schematic & Fabrication Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2018-01-17 05:25:29 PM UTC Page 19 of 19