Srxon05

zelja njokina

Nov 28th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_INA219.h> // You will need to download this library
  3.  
  4. Adafruit_INA219 sensor219; // Declare and instance of INA219
  5.  
  6. void setup(void)
  7. {
  8.      
  9.   Serial.begin(9600);    
  10.   sensor219.begin();
  11.  
  12. }
  13.  
  14. void loop(void)
  15. {
  16.   float busVoltage = 0;
  17.   float current = 0; // Measure in milli amps
  18.   float power = 0;
  19.  
  20.   busVoltage = sensor219.getBusVoltage_V();
  21.   current = sensor219.getCurrent_mA();
  22.   power = busVoltage * (current/1000); // Calculate the Power
  23.  
  24.  
  25.   Serial.print("Bus Voltage:   ");
  26.   Serial.print(busVoltage);
  27.   Serial.println(" V");  
  28.  
  29.   Serial.print("Current:       ");
  30.   Serial.print(current);
  31.   Serial.println(" mA");
  32.  
  33.   Serial.print("Power:         ");
  34.   Serial.print(power);
  35.   Serial.println(" W");  
  36.  
  37.   Serial.println("");  
  38.  
  39.   delay(2000);
  40. }
Add Comment
Please, Sign In to add comment