The energy monitor is based on the Arduino Mega 2560 which offers sufficient memory and multiple UART’s (Serial Ports). Currently it is:
- Arduino Mega 2560 with EthernetShield
- Count pulses of kWh meter and generate energy statistics
- Read P1-port output of smart energy meter
- Upload the statistics to pvoutput.org
- Monitor electricity import and export from grid and total consumption
- Monitor gas consumption
- Send statistics over ethernet to my Arduino ‘Domotica Gateway’.
This page describes the parts used and roughly how it works. I have used parts of other free available code and combined it to what I wanted to have. Sourcecode is available on request, just leave a comment asking for it.
You will receive the whole package, Energy Meter, Domotica Gateway and Wireless LCD Display. Unfortunately it is not ‘monkey proof’, so you have to dig into the code and change it to suit your situation and needs.
Credits: Harold65 for his version 7 which is used as the base for my modifications.
This page will be updated with additional info. It takes some time to write it all down.
P1 – Port connection
The smart meter is connected with a RJ11 connector. You can use an old telefone cable if you like. There are 3 connections to make:
- RTS – set this HIGH and the meter will send data every 10 seconds
- GND – just connect it to GND on your arduino
- RxD – Serial receive. Connect to the 7404 chip (just continu reading!)
Remember: RJ11 can have 6 pins but usually comes with 4. So count as if there were 6 pins on the connector!!!
The smart meter P1 port has inverted TTL signals. TTL means the voltage is 0 – 5 volts instead of regular serial signals which are -12v and +12v. Also the signal is inverted so you can’t just connect it to your arduino. (you could when using softserial but I use the hardware serial port which offers better performance).
It’s not hard to invert the signals but you need an additional IC (chip) to invert the signals. Go buy a SN74HC04 chip for 20 cents and hook it up:
- Pin 14 to +5v (=VCC)
- Pin 7 to GND
- Pin 1 to RxD (from smart meter)
- Pin 2 to Arduino Receive on UART 1 (Pin 19 on Arduino)
When a 5 volt is received on Pin 1, a 0 volt is on pin 2
When a 0 volt is on pin 1, pin 2 becomes 5 volt. It just inverts the 1 to 0 and 0 to 1 😉
The Mega 2560 has 4 UART’s. UART 0 is also connected to USB for connection to the PC and serial monitoring. We pick UART 1 (serial1) which has the Receive on pin 19. The Smart meter uses a little different settings then normal. Since Arduino IDE 1.0.2 we can easily set those parameters by using:
Serial1.begin(9600,SERIAL_7E1);
In my code I use pin 4 to connect to the RTS pin in the smart meter. When Pin 4 is HIGH, the meter starts sending data every 10 seconds. I don’t do rocket science with this pin, just make it high at program start and start reading.
[wpdm_file id=4]
[wpdm_file id=5]
You receive the whole package, Energy Meter, Domotica Gateway, SensorBox and Wireless LCD Display so all versions are working together. I’ve packed all libraries as they are on my disk now. Those might not be the most recent versions, but they should work with sources.
Unfortunately the sources are not ‘monkey proof’, so you have to dig into the code and change it to suit your situation and needs.
Hi Alexander,
I am currently preparing for reading my own smart meter with my arduino. Would you be so kind to share your source with me.
Many thanks in advance,
Lex
Duven
It’s on it’s way to your mailbox 😉
Hi Alexander,
I’m building a robot (for the first time!) and want to monitor the power usage on it. The output of the power meter is on an RJ11 cable, but I don’t know if the signal is inverted or not. If it is not, is there a similar IC out there that does the conversion from +/-12V to 0-5V without inverting?
Thanks,
Felix
Have a look at the MAX232 IC which converts +/- 12v to TTL levels (0-5 volt)
alex
Hey,
Thanks!
I called the seller of the power monitor, and they don’t know whether the RJ11 signal is inverted. I am planning to go to the store to see the unit. Is there any easy way I can tell whether the unit sends inverted or non-inverted TTL signals?
Just connect to the arduino and try out. It won’t hurt, you’ll only see garbage on your screen when it is inverted signal. A 7404 IC is very cheap (maybe 50 cents or so). If you see garbage, put a 7404 inbetween.
Actually, my guess is that when you get RS232 signal (-12/+12 volts) that the signal is not inverted. It’s just a guess. Always use the Max232 IC to convert -12/+12v to 0/5 volt
Another option is to use softserial library. I’ve read that it contains an option to process inverted signals. Once you know what signal it is, you can go back to the hardware serial (UART).
Also check the bitrate and parity stuff (the 9600,8,N,1 stuff)
Hi,
I am building a solar powered office work station with the raspberry pie as a computer. I have a 12v lead acid battery supplying power to the loads. I want to keep a track of the state of charge in the battery ie the energy left. Please could you help me on how to do this using the arduino. I am new to this and not really sure how to proceed.
Thanks.
Hi Amit,
I don’t have experience in measuring the remaining charge level of batteries. While the sun is shining, the solarpanel will power your Raspberry and also charge the battery. At that point I don’t know how to measure the charge level of the battery. When it’s dark the Raspberry will discharge the battery. I expect you can measure the voltage of the battery. The lower the voltage, the less charge is left.
Try Google and search for ‘Arduino measure 12 volts’.
Good luck!
Alex
Hello Alexander,
Currently i’m using a Mega to readout my smart meter (used other info from the net). Now i’m adopting the code to readout my smart meter AND the solar production meter. The Mega should be able to do this. …..
Im very interested in you code, can you share this with me?
Thanks
Harry
Hi Harry,
that is indeed possible, I’m doing it in my source. You can find the source on my site: https://vdsar.net/wordpress/diy-domotica-solar-pv-output-metering/
Also, you should checkout: http://solarmeter.codeplex.com
I’ve used one of the older versions and added smart meter to it and some other things I like. Now there is already version 11.2 available at the codeplex site, that might do all you want.
Good luck!
Alexander
Hi Mr. Alexander!
We are currently doing a project research at school..would you mind giving us some advice? We’re also doing an energy meter using Arduino Mega 2560..Thanks a lot!
Hi Joan,
What kind of advice are you looking for? I think my blog can be a kind of inspiration for the project.
Best regards,
Alex
Hi Alex! Joan and I are on the same group, we’re trying to make a digital meter using Arduino Mega 2560. What we will do is to measure the ac current (setting 20Amps as our maximum) we will use current transformer to step it down (turns ratio: 20) and use a precision rectifier circuit. A change in load (change in current) will correspond to a change in voltage output of our precision rectifier. With a maximum of 13V and about 200mV as our minimum value from the output of our rectifier. Our problem is what pin (Digital/Analog) we must use to input this signal? And what are the voltage and current limits for this pins? Thanks in advance Alex 🙂
*Digital Energy Meter
Hi Ken, Joan,
I want to make a warning since I do not know how much experience you’ve got. 230 volts AC is dangerous and please check the kind of current transformer. I do not have experience with them, besides that I have one laying around in a box. I do know that there are warnings about the voltage they can generate and might be dangerous when touching them!
At the arduino.cc website you can find the specifications of the pins. It also contains information you should take into account (40 milliamps per pin in- or output).
You need an analog pin. If you are going to build things like this, do a google search on what analog and digital means. Digital has two values, 0 or 1 so with digital you can only detect two levels (0 volts or 5 volts). Useless for your purpose but useful for determine a push of a button (on or off).
The analog pin has an ADC convertor (Analog to digital) convertor. It converts the analog value to a digital value that can be represented by the microcontroller.
you have one challenge: The 200 mV to 13V needs to be reduced further. An analog port of the Arduino can measure values between 0 – 5 volts. So you have to step down the 13 volts to max 5 volts! I think you can use a voltage divider using two resistors. Also keep in mind, it is 10 bits ADC meaning the command: analogRead(pin used) returns a value between 0 and 1024. So your voltage of 0-5 volts is represented in 1024 steps!
So, if you can reduce the voltage from your current transformer to max 5 volt, it is relative simple to create the digital meter.
Check out this page to, it is of the EMON (energy monitor) which contains a lot of information on current transformers and also additional info to measure the voltage of the wall outlet and even the phase of the sinus. At least nice to read 😉
Good luck and enjoy building!
Alexander
Thanks Alex! This is a big help 😀 By the way, what will happen if i supply more than 5 Volts on the pins of arduino mega 2560?
more than 5 volts will damage the pin or even the whole Arduino chip. It might even start smoking.
Thanks Alex! This is a big help 😀
What will happen to the arduino if we supply its pin with more than 5 volts?
more than 5 volts will damage the pin or even the whole Arduino chip. It might even start smoking.
Hi Allexander,
I am looking for an immediate assistance on how to use the Arduino to know the remained units on the prepaid energy meter using pulses generated when a load is connected to the meter.
Kindly regards