0% found this document useful (0 votes)
50 views5 pages

Coding On Prepaid Energymeter

1) The document contains code for an automatic energy meter that uses a GSM module to send SMS alerts when the balance is low. 2) It initializes the LCD display and GSM module, reads energy pulses to calculate usage and balance, and sends SMS alerts when the balance drops below certain thresholds. 3) It can also receive SMS messages containing recharge amounts, decode them to update the balance, and send a confirmation SMS along with reconnecting the electricity.

Uploaded by

Prakash Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views5 pages

Coding On Prepaid Energymeter

1) The document contains code for an automatic energy meter that uses a GSM module to send SMS alerts when the balance is low. 2) It initializes the LCD display and GSM module, reads energy pulses to calculate usage and balance, and sends SMS alerts when the balance drops below certain thresholds. 3) It can also receive SMS messages containing recharge amounts, decode them to update the balance, and send a confirmation SMS along with reconnecting the electricity.

Uploaded by

Prakash Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#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 pulse_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("Friends Arena");
delay(2000);
lcd.clear();
lcd.print("GSM Initializing...");
void gsm_init();
gsm_init();
lcd.clear();
lcd.print("System Ready");
Serial.println("AT+CNMI=2,2,0,0");
void init_sms();
init_sms();
void send_data(String message);
send_data("System Ready");
void send_sms();
send_sms();
delay(1000);
digitalWrite(led,LOW);
lcd.clear();
// EEPROM.write(1,0);
// rupees=EEPROM.read(1);

}
void loop()
{
void serialEvent();
serialEvent();
rupees=EEPROM.read(1);
units=rupees/20.0;
lcd.setCursor(0,0);
lcd.print("Units:");
lcd.print(units);
lcd.print(" ");
lcd.setCursor(0,1);
if(rupees<25)
lcd.print("LOW Balance");
else
lcd.print("Balance");
lcd.print(rupees);
lcd.print(" ");
void read_pulse();
read_pulse();
void check_status();
check_status();
void decode_message();
void send_confirmation_sms();
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=\"+917007588894\"");
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*20;
EEPROM.write(1,rupees);
while(!digitalRead(pulsein));
digitalWrite(led,LOW);
// delay(2000);
}
}
void check_status()
{
if(rupees>25)
{
digitalWrite(relay,HIGH);
flag1=0;
lcd.setCursor(0,1);
lcd.print("LOW Balance");
init_sms();
flag2=0;
}
void flag();
if(rupees<25&&flag==0)
{
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();
void message_sent();
message_sent();
flag1=1;
}
if(rupees<15&&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:\n Light Cut due to low balance\n Please
recharge your energymeter soon.\n Thank you");
send_sms();
void message_sent();
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();
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("Electricity 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("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("ATEO");
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();

You might also like