Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_INA219.h>
- #include <LiquidCrystal_I2C.h>
- Adafruit_INA219 ina219;
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- void setup()
- {
- Serial.begin(9600);
- lcd.init();
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("Hello, world!");
- if (!ina219.begin()) {
- Serial.println("INA219 not found");
- while (1) {
- delay(10);
- }
- }
- // To use a slightly lower 32V, 1A range (higher precision on amps):
- //ina219.setCalibration_32V_1A();
- // Or to use a lower 16V, 400mA range (higher precision on volts and amps):
- ina219.setCalibration_16V_400mA(); // Set calibration for INA219
- delay(2000);
- lcd.clear();
- }
- void loop()
- {
- float shuntVoltage = 0;
- float busVoltage = 0;
- float current_mA = 0;
- float loadVoltage = 0;
- float power_mW = 0;
- shuntVoltage = ina219.getShuntVoltage_mV(); // Read shunt voltage
- busVoltage = ina219.getBusVoltage_V(); // Read bus voltage
- current_mA = ina219.getCurrent_mA(); // Read current
- power_mW = ina219.getPower_mW(); // Read power
- loadVoltage = busVoltage + (shuntVoltage / 1000); // Calculate load voltage
- 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("");
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("VxI=");
- lcd.print(loadVoltage);
- lcd.print("Vx");
- lcd.print(abs(current_mA));
- lcd.print("mA");
- lcd.setCursor(0, 1);
- lcd.print("P = ");
- lcd.print(power_mW);
- lcd.print("mW");
- delay(2000); // Delay for 2 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement