Power Meter Project Using GSM and Arduino

 Prepaid electricity energy meter is a good concept with which you can recharge the balance, as we do in our mobile phones. In this project we are building an automated system using Arduino and GSM module. You can recharge your electricity balance through this system just by sending an SMS. It can also disconnect the home power supply connection, if there is low or no balance in the system. And this system will read the readings of the power meter and automatically send some updates to the user's mobile phone such as low balance alert, cut-off alert, resume alert and recharge alert.


Project description:

Here we have connected an electricity power meter with an Arduino using an electric power meter's LED pulse. We just need to connect the tis CAL LED to the Arduino through the Optocoupler IC.

Ingredients used:
     Arduino
     GSM module
     16x2 LCD
     Analog Electricity Meter
     Optocoupler 4n35
     resistors
     Container
     wire connection
     bulb and holder
     SIM card
     power supply
     Mobile phone

When we power on the system it reads the previous values ​​stored in the EEPROM and restores them in the variables then checks the available balance with the preset value and takes action according to it like if the available balance is greater than Rs 15 then the Arduino will turn on the home or office electricity using the relay. And if the balance is less than Rs 15, the Arduino sends an SMS to the user's phone regarding the low balance alert and asks to recharge soon. And if the balance is less than 5 rupees, Arudino will turn off the electricity to the house and send an SMS to the user's phone to alert 'Light Cut' and request a recharge soon. The GSM module is used to send and receive messages.

Now when we need to recharge our system, we can recharge it simply by sending an SMS to the system, through our mobile phone. Like if we want to recharge with $45, we will send *#45, here # and * are the prefix and suffix of the recharge amount. The system receives this message, extracts the shipping amount, and updates the system balance. The system again turns on the electricity of the home or office.

circuit diagram

 

 The circuit connections of the wireless electricity meter reading project are shown in the diagram; We have used an Arduino UNO to process all the things used in the project. The liquid crystal display is used to display the status of the units and the remaining balance. The LCD data pins RS, EN, D4, D5, D6, and D7 are connected to the Arduino digital pin number 7, 6, 5, 4, 3 and 2. Also, the Rx and Tx pins of the GSM module are directly connected to the Tx and Rx pins of the Arduino on straight. The GSM module is powered by a 12V adapter. A relay is used to switch the power supply connected to pin 12 of the Arduino through the ULN2003 driver.

Code Explanation :Power Meter Project Using GSM and Arduino :

We include the required library and define the required pins and variables in our project. This can be seen in the first few lines of our program code below.

After that we configure the LCD, serial communication, GSM and display some message messages.

After this in the loop function we read the received serial data if any. It reads the pulse from the energy meter and shows the units and balance on the LCD screen. 


After this in the loop function we read the received serial data if any. It reads the pulse from the energy meter and shows the units and balance on the LCD screen.

 

The functions void init_sms(), void send_data (string message), and void send_sms() were used to send SMS.

The gsm_init() function is used to configure the GSM module to be ready to work with the system. In this, we first send an AT command to see if the GSM module is connected or not. Next we turned off echo and then checked the network.

 

 The check_status() function system reads the connection and balance conditions; Such as if the electricity balance is greater than the specified limit. If the balance is less than 15, it alerts the user by sending SMS alert with “Low Balance” and if the balance is less than 5 rupees, the system will cut off the electricity and inform the user by sending SMS using the GSM module.

 

 The send_confirmaiton_sms() function is used to send a confirmation message to the user if a recharge is made and also to update the balance in the system.

The decode_message() function is used to decode the amount number from an SMS, using # and * as the start and end character.

The read_pulse() function is used to read the pulse from the power meter through the optocoupler IC. Updating unity and balance.


 

 The serialEvent() function is used for serial communication and message receipt.

//WWW.enghme.com
#include<EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);

int led=13;
#define pulsein 8
#define relay 12
unsigned int pusle_count=0;
float units=0;
unsigned int rupees=0;

 float watt_factor=0.3125;
unsigned int temp=0,i=0,x=0,k=0;
char str[70],flag1=0,flag2=0;

String bal="";

void setup()
{
  lcd.begin(16,2);
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(pulsein, INPUT);
  pinMode(relay, OUTPUT);
  digitalWrite(pulsein, HIGH);
  lcd.setCursor(0,0);
  lcd.print("Automatic Energy");
  lcd.setCursor(0,1);
  lcd.print("      Meter    ");
  delay(2000);
  lcd.clear();
  lcd.print("Circuit Digest");
  delay(2000);
  lcd.clear();
  lcd.print("GSM Initilizing...");
  gsm_init();
  lcd.clear();
  lcd.print("System Ready");
  Serial.println("AT+CNMI=2,2,0,0,0");
  init_sms();
  send_data("System Ready");
  send_sms();
  delay(1000);
  digitalWrite(led, LOW);
  lcd.clear();
//  EEPROM.write(1,0);
 // rupees=EEPROM.read(1);
}

void loop()    
{
    serialEvent();
    rupees=EEPROM.read(1);
    units=rupees/5.0;
    lcd.setCursor(0,0);
    lcd.print("Units:");
    lcd.print(units);
    lcd.print("      ");
    lcd.setCursor(0,1);
    if(rupees<15)
    lcd.print("LOW Balance:");
    else
    lcd.print("Balance:");
    lcd.print(rupees);
    lcd.print("      ");
    read_pulse();
    check_status();
    if(temp==1)
    {
     decode_message();
     send_confirmation_sms();
    }
}
void serialEvent()
{
  while(Serial.available())
  {
    char ch=(char)Serial.read();
    str[i++]=ch;
    if(ch == '*')
    {
      temp=1;
      lcd.clear();
      lcd.print("Message Received");
      delay(500);
      break;
    }
  }
}

void init_sms()
{
   Serial.println("AT+CMGF=1");
   delay(200);
   Serial.println("AT+CMGS=\"+918287114222\"");
   delay(200);
}

void send_data(String message)
{
  Serial.println(message);
  delay(200);
}

void send_sms()
{
  Serial.write(26);
}

void read_pulse()
{
    if(!digitalRead(pulsein))
    {
      digitalWrite(led, HIGH);
      //count++;
      //units=watt_factor*count/1000;
      if(units<1){}
      else
      units--;
      rupees=units*5;
      EEPROM.write(1,rupees);
      while(!digitalRead(pulsein));
      digitalWrite(led,LOW);
     // delay(2000);
    }
}

void check_status()
{
      if(rupees>15)
      {
        digitalWrite(relay, HIGH);
        flag1=0;
        flag2=0;
      }
      if(rupees<15 && flag1==0)
      {
       lcd.setCursor(0,1);
       lcd.print("LOW Balance       ");
       init_sms();
       send_data("Energy Meter Balance Alert:");
       send_data("Low Balance\n");
       Serial.println(rupees);
       delay(200);
       send_data("Please recharge your energy meter soon.\n Thank you");
       send_sms();
       message_sent();
       flag1=1;
      }
      if(rupees<5 && flag2==0)
     {
      digitalWrite(relay, LOW);
      lcd.clear();
      lcd.print("Light Cut Due to");
      lcd.setCursor(0,1);
      lcd.print("Low Balance");
      delay(2000);
      lcd.clear();
      lcd.print("Please Recharge ");
      lcd.setCursor(0,1);
      lcd.print("UR Energy Meter ");
      init_sms();
      send_data("Energy Meter Balance Alert:\nLight cut due to low Balance\nPlease recharge your energy meter soon.\n Thank you");
      send_sms();
      message_sent();
      flag2=1;
    }
}

void decode_message()
{
  x=0,k=0,temp=0;
     while(x<i)
     {
      while(str[x]=='#')
      {
        x++;
        bal="";
        while(str[x]!='*')
        {
          bal+=str[x++];
        }
      }
      x++;
    }
    bal+='\0';
}

void send_confirmation_sms()
{
    int recharge_amount=bal.toInt();
    rupees+=recharge_amount;
    EEPROM.write(1, rupees);
    lcd.clear();
    lcd.print("Energy Meter ");
    lcd.setCursor(0,1);
    lcd.print("Recharged:");
    lcd.print(recharge_amount);
    init_sms();
    send_data("Energy Meter Balance Alert:\nYour energy meter has been recharged Rs:");
    send_data(bal);
    send_data("Total Balance:");
    Serial.println(rupees);
    delay(200);
    send_data("Eelctricity Has Been Connected\nThank you");
    send_sms();
    temp=0;
    i=0;
    x=0;
    k=0;
    delay(1000);
    message_sent();
}

void message_sent()
{
  lcd.clear();
  lcd.print("Message Sent.");
  delay(1000);
}

void gsm_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag=1;
  while(at_flag)
  {
    Serial.println("AT");
    while(Serial.available()>0)
    {
      if(Serial.find("OK"))
      at_flag=0;
    }
    delay(1000);
  }

  lcd.clear();
  lcd.print("Module Connected..");
  delay(1000);
  lcd.clear();
  lcd.print("Disabling ECHO");
  boolean echo_flag=1;
  while(echo_flag)
  {
    Serial.println("ATE0");
    while(Serial.available()>0)
    {
      if(Serial.find("OK"))
      echo_flag=0;
    }
    delay(1000);
  }

  lcd.clear();
  lcd.print("Echo OFF");
  delay(1000);
  lcd.clear();
  lcd.print("Finding Network..");
  boolean net_flag=1;
  while(net_flag)
  {
    Serial.println("AT+CPIN?");
    while(Serial.available()>0)
    {
      if(Serial.find("+CPIN: READY"))
      net_flag=0;
    }
    delay(1000);
  }
  lcd.clear();
  lcd.print("Network Found..");
  delay(1000);
  lcd.clear();
}

 

Post a Comment

Previous Post Next Post