to read the current and power calculation i am using an arduino nano with an I2C adapter. This I2C adapter makes easy to connect current monitoring board.
I will also explain how you can write data into an xl sheet and in a google sheet using arduino.
Hardware you need
3. I2C cable
lets start with arduino code.
in this code i will write a command to read current through I2C.
this code is pretty straight forward, all you need to do is send a command to read current and the Current monitoring board will do everything for you.
In my area the AC voltage is around 120-124V. we will use this voltage reading to calculate the power uses.
in this code i am calculating current,power, watt hour, total watt hour and total kilo watt hour.
//Include Wire I2C Library
#include <wire.h>
int address = 42; // I2C address
double voltage = 121.7; //////// voltage reading
double tkWh = 0;
double tWh = 0;
void setup()
{
Serial.begin(9600); // Create Serial Object (9600 Baud)
Wire.begin();
}
void loop()
{
Wire.beginTransmission(address); // Start communication
Wire.write(146); // Command header
Wire.write(106); // Command header
Wire.write(1); // Command 1
Wire.write(1); // Start Channel no
Wire.write(1); // End Channel no
Wire.write(0);
Wire.write(0);
Wire.write((146 + 106 + 1 + 1 + 1 + 0 + 0) & 255); // CheckSum
Wire.endTransmission(); // Complete Transmission
Wire.requestFrom(address, 5);
unsigned long MSB1 = Wire.read();
MSB1= MSB1*65536;
unsigned long MSB = Wire.read();
MSB=MSB*256;
unsigned long LSB = Wire.read();
MSB1=MSB1+MSB+LSB;
double current = ((double)MSB1)/(double)1000;
Serial.print(current,3); //// current on ch 1
Serial.print(",");
double Power = voltage * current; /// power on ch1
Serial.print(Power,3);
Serial.print(",");
double Wh = 0.000833 * Power; /// Watt hour on ch1
Serial.print(Wh,4);
Serial.print(",");
tWh = tWh + Wh; /// total watt hour used
Serial.print(tWh,4);
Serial.print(",");
tkWh = tWh/1000; /// total kilo watt hour used
Serial.print(tkWh,4);
</p><p>
Serial.print("\n");
Wire.endTransmission(); // Complete Transmission
delay(3000);
}
after reading the current now we will calculate the power.
power calculations are done in this section of the code.
All you need to do is burn the code in arduino and check your readings on serial port.
Serial.print(current,3); //// current on ch 1
Serial.print(",");
double Power = voltage * current; /// power on ch1
Serial.print(Power,3);
Serial.print(",");
double Wh = 0.000833 * Power; /// Watt hour on ch1
Serial.print(Wh,4);
Serial.print(",");
tWh = tWh + Wh; /// total watt hour used
Serial.print(tWh,4);
Serial.print(",");
tkWh = tWh/1000; /// total killo watt hour used
Serial.print(tkWh,4);
Just for the testing purpose i changed to a different different load just to see if it works with other load, so far it worked great.
you can also find the code on git.
To write data into a text file i am using CoolTerm, its a really simple tool for capturing data.
to setup cool term
1. Download coolterm
2. go to connection >> option
3. select serial port >> port
4. go to connection >> capture to text file
once you setup this it will start writing all the data coming from the arduino into a text file. We will use this data to plot power usages graph.
CoolTerm will save all data in a local folder and you can import this file into a XL sheet.
I separated different different readings with a "," so that i can create tables into the XL sheet. i will suggest if you have multiple data, do the same.
Now we will import the arduino data into a google sheet.
its a very simple process please follow these steps:
1. open google
2. go to google sheet
3. create a new google sheet
4. go to file import and select your arduino o/p text file
after doing this google will create a google sheet.