hi every one
i am making a prepaid energy meter using arduino uno and sim800l but the code is not working well.
it says that the sendsms is not declared inn this scope here is the complete code
#include <Sim800L.h>
#include<SoftwareSerial.h>
String str = "";
Sim800L Sim800L;
SoftwareSerial myserial (9, 10); // 9 rx 10 tx
#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 stri[70], flag1 = 0, flag2 = 0;
String bal = "";
void setup()
{
lcd.begin(16, 2);
myserial.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("GSM Initilizing...");
gsmInit();
lcd.clear();
lcd.print("System Ready");
sendSMS("SYSTEM READY");
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 (myserial.available())
{
char ch = (char)myserial.read();
stri[i++] = ch;
if (ch == '*')
{
temp = 1;
lcd.clear();
lcd.print("Message Received");
delay(2000);
break;
}
}
}
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, LOW);
flag1 = 0;
flag2 = 0;
}
if (rupees < 15 && flag1 == 0)
{
lcd.setCursor(0, 1);
lcd.print("LOW Balance ");
sendSMS("Please recharge your energy meter soon Thank you Low Balance:");
myserial.println(rupees);
flag1 = 1;
}
if (rupees < 5 && flag2 == 0)
{
digitalWrite(relay, HIGH);
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 ");
sendSMS("Light cut due to low Balance\nPlease recharge your energy meter soon.\n Thank you");
flag2 = 1;
}
}
void decode_message()
{
x = 0, k = 0, temp = 0;
while (x < i)
{
while (stri[x] == '#')
{
x++;
bal = "";
while (stri[x] != '*')
{
bal += stri[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);
sendSMS("ELECTRICITY CONNECTED Your energy meter has been recharged Rs:");
myserial.println(rupees);
temp = 0;
i = 0;
x = 0;
k = 0;
delay(5000);
}
void sending(String msg)
{
lcd.clear();
lcd.print("Sending SMS");
myserial.println("AT+CMGF=1");
delay(5000);
myserial.print("AT+CMGS=");
myserial.print('"');
myserial.print("+923411046117");// number
myserial.print('"');
myserial.println();
delay(5000);
myserial.println(msg);
delay(5000);
myserial.write(26);
delay(3000);
lcd.clear();
lcd.print("SMS Sent");
delay(3000);
lcd.begin(16, 2);
}
void gsmInit()
{
lcd.clear();
lcd.print("Finding Module..");
boolean at_flag = 1;
while (at_flag)
{
myserial.println("AT");
while (myserial.available() > 0)
{
if (myserial.find("OK"))
at_flag = 0;
}
delay(3000);
}
myserial.println("ATE0");
lcd.clear();
lcd.print("Finding Network..");
boolean net_flag = 1;
while (net_flag)
{
myserial.println("AT+CPIN?");
while (myserial.available() > 0)
{
if (myserial.find("READY"))
net_flag = 0;
break;
}
delay(2000);
}
myserial.println("AT+CNMI=2,2,0,0,0");
delay(2000);
myserial.println("AT+CMGF=1");
delay(2000);
myserial.println("AT+CSMP=17,167,0,0");
lcd.clear();
myserial.flush();
}