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

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

Main Parts of Smart Energy Meter

The following is the complete circuit diagram of Smart Energy Meter. You can see the blocks partition in the diagram. To see the whole diagram in details click on the image 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.

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.

We will have here little discussion about LCD interfacing and its coding. To study completely study 4-Bit LCD interfacing. 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.

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 we are using the receive interrupt. When someone sends the “off” string the load will be disconnected and when someone will send “on” string the load will be connected.

Note: To enable the interrupt at receiving data make sure you enable the RXCIE bit in UCSRB register

PCB Designing

There are a lot of ways to designs PCB layout, manually or by using some software. Different software’s are also available in market for PCB designing. 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

Electrical engineering is my profession, my hobby and my passion. I completed bachelors of electrical engineering in 2015. Currently I am working with a utility company which provides electricity to its consumers. Power Electronics, Embedded Systems and Energy Metering are my fields of specialization. In free time I listen music and watch movies.

24 thoughts on “Smart Energy Meter using Atmel AVR Microcontrollers

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

  2. 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?

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

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

  5. 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?