Smart Energy Meter using Atmel AVR Microcontrollers

What is Smart Energy Meter?

A smart energy meter is device which can calculate the energy consumption and send it to energy provider through some communication medium. It must be compact, cost effective and able to communicate data by itself with the power control center.

I designed a smart energy meter through an ATmega8 microcontroller with following specifications:

  • Compact size
  • Cheap
  • Can be able to measure up to 2.5KW load
  • LCD to show complete data to consumer
  • Data communication at every 3 seconds to the control center
  • Control Center can connect or disconnect the load
  • Auto Warning to consumer for Excessive usage of power

Study a comparison article on AMR vs AMI Enabled Smart Energy Meters

Components used in the Smart Energy Meter:

Click on the component name to buy the product from reliable sources:

Main Parts of Smart Energy Meter

To explain the circuitry I divided whole smart energy meter into following blocks:

The following is the complete circuit diagram of Smart Energy Meter. You can see the blocks partition in the diagram below:

Circuit Diagram of Smart Energy Meter
Figure 1: Complete Circuit Diagram (Smart Energy Meter)

Where to start?

In circuit diagram, you can see there are three blocks named as voltmeter, Ammeter and Power factor meter. In this article, I am not able to enlighten those blocks due to their lengthy explanations. So, before you start reading this article, I will advice you to first read the articles which I linked below.

AC voltage measurement using Atmel AVR microcontrollers

AC current measurement using Atmel AVR microcontrollers

Power factor measurement using Atmel AVR microcontrollers

Now I will explain the remaining parts of smart energy meter and how to link the Voltmeter, Ammeter and Power Factor meter to the whole system.

Why ATmega8? Not Arduino or other?

I used ATmega8 due to its cheapness, availability, compactness and versatility.

Cheapness: Yes it is cheap. I had to make three smart energy meters for my project and they saved me lot of money.

Availability: It is pretty famous microcontroller and it is available at almost every electronics components shop.

Compactness: The size of this ATmga8 makes it ideal to make small circuits.

Versatility: In this small microcontroller you will find most of the things one need to. It has UART, I2C, Timers etc and also gives flexibility of external and internal interrupts.

To study the complete comparison, follow the link below:
Arduino: Advantages and Disadvantages

Energizing Circuit:

I have energized the circuit from voltage source of load itself. You may notice that the simple energy meters do not have batteries or other things to energize it. There are just two incoming terminals and two out going terminals and that’s all. So I made this system in such a way that two pairs of incoming and outgoing terminals are enough to complete the whole process i.e. no need of external batteries.

Study complete article on different ways to make 5 volt supply

The smart energy meter comprises of 220/12 volt transformer to step down the voltage then a rectifier bridge will convert the AC 12 volts RMS to DC volts. A capacitor 47uf will remove the ripples of DC voltage. After that a voltage regulator LM7805 is present which will hold the output voltage to 5volts. There is a LED present after the 7805 IC which tells the correct working of energizing circuit. The energizing circuit is shown below:

Energizing Circuit for Microcontrollers
Figure 2: Energizing Circuit

Reset Circuit:

Generally we don’t need the reset button in case of smart energy meters but in case of some error or any other reason you may have to restart the system. In that case this circuit will help you.

The reset button of ATmega8 is active low pin which means the pin will become active when it gets a zero or low signal. Reset Circuit Consists of 10k ohm pull up resistor. A pull-up resistor pulls that pin to high state until it gets another path of low resistance to complete its circuit. PINC.6 is the reset pin of ATmega8 which will get a high signal continuously until someone will press the push button present in the circuit. When the push button will be pressed PINC.6 will get a path of low resistance to the ground and in this way it will get a low value and reset the microcontroller to the initial state

Recent Circuits for Microcontrollers
Figure 3: Reset Circuit for Microcontrollers

LCD Interfacing

In pursue of small and cost effective smart energy meter, I gave the 16x2 LCD to the system to display all our parameters. This display is nothing to do with the distribution company providing the electricity. LCD is for the consumer to know its present status of units and other stuff like voltage, current or power factor.

As we have small microcontroller having less number of pins so we did 4 bit interfacing of LCD with microcontroller to save pins for other stuff.

Little discussion about interfacing of 4 bit LCD:

