aytwartoofyoroo

[Verified]ina219 current and voltage detection module-with code

 
Overview

Chip characteristics

Sensed bus voltage range: 0V to 26V

Reports current, voltage, and power

16 programmable addresses

High accuracy: ±0.5% accuracy over entire temperature range

Filtering options

calibration register

Tutorial

Use Dupont wires to connect the positive and negative and i2c interfaces to arduino, then download the attached arduino ina219 library and put it in the libraries folder

#include 
#include 

Adafruit_INA219 ina219;

void setup(void) 
{
  Serial.begin(115200);
  while (!Serial) {
      delay(1);
  }

  uint32_t currentFrequency;

  Serial.println("Hello!");

  // 初始化会默认使用最大测量范围(32V, 2A),你也可以使用setCalibration指令更改,以获取更高的精度
  ina219.begin();
  // 用 32V, 1A 范围来测量会获取更高的电流测量精度,如果想使用这个选项就删除下面那行的注释
  //ina219.setCalibration_32V_1A();
  // 用16V, 400mA 范围来测量会获取更高的电流和电压测量精度,如果想使用这个选项就删除下面那行的注释
  //ina219.setCalibration_16V_400mA();

  Serial.println("Measuring voltage and current with INA219 ..."); //打印‘正在使用ina219测量电压和电流’
}

void loop(void) 
{
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;
  float power_mW = 0;

  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();
  loadvoltage = busvoltage + (shuntvoltage / 1000);

  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");    //打印总线电压
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV"); //打印分流电压
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");   //打印负载电压
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");   //打印电流
  Serial.print("Power:         "); Serial.print(power_mW); Serial.println(" mW");     //打印功率
  Serial.println("");

  delay(2000);
}

Achievements

The load is connected to an Arduino UNO board without other loads. The accuracy has not been tested. Next time, I will compare it with a Lichuang multimeter.

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-19 07:15:24
  • WinCE product charging situation
  • Sensor circuit
  • How to play PIC32 microcontroller
  • What does ACLK=n/a mean?
  • Check the number of PICKIT3 owners in the forum.
  • The company closed down and all kinds of parts were sold at low prices.

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号