AC Energy Logger

For the discussion of Arduino related topics.

Moderator: phalanx

Post Reply
Matsume
Posts: 3
Joined: Sat Feb 18, 2017 12:37 pm

AC Energy Logger

Post by Matsume » Fri Oct 06, 2017 5:46 am

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);

}
Attachments
Doc122.pdf
Circuit-Diagram
(92.78 KiB) Downloaded 30 times

User avatar
DanV
Posts: 372
Joined: Sat Apr 25, 2015 9:29 am

Re: AC Energy Logger

Post by DanV » Fri Oct 06, 2017 6:39 am

Make sure you have a delay after analogRead(A2) - before you analogRead(A0).
The Arduino.cc site says :
"It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second. "

EDIT:
I just noticed that you're measuring current from an AC source.
That's likely to vary in magnitude especially if your filter cap is sized poorly.

And you're measuring voltage from a rectified AC source.
You surely can't expect that to not fluctuate widely without applying some smoothing capacitors.

jremington
Support Volunteer
Posts: 2265
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: AC Energy Logger

Post by jremington » Fri Oct 06, 2017 8:59 am

See the great tutorial on the OpenEnergyMonitor site for other ideas on how to do AC line energy monitoring, safely and properly.
https://learn.openenergymonitor.org/ele ... gy-monitor

Anthony Fremont
Posts: 23
Joined: Fri Oct 12, 2007 6:25 am

Re: AC Energy Logger

Post by Anthony Fremont » Wed Oct 11, 2017 6:52 am

jremington wrote:See the great tutorial on the OpenEnergyMonitor site for other ideas on how to do AC line energy monitoring, safely and properly.
https://learn.openenergymonitor.org/ele ... gy-monitor
Great isn't a big enough word. That looks like a thesis for someone working on a PHD. I spent hours pouring through that. Thanks

Sent from my Moto G (4) using Tapatalk

Matsume
Posts: 3
Joined: Sat Feb 18, 2017 12:37 pm

Re: AC Energy Logger

Post by Matsume » Sun Oct 29, 2017 8:18 am

Hey guys, Could you please help me out with the following:

1. How do I connect the load(Light-bulb) accurately so I can measure It's Voltage & Current.
2. Is my Current Sensor connected correctly?
3. And lastly but not least, How do I remove the error that keeps occurring when I run the simulation.

Please find attached the Circuit Diagram and the code below.

Thanks.
Attachments
LCD RS pin to digital pin 12.pdf
Code
(118.29 KiB) Downloaded 31 times
Doc1.pdf
Circuit Diagram
(168.89 KiB) Downloaded 26 times

Post Reply