hi everyone.. presently i am working on a project and i am facing some errors in my program. if anyone help me to sort out the problem it would be highly appreciated. my code is as below :
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 9, 10, 11, 12,13);
SoftwareSerial s(5,6);
//part of current sensor//
const int currentvalue = A1;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
int sensorValue = 0;
int ACSoffset = 2500;
float volt = 0;
float Amps = 0;
float cutOffLimit = 0;
//part of voltage sensor//
const int voltagevalue=A2;
int voltage=0;
float r1=47000.0;
float r2=33000.0;
//part of power//
const float watt=0;
const float Kwh=0;
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
//Name Printing on LCD//
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("IoT based solar");
lcd.setCursor(0, 1);
lcd.print("power monitoring");
delay(4000);
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Project By");
lcd.setCursor(0, 1);
lcd.print("Amjad (Leader)");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("2. xray");
lcd.setCursor(0, 1);
lcd.print("3. arhm");
delay(3000);
lcd.clear();
}
void loop()
{
//part of current measurment//
sensorValue = analogRead(currentvalue);
volt = ((sensorValue / 1024.0) * 5000); // Gets you mV
Amps = ((volt - ACSoffset) / mVperAmp)*1000;
if((Amps) > cutOffLimit )
{
lcd.setCursor(2, 0);
lcd.print(Amps,0);
Serial.println("Amps");
Serial.print(Amps,2); // print the current with 2 decimal places
}
else
{
Amps=0;
lcd.setCursor(2, 0);
lcd.print(Amps,0);
Serial.println("No Current");
}
//part of voltage measurement//
voltagevalue = analogRead(A2);
voltage=(voltagevalue*(5.0/1024)*((r1+r2)/r2));
//for power conversion//
watt=(voltage*(Amps/1000));
Kwh=Kwh+(watt/3600)*1000;
//Part of serial communication//
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["voltage"] = voltage;
root["Amps"] = Amps;
root["Kwh"] = Kwh;
root["watt"] = watt;
if(s.available()>0)
{ root.printTo(s); }
// data printing on lcd//
lcd.setCursor(0, 0);
lcd.print("I=");
lcd.setCursor(6, 0);
lcd.print("mA");
lcd.setCursor(0, 1);
lcd.print("V=");
lcd.setCursor(2, 1);
lcd.print(voltage,2);
lcd.setCursor(6, 1);
lcd.print("V");
lcd.setCursor(10, 0);
lcd.print("W=");
lcd.setCursor(12, 0);
lcd.print(watt,0);
lcd.setCursor(15, 0);
lcd.print("P");
lcd.setCursor(8, 1);
lcd.print("mWh=");
lcd.setCursor(12 , 1);
lcd.print(Kwh,0);
lcd.setCursor(15, 1);
lcd.print("E");
delay(9000);
// data printing on serial monitor//
Serial.print("Amps = "); // shows the voltage measured
Serial.println(Amps,2); // the '2' after voltage allows you to display 2 digits after decimal point
Serial.print("Voltage =");
Serial.println(voltage);
Serial.println(watt,2);
Serial.print("watt = "); // shows the watt measured
Serial.print("Kwh = "); // shows the kwh measured
Serial.println(Kwh,2);
}