# 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:

## 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

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.

## 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:

## 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

## 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.

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:

$P(1-\Phi) = V \times \times I \times cos \phi$

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.

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.

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

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.

## 79 thoughts to “Smart Energy Meter using Atmel AVR Microcontrollers”

1. vivek magar says:

Sir I wanted to do program in pic16f microcontroller. Can you help me in program.

2. shiva shiva says:

share the link here if any software require to dump the program as of now im having codevision avr and atmel studio 8.0 version and tq for ur response sir

3. shiva shiva says:

sir can you help me in detail and can i use atmega8a-pu instead of atmega8?

4. shiva shiva says:

sir how to burn program into micro-controller usbasp or usb to ttl converter which one is easy method??

5. RIHEM HSSAN says:

HELLO i want to know the appropriate 3-phase voltage transformer?
ps: my power supply is 380/220v

6. bhushan joshi says:

sir i want arduino program for atmega328p for same project

plz send me proteous file and code file of this project if you have.

8. Steve says:

* so I copied everything except mega8.h (I couldnt find which file is associated with the mega8.h, error says: "No such file or directory")

9. Steve says:

Hi Ismail, I have tried this in my own project but got stuck in the ftoa function.

1. The first time I compiled, I got error: "warning: implicit declaration of function 'ftoa'"

2. I assumed that the function is from one of your library, so I copied everything except (I couldnt find which file is associated with the , error says: "No such file or directory")

3. I compiled again, and ftoa function still resulted in the same error: "warning: implicit declaration of function 'ftoa'".

Much much thanks!

10. Valliappan says:

what is full working of proteus file?

can you explain me how the current and voltage in the circuit is measured and displayed?

pls send me a complete working of both block diagram and simulation diagram

my mail : manivalliappan2@gmail.com

Dear Mr.Ismail
the code includes mega.h and delay.h which is not exist in Atmel studio..
What should I do??

best regards..

12. Futoon says:

Dear Mr. Ismail

There are some problems in the code, such as PINC.3, PORTD.2 and so on. It gives error and I don't know how to make it right. Please help 🙁

ualsharif@effat.edu.sa

13. abla attia says:

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.

1. Ofcourse you can use 100A CT. It will improve the performance of the circuit. At 220 volt ith 100A CT your power ratings will be exceeded to nearly 22.000 kW.

14. Futoon says:

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 4: It should be in miliAmps.

15. 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.

16. 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.

17. Hello, Sir nice articles, I want AVR studio codes for all the circuits, Energy Meter, Voltmeter, Ammeter and Power Factor.
Email: satyamehta1996@gmail.com

18. saravanan says:

sir where i have to connect my loads?

19. Anonymous says:

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.

20. Zobayer Rahman says:

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.

Thank you.

Best Regards,

Zobayer Rahman

1. Dear I have shared complete code of the project. You can understand that code to understand the working flow of circuit.

21. Anonymous says:

Greetings! sir i need code for Atmel studio and a picture or screenshot of proteus simulation, i think i could`t download Proteus files thoroughly.... my email is : zaka.zaki1996@gmail.com

22. Akshay says:

I dont see a HEX file in the folder ive downloaded. There are DBK, DSN and PWI files

23. Akshay says:

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. Use hex file present inside the folder.

24. Ahmed says:

Sir: the o/p of current sensor is DC . Is it important to get op amp Ac i/p . can you provide me the Complete Circuit Diagram My email is Ahmed.elfakhrany56@gmail.com

1. Ismail says:

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.

25. Ahmed says:

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. Ismail says:

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.

26. 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'.

1. Ismail says:

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.

27. SANTI BHUSAN ACHARYA says:

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

28. SANTI BHUSAN ACHARYA says:

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

29. sneha says:

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

1. Ismail says:

use '.c' file and compile that file again with respect to your requirement.

30. pranoti chavan says:

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?

1. Ismail says:

Just a multiplying factor with the energy unit variable will serve the purpose.

31. Anonymous says:

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. Ismail says:

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.

32. Zaman says:

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.

33. Anonymous says:

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

1. Ismail says:

You are asking really sensitive question. Kindly explain it. So that I can give you right answer.

34. Anonymous says:

hey sir!
i wanna know which crystal should i use? 4Mhz or 8Mhz or 16 Mhz ?

1. Ismail says:

Its purely your own choice. In this project, I am using internal crystal of 1Mhz.

35. Anonymous says:

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. Ismail says:

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. Anonymous says:

oh sorry i mean pt 🙂 thanks sir ))

36. Hello Sir

I can't get Complete Code and Proteus File from above given links, it was just loading and not showing anything.

1. Ismail says:

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.

37. Raj Gohil says:

sir whats the difference in this meter and the meter we have installed in our home?

1. Ismail says:

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. steven says:

sir do you have energy meter code ??.the simple one which display only the energy reading.

1. Ismail says:

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.

1. steven says:

sir can i have the hex file ? i dont know what software do i use to create the hex file.

2. Ismail says:

Use CodeVision AVR Software to creat HEX file.

38. Anonymous says:

Battery voltage

39. Anonymous says:

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?

40. Rajiv Shandilya says:

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

1. Ismail says:

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.

41. debraj nath says:

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

42. debraj nath says:

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

1. Ismail says:

Everything is given in my article. Don't hesitate to use them 🙂

43. Ranjit says:

Dear sir,
If you have any projects regarding to solar inverter ongrid or offgrid kindly inform me.My email id is ranjit467534@gmail.com

1. Ismail says:

I don't have one. I will upload articles on solar soon. 🙂

44. Ranjit says:

Sir its awesome thank you for your contribution

45. Mayur says:

I want full list of components and simulation files.

1. Ismail says:

You can get your required files in the above article. Feel free to have them 🙂

This site uses Akismet to reduce spam. Learn how your comment data is processed.