- Fri Oct 06, 2017 5:46 am
#196433
Hey Guys,
I've attached my circuit diagram below. I'm trying to build an energy logger which measures both voltage and current, but I've been experiencing some difficulties with measuring both of them.
Both the voltage and current keeps changing. I tried to get an average of the samples but it still doesn't remain constant. Maybe my program is wrong, I'm not sure what's wrong anymore.
I've placed the code below, Please check it out & help me find the main problem with it & the circuit diagram.
Thanks,
Here's my code:
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int volt=A2;
float vin=0,num,input,ana,out;
void setup()
{
// put your setup code here, to run once:
lcd.begin(16, 2);
}
void loop()
{
// put your main code here, to run repeatedly:
voltage();
}
void voltage()
{
lcd.clear();
lcd.print("voltage:");
num = analogRead(A2);
input=(5*num)/1023.0;
lcd.setCursor(10,0);
lcd.print(input);
lcd.setCursor(0,1);
lcd.print("Current:");
ana=analogRead(A0);
lcd.setCursor(10,1);
lcd.print(ana);
delay(500);
}
I've attached my circuit diagram below. I'm trying to build an energy logger which measures both voltage and current, but I've been experiencing some difficulties with measuring both of them.
Both the voltage and current keeps changing. I tried to get an average of the samples but it still doesn't remain constant. Maybe my program is wrong, I'm not sure what's wrong anymore.
I've placed the code below, Please check it out & help me find the main problem with it & the circuit diagram.
Thanks,
Here's my code:
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int volt=A2;
float vin=0,num,input,ana,out;
void setup()
{
// put your setup code here, to run once:
lcd.begin(16, 2);
}
void loop()
{
// put your main code here, to run repeatedly:
voltage();
}
void voltage()
{
lcd.clear();
lcd.print("voltage:");
num = analogRead(A2);
input=(5*num)/1023.0;
lcd.setCursor(10,0);
lcd.print(input);
lcd.setCursor(0,1);
lcd.print("Current:");
ana=analogRead(A0);
lcd.setCursor(10,1);
lcd.print(ana);
delay(500);
}
You do not have the required permissions to view the files attached to this post.