We will have here little discussion about LCD interfacing and its coding.  First two pins are for the energizing of the LCD and third pin is for the contrast setting. ‘RS’ pin is controlled by microcontroller which decides that the command will be read by the LCD or some data is going to display on the LCD. Commands are to control the LCD and data are those things which will display on the LCD.RS=0 for commands and RS=1 for data. ‘R/W’ pin is not mandatory to discuss here just connect it with ground every time you see that pin.

‘E’ pin is used for the entering of data or command into the LCD. LCD has to get a negative pulse on ‘E’ pin for entering of commands or data. D0 to D7 pins are data pins but as we are using 4-bit interfacing so only D4 to D7 pins are going to connect with microcontroller. Remaining pins will be left disconnected. You may ground the remaining pins but it is not necessary.

Study this article to completely understand the topic 4-Bit LCD interfacing.

4 bit LCD interfacing with Microcontrollers
Figure 4: LCD Interfacing with MicroControllers

The Coding of 4-bit interfacing is little bit different than 8-bit interfacing. We push 4 bits to the LCD from microcontroller ATmega8 and then push other 4 bits. As shown in the writecmd() function. PORTB is pushing first four bits and pushed the other four bits after shifting the remaining bits.

//.............................Begin LCD Code...........................

int writecmd(char z){
RS=0;
PORTB=z;
E=1;
delay_ms(1);
E=0;
delay_ms(1);      
z1 = z << 4;
PORTB=z1;
E=1;
delay_ms(1);
E=0;
delay_ms(1);
return 0;}

The initialization commands of 4-bit LCD are little bit different than 8-bit interfacing. You should have first two commands like this.

void lcd_init(void){
writecmd(0x02);
writecmd(0x28);
writecmd(0x0c);
writecmd(0x01);
writecmd(0x06);}

Power and Energy Calculations:

We know the formula for single phase power is follows:

We have calculated the Voltage, Current and cos(φ) as well. So we can easily measure the power through multiplying these three parameters. But the main goal of the energy meter is not to find the power but to find units consumed.
We know:
So to calculate the unit consumed we have to multiply the power with time. Whole measurements of voltage, current, power, power factor is done in 3.3 seconds. So, if we multiply the power with 3.3 seconds then we can get the unit consumed.
am=3.3*am;  //here am is power
am=am/3600;  //for conversion in hours
energy=am+energy;  // Here am is new unit consumed and energy is old unit consumed
ftoa(energy,2, buf);
cstring_trans (buf); // units consumed transferring to communication module
cstring_trans ("\n\r");
lcd_init();
lcd_print("***ENERGY***");
lcd_gootooxy(1,2);
lcd_print(buf);
lcd_print("Wh");

Don’t worry you will get the whole code at the end of the article.

Control Circuit

Control circuit in Smart Energy Meters is for controlling the supply of the consumer from the control center. The control circuit enables the control engineer present in the control center to disconnect or connect the supply of a specific consumer. For the controlling purpose electric relay is our best option. To study the electrical relay, follow the link below:

How to use relays with microcontrollers

Without getting involved in the details of relay we will directly explain here the circuitry and coding of control circuit.

Load Control Circuit
Figure 5: Control Circuit

The resistor present here is to limit the current or more precisely it is for the safety of microcontroller. The transistor is for the amplification of the voltage and diode is to stop the inductor of the relay to give back emf. In normally open condition the circuit will be complete and load will get the supply but when someone wants to disconnect the load then a command will send to the microcontroller which will give high command to the PIND.2. After this the relay will operate and load will be disconnected. Its coding is as follows:

interrupt [USART_RXC] void intrp()
{
data1= cstring_rec ();
while(1){
if(strncmp(data1,"off",3)==0){
PORTD.2=1;}
lcd_print("House Disconnected");
data1= cstring_rec();
if(strncmp(data1,"on",2)==0){
PORTD.2=0;
break;}
 }
}

For its coding receive interrupt will be used. When someone sends the “off” string, the load will be disconnected and when someone will send “on” string, the load will be connected.

Note: Make sure you enable the RXCIE bit in UCSRB register for enabling the interrupt at receiving data .

PCB Designing

Layouts of Printed Circuit Boards can be designed through manual ways or through some software. Many software packages are present for this purpose. We used Proteus for our basic circuit designing and Proteus also provides PCB designing called ARES (Advanced Routing and Editing Software).

What is ARES?

ARES is used to create the PCB layout of the Proteus Circuit Design. The major features of ARES are auto placement and auto routing which helps a lot in designing a PCB layout.

 

Complete PCB Layout of smart energy meter
Figure 5: PCB Layout of Smart Energy Meter
Print of PCB for Smart Energy Meter
Figure 6: Print of PCB Layout
3D View of PCB
Figure 7: 3D View of PCB Layout
Smart Energy Meter
Figure 8: Final testing of Energy Meter

To get the complete code and simulation files click the buttons below:

Complete Code Proteus File

 

 

If You need anymore help feel free to comment below and don't forget to like our Facebook page 🙂

Ismail Sarwar

Electrical engineering is my profession, my hobby and my passion. I completed bachelors of electrical engineering in 2015. Currently I am working with an Electric Utility Company. Power Electronics, Embedded Systems and Energy Metering are my fields of specialization. In free time I listen music and watch movies.

64 thoughts to “Smart Energy Meter using Atmel AVR Microcontrollers”

  1. The 30 A current transformer is not available , can we use 100A one. Is this will affect the current reading and at which load power we can test this meter with this current transformer.

  2. Dear Mr. Ismail

    I have some questions regarding the circuit:

    1. At which load power did you test the meter.
    2. Did you actually test the circuit on 4 lamps?
    3. The transformer ratio, is it still at 1:1500 or less?
    4. In the current circuit, what is the expected current of the secondary winding of the transformer?

    1. Answer of point 1 & 2 : I tested this meter on nearly 2000 watts. Bearing of load majorly depends on rating of relay and current transformer. If you have relay of 100A and CT of 100A. Then the rating of the circuit will goes to 22 kWatts.
      Answer of point 3: It depends on your own CT ratio. Read rating of your CT.
      Answer of Point 4: It should be in miliAmps.

  3. Hello once again Ismail :),

    Thanks for you fast respone, seriously it means a lot to me.

    I know that the Relay circuit is to connect or disconnect a load, but, i throught that in the simulation you could connect or disconnect a load by sending "on/off".

    What do you mean by "load as real circuit"?

    Sorry if i ask dumb questions but i find this subject interesting but i'm not able to understand some concepts.

    Greetings from Mexico.

  4. Hello. First, thank you for sharing with us your Project. It has been really helpfull for me because i'm working in something similar. I downloaded the Simulation File but i was not able to understand two things:

    1. How do you connect or disconnect a load?
    2. What is the load in the simulation?

    Thank you once again.

  5. Nice tutorial. It would make a whole lot more sense, and be more convincing if you could also attach videos to these tutorials. That shows us that the design is not just a paper model, but a physically realizable design. But good work though; kudos.

  6. Dear Mr. Ismail Sarwar,

    Good Day!
    I hope you are well by the grace of almighty ALLAH.

    I am Zobayer Rahman from Bangladesh. I've been trying to build your 'Smart Energy Meter' project for a long time. I found this project magnificent. But in the process of making it, I am facing many adversities. So please help me with this email.

    I need some information for the purpose of fully accomplishing this task. One of which is the logic operation of the micro-controller. Here, I do not understand what logic operation is happening on each pin of the micro-controller. But it is very important for me to know the logic operation of this device for completing this task. For this, I want your urgent cooperation.
    If you explain to me the micro-controller's logic operation or explained it through a flow chart, then I could understand it & complete the project. So, Please help me.

    I already emailed you about this. If you answer my mail then I'll be very grateful to you for your cooperation.

    Thank you.

    Looking forward to your answer.

    Best Regards,

    Zobayer Rahman

  7. Good day Sir. I am having a problem implementing your simulation file. Proteus is not recognizing any of the file extensions. Could you please send me the proteus project files as soon as possible. I am a first time proteus user. This project is essential to one of my very own so your assistance is greatly appreciated. Email: amootheeram@gmail.com

    1. No the output of hall sensor is AC which have a offset in it. But in this application you can use it as the way it is.

  8. Hi Sir I change the CT with current sensor Acs712-30A the circuit work correctly on proteus not physically .Ameter and Voltmeter circuits each one worked alone but the SEMeter does not work and Power Factor too

    1. It seems that Power Factor area is not working correctly. For Power Factor measurement zero cross detection should be accurate. Use oscilloscope to resolve the matter.

  9. Hello, This is a brilliant project with a great idea. Your description make it far easier to understand. But can you provide me the whole equipment list & how i implement the source code in Proteus? And,can you provide me the 'Figure 1: Complete Circuit Diagram (Smart Energy Meter)' circuit diagram of Proteus? My email address is 'zobayerrahman@gmail.com'.

    Hope you will reply soon.

    1. I emailed your required image and in that image whole equipment is mentioned clearly. To implement project in Proteus just include HEX file into the Micro-controller of Proteus after double clicking on Micro-controller.

  10. Correction: Sir, I am having problem in getting the current transformer (1: 1500). Please tell some alternative. Can I use Hall effect sensor !!

  11. Sir, I am having problem in getting the current transformer (1500:1). Please tell some alternative.

  12. i want to add cost in this project. for that some programme chages are required but m not able edit that program and generate .cof file for proteous

  13. sir i did proteus simulation ..its working..now i want to add cost display..so what changes in program..how i have to change program..can u help me?

  14. Sir,i did it on proteus its running.now I want to display units consumed and cost on lcd for the same ..what I have to do??

    1. The energy measurements by the microcontroller is actually the units consumed. You just have to multiply the cost of a Energy unit with the Energy Variable. You will get your required result.

  15. Hey there sir.
    I decided to use the enc28j60 to share the values online.As it is i will need the change the LCD pings (PB4 and PB5) to use it.Because the enc28j60 ic is using the MISO,MOSI,SCK and SCL pings of the atmega8.I need help.How can i change the pings of PB4,PB5 to (for example) PD4,PD5 (or to PB0,PB1).I didnt get how can i use PB0-PB1 pings instead of PB4-PB5.Please help me.
    Thanks.

  16. hello sir.
    is it okay if i just combined my load with the energizing circuit rather than build another ac source? this means that i'm using only one transformer and current sensor.
    thank you

  17. Hello sir ! I have two questions about this project.First which ct transformer should i use ? (there are many kind of this..for example 220/6 6va or 220/6 8VA,10Va..).Second, i have studied the picture which made with Ares.I didnt see seconf lm358 ic .. where is other lm358? so. are there using together in same ic?

    1. I think you are asking about PT because the ratings you are writing here is of PT ratings. And you can use any of these, they all will give same results, but I will recommend to use 220/6 6VA (Least VA ratings will result in least power consumption). And Yes LM358 have two amplifiers in it, that's why I am using only one IC.

    1. After clicking on "complete code" button, a page will open. On that page there is a downward arrow at top right corner. Click on that arrow to download file.

    1. Dear Raj, the meters installed in our homes are simple energy meters which are capturing the energy units and just displaying it on its LCD. Smart Energy Meters are those meters that have the capability to send those captured energy units to a database through some means like GSM module or power line communication.

        1. Dear Steven, You can use same code for the simple energy meter as well. You just have to remove extra functions that making this
          Energy Meter a Smart One.

  18. Hi. I want to make a circuit that measure the voltage of automative motor. What is the interface circuit with avr micro? Can you help me please?

  19. SIR
    HOW TO MEASURE DC CURRENT VOLTAGE THROUGH CONTROLLER CIRCUIT & GET READING THROUGH GSM MODULE PLEASE GET HELP FOR PROJECT

    1. You have to combine different projects into one project. Go step by step.
      Step1: First of all study and implement that how to measure DC voltage and current. You can take help through these articles.
      http://engineerexperiences.com/dc-volt-measurement.html
      http://engineerexperiences.com/using-hall-sensor.html
      Step2: Study the basics of GSM and then implement a small project of related to GSM module. You can take help from the following articles.
      http://engineerexperiences.com/gsm.html
      http://engineerexperiences.com/control-leds.html
      After implementing these four projects you can easily get what you want by combining these projects.

  20. sir
    please send me the circuit diagram with proteus and c code. i want to use atmega 16/32 in place of atmega 8 and also the connection of various meters like voltmeter ammeter and pf meter is on clearly mentioned in the content . also i want that that the voltage and current would be displayed in the lcd . so please send me more information about this project because i am interested to do it for my b.tech final year project my email id : debrajnath230@gmail.com pg no : +919435240870

  21. sir cany you send me the circuit diagram with proteus and c code. i want to use atmega 16/32 in place of atmega 8 and also the connection of various meters like voltmeter ammeter and pf meter is on clearly mentioned in the content so please send me more information about this project because i am interested to do it for my b.tech final year project my email id : debrajnath230@gmail.com

What do you think?