Hi, may anyone helps me? How can I display current and voltage in arduino uno and display it through LCD? May anyone check my program incase there's problem or error.
#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include<LcdBarGraphRobojax.h>
#include <INA219_WE.h>
#define I2C_ADDRESS 0x40
INA219_WE ina219 = INA219_WE(I2C_ADDRESS);
Servo myservo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
float voltage1;
void setup()
{
lcd.begin();
lcd.backlight();
lcd.clear();
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SOLAR and PIEZO");
lcd.setCursor(4,1);
lcd.print("SYSTEM");
delay(10000);
lcd.clear();
Serial.begin(9600);
Wire.begin();
if(!ina219.init()){
//lcd.clear();
Serial.println("INA219notconnected!");
lcd.print("INA219 conneted");
}
Serial.println("INA219 Current Sensor with solar panel");
}
void loop() {
float shuntVoltage_mV=0.0;
float loadVoltage_V=0.0;
float busVoltage_V=0.0;
float current_mA=0.0;
float power_mW=0.0;
bool ina219_overflow=false;
float a;
float power;
shuntVoltage_mV = ina219.getShuntVoltage_mV();
busVoltage_V = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
a=abs(current_mA);
power_mW = ina219.getBusPower();
loadVoltage_V = busVoltage_V + (shuntVoltage_mV/1000);
ina219_overflow = ina219.getOverflow();
Serial.print("Shunt Voltage [mV]: "); Serial.println(shuntVoltage_mV);
Serial.print("Bus Voltage [V]: "); Serial.println(busVoltage_V);
Serial.print("Load Voltage [V]: "); Serial.println(loadVoltage_V);
Serial.print("Current[mA]: "); Serial.println(a);
Serial.print("Bus Power [mW]: "); Serial.println(power_mW);
lcd.clear();
lcd.setCursor (8,0);
lcd.print("|");
lcd.setCursor (8,1);
lcd.print("|");
lcd.setCursor (0,0);
lcd.print("VS:");
lcd.setCursor(0,1);
lcd.print("IS:");
//VS and IS display but no values
lcd.setCursor(3,0);
lcd.print((float)loadVoltage_V,1);
lcd.setCursor(7,0);
lcd.print("V");
lcd.setCursor(3,1);
lcd.print((float)a);
lcd.setCursor(6,1);
lcd.print("mA");
if(!ina219_overflow){
Serial.println("Values OK - no overflow");
float volt1 = analogRead(A1);
voltage1 = (volt1* 5.0/1024);
Serial.print("voltage1= "); Serial.println(voltage1,2);
lcd.setCursor (9,0); //
lcd.print("P:");
lcd.setCursor (11,0); //
lcd.print(voltage1); // print
lcd.setCursor (15 ,0); //
lcd.print("V");
lcd.setCursor (9,1); //
lcd.print("P:");
lcd.setCursor (11,1); //
lcd.print(voltage1); // print
lcd.setCursor (14 ,1); //
lcd.print("mA");
power= (loadVoltage_V*(a/1000))+(voltage1);
delay (2000);
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Power:");
lcd.setCursor (7,0); //
lcd.print(power); // print
lcd.setCursor (11 ,0); //
lcd.print("W");
delay (5000);
}
else{
Serial.println("Overflow! Choose higher PGAIN");
}
Serial.println();
delay(5000);
}