Skip to content

Instantly share code, notes, and snippets.

@arduinothai
Last active May 18, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arduinothai/a87431b970d247b1ea966e91e6243c75 to your computer and use it in GitHub Desktop.
Save arduinothai/a87431b970d247b1ea966e91e6243c75 to your computer and use it in GitHub Desktop.
ดาวโหลดไลบารี่ได้ที่ https://github.com/adafruit/Adafruit_INA219
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void setup()
{
uint32_t currentFrequency;
Serial.begin(9600);
Serial.println("Hello!");
Serial.println("Measuring voltage and current with INA219 ...");
ina219.begin();
pinMode(2,OUTPUT);
}
void loop()
{
digitalWrite(2,HIGH);
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
power = current_mA * loadvoltage;
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); Serial.println(" mW");
Serial.println("");
delay(1000);
}
// ที่มา https://openhomeautomation.net/power-monitoring-arduino-ina219
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment