# Arduino Based Solar PV Energy Meter With Xively Connectivity ( Can Be Monitored on Android or IPhone )

12,273

110

17

It's been about two days since I made The Arduino PV generation Meter, but it was a mistake to not to take the step by step photos before proceeding for final testing. And it was an awful idea to show the raw box of so called energy meter :P. Anyways, It was really fun to work on arduino and for the first time. This tutorial is based on the original instructable by Deba18. I made few tweaks and enhanced the code little bit.

What this meter do?

1. Sense the Solar Panel Voltage
2. Sense amperage of Solar Panel
3. Calculates energy used
4. Display output live on 16x2 Character LCD
5. and post it to Xively (www.xively.com)

E.g in my case, am uploading data to xively from PV energy meter and grabing data for pvoutput.org

So the Energy Consumption of my home is measured by "Current Cost Energy Meter" and Solar PV generation measured by My Homemade Arduino Solar PV Meter.

Here is everything you will need for this easy to build project:

• Arduino UNO R3
• Network Shield
• ACS712 Current Sensor (30A)
• 16x2 Character LCD
• Jumper Wires (male to male and male to female)
• 100K resistor
• 10k resistor
• 5k potentiometer
• Connection sockets

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Collect the Parts:

1. Arduino UNO
2. Arduino Ethernet Shield
3. ACS 712 current Sensor
4. 16x2 Charcater LCD
5. 100k Resistance
6. 10K Resistance
7. 5k Potentiometer
8. Jumper Wires (Male to male and Male to Female)
9. Connectors

## Step 2: Understanding Terms and Calculating Values

What is power?

Power is a product of voltage (volt) and current (Amp)

P=VxI Unit of power is Watt or KW

e.g:

P = 2.5 x 2

P = 5 watts

What is Energy?

Energy is product of power (watt) and time (Hour)

E = P x t

Unit of Energy is Watt Hour or Kilowatt Hour (kWh)

So,

What we need now?

We need voltage, current and time in our project.

## Step 3: Measuring Voltage

To measure Voltage, we will need:

• An Arduino
• The Arduino IDE (integrated development environment).
• One 100Ko resistor.
• One 10Ko resistor.
• Four wires, in at least two different colors (red and black are recommended).
• A breadboard (or suitable stripboard and soldering equipment).

The Arduino Sketch

To eliminate the possibility that the Arduino will run a previous sketch and operate in an unknown way, you can program the sketch first.

To create the voltmeter sketch:

Open the Arduino IDE.Paste in the following code:

``` <br>
float vPow = 4.7;
<br> float r1 = 100000;<br>
float r2 = 10000;
<br>
void setup() <br>{
Serial.begin(9600);

<br>   // Send ANSI terminal codes
<br> Serial.print("\x1B");
<br>  Serial.print("[2J");
<br>  Serial.print("\x1B");
<br> Serial.println("[H");
<br>  // End ANSI terminal codes
<br>
Serial.println("--------------------");
<br>   Serial.println("DC VOLTMETER");
<br> Serial.print("Maximum Voltage: ");
<br>  Serial.print((int)(vPow / (r2 / (r1 + r2))));
<br>   Serial.println("V");
<br>  Serial.println("--------------------");
<br>   Serial.println("");
<br>
delay(2000);
}

<br> void loop()<br> {
<br> float v = (analogRead(0) * vPow) / 1024.0;
<br>  float v2 = v / (r2 / (r1 + r2));
<br>
// Send ANSI terminal codes
<br>   Serial.print("\x1B");
<br>  Serial.print("[1A");
<br>  // End ANSI terminal codes
<br>
Serial.println(v2);
<br>

}```

And then save the sketch:

On the File menu, click Save As…This sketch begins by initializing the serial port and declaring a few variables: vPow – When powered over a USB cable, it is common for the Arduino’s 5V power supply to be a little less than that ideal.

r1 – the value (in ohms) of the first resistor in the circuit.

r2 – the value (in ohms) of the second resistor in the circuit.

The sketch then sends some basic information to the terminal, and it displays the maximum voltage than can safely be measured by the current circuit.

The Serial Port Monitor in the IDE can be used to view the messages sent by this sketch.

The serial port you need to connect to can be found from the Arduino IDE: On the Tools menu, click Serial Port and look for the item that is ticked.The other setting you should use are:

Display: ANSI

Speed: 9600

Parity: None

Data Bits: 8

Stop Bits: 1

Hardware Flow Control: None

Software Flow Control: None

## Step 4: Building the Circuit

Disconnect the Arduino from your computer before building this circuit!

The circuit can be constructed on a breadboard:

The analog inputs of an Arduino can measure up to 5V (when using the built-in analog reference voltage). Even when only connecting to a 5V circuit, you should use the resistors to help protect the Arduino from short-circuits or unexpected voltage surges.

Those two resistors form a potential divider that is used to lower the voltage being measured to a level that the Arduino can read. This actually extends the range that can be used. For example, if resistors are used to halve the input voltage then the Arduino can effectively read up to 10V (since 10V will be read as 5V, 5V will be read as 2.5V…). This comes at the expensive of accuracy – the ADCs in the Arduino can read up to 1024 different levels between 0V and 5V. By expanding the range to 10V, those 1024 levels are spread across a wider range and are therefore less able to detect small changes.

You can increase the resistance value of R2, then the maximum voltage that can be read will be decreased; giving a slightly more accurate reading. With R1 at 100Ko and R2 at 10Ko, the input voltage is reduced by a factor of around 11 – allowing the voltmeter to read from 0V–55V.

The formula for calculating values in a potential divider is:

Vout = (R2 / (R1 + R2)) * Vin

If the divider for the Arduino voltmeter is functioning correctly then Vout will be a maximum of 5V, and so you can calculate the maximum input voltage to the circuit:

`Vmax = 5.0 / (R2 / (R1 + R2))`

You can see a variation of this expression used in the setup() routine of the sketch.

Note: If you use different resistors from the ones suggested here, you must be remember to adjust the values of r1 and r2 in the sketch.

When measuring the voltage in the loop() routine, analogRead(0) is used to read the level from analog input 0. The returned value is an integer in the range 0 through 1023, so it must first be adjusted to a range 0 through 5. This is done by multiplying it by the power supply level, and then dividing by 1024.

To transform the 0V–5V value into a reading that reflects the range of values that can be measured by the circuit, the resistors must be taken into account in the same way as was done to calculate the maximum voltage the circuit could measure:

v2 = v / (r2 / (r1 + r2))

## Step 5: Current Measurment

For current measurement we will use a Hall Effect current sensor ACS 712 (30 A).

WORKING PRINCIPLE :

The Hall Effect is the production of a voltage difference (the Hall voltage) across an electrical conductor, transverse to an electric current in the conductor and a magnetic field perpendicular to the current.

The data sheet of ACS 712 sensor is found online easily.

From Data Sheet of ACS 712, it measure positive and negative 30Amps, corresponding to the analog output 66mV/A.

No test current through the output voltage is:

VCC / 2 =5v/2=2.5V

Calibration:

Analog read produces a value of 0-1023, equating to 0v to 5v

So, Analog read 1 = (5/1024) V =4.89mv

Value = (4.89*Analog Read value)/1000 V

But as per data sheets offset is 2.5V (When current zero you will get 2.5V from the sensor's output)

Actual value = (value-2.5) V

Current in amp =actual value*10

## Step 6: Time Measurement

For time measurement there is no need of any external hardware, as ARDUINO itself has inbuilt timer. The millis() function returns the no of milliseconds since the Arduino board began running the current program.

## Step 7: Connect LCD

### Connect LCD with ARDUINO as given bellow :

LCD -> Arduino

1. VSS -> Arduino GND

2. VDD -> Arduino +5v

3. VO -> Arduino GND pin + Resistor or Potentiometer

4. RS -> Arduino pin 8

5. RW -> Arduino pin 7

6. E -> Arduino pin 6

7. D0 -> Arduino - Not Connected

8. D1 -> Arduino - Not Connected

9. D2 -> Arduino - Not Connected

10. D3 -> Arduino - Not Connected

11. D4 -> Arduino pin 5

12. D5 -> Arduino pin 4

13. D6 -> Arduino pin 3

14. D7 -> Arduino pin 2

15. A -> Arduino Pin 13 + Resistor (Backlight power)

16. K -> Arduino GND (Backlight ground)

SPI : Import from arduino IDE (sketch -> Import library.....)

Ethernet : Import from arduino IDE ((sketch -> Import library.....)

Open an account with http://xively.com

Working Code is attached in this step.

I am creating a detailed video.

Feel free to ask anything if you have any difficulties.

## Step 9: Packing Up Your Circuits

You can use any thing to manage and install your circuit in it. I used an old DSL router of Orange. Got it from garbage store :P.

I removed main board from the casing of Orange DSL Router. and modified it accordingly.

## Step 11: Checking My Working Solar Meter

This video was made when there was power cut down from grid station. So its showing 000V in AC in. Participated in the
First Time Author Contest 2016 Participated in the
Internet of Things Contest 2016 Participated in the
Sensors Contest 2016

## Recommendations

2 933
3 161
93 5.9K ## 17 Discussions

hi.....i have to compare DC voltage and current of two solar modules. Can I do this with this arrangement? can I use two analogs i/p of Arduino for two voltage source grounding both negative terminal?since there is only 6 analogs i/p terminal and for comparison there is need of 8 i/p(2 for foltage 2 for current for both modules).