You are on page 1of 5

When we talk about software implementation, to program this target you must be

very familiar with Arduino software and it’s algorithms. I’m not using any shield or
any other tool between the software and hardware. To program this target, I’ve
used only AT commands to communicate with the GSM module.

Software Program to Send a message and Read a message:


#include <LiquidCrystal.h>

char mob1[]=”9396553329″;
char msg1[]=”ON”;
char msg2[]=”OFF”;
char msg3[]=”QUERY”;

char a[70],i=0,k,temp;
char m=0,msg[15];
int count=0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
pinMode(7,OUTPUT);
digitalWrite(7,HIGH);
lcd.begin(16,2);
lcd.print(“WELCOME”);
delay(1000);
lcd.clear();
Serial.begin(9600);
lcd.print(“PORT OPENED”);
delay(1000);
lcd.clear();
lcd.print(“Connecting…”);
delay(1000);

begin:
Serial.println(“AT”); // Checking GSM modem connected to Arduino or not
if(!Serial.available())
goto begin;

lcd.clear();
lcd.print(“GSM CONNECTED”);
delay(1000);
lcd.clear();
lcd.print(“Text Format”);
delay(1000);
Serial.println(“AT+CMGF=1″); // Setting our GSM modem in Text Format
while(!Serial.available());

lcd.clear();
lcd.print(“Format Entered”);
delay(1000);
Serial.print(“AT+CMGS=”); // Sending message
Serial.print(‘”‘);
Serial.print(mob1);
Serial.println(‘”‘);
Serial.print(“WELCOME”);
Serial.write(0x1A);

}
void loop()
{
i=0;
m=0;
count=0;
xx:
lcd.clear();
lcd.print(Serial.available());
temp=Serial.read();
delay(1000);
if(Serial.available())
goto xx;

lcd.clear();
lcd.print(“Waiting…”);
while(!Serial.available()); // Waiting for a new message that to read

while(Serial.available())
{
a[i]=Serial.read();
lcd.print(a[i]);
delay(1000); // Storing the entire message format
lcd.clear();
i++;
}
a[i]=”;

lcd.clear();
lcd.print(“String End”);
delay(1000);
lcd.clear();

for(k=0;a[k]!=”;k++) // Extracting message and mobile num


{
if(count==2)
{
lcd.print(a[k]);
msg[m]=a[k];
m++;
}

if(a[k]==’\n’)
{
count++;
}

lcd.clear();
m=m-2;
msg[m]=”;
lcd.print(msg);
delay(1000);
lcd.clear();

if(!strcmp(msg,msg1)) // Doing manipulation based on the msg received.


{
digitalWrite(7,LOW);
Serial.print(“AT+CMGS=”);
Serial.print(‘”‘);
Serial.print(mob1);
Serial.println(‘”‘);
Serial.print(“LOAD1 ON”);
Serial.write(0x1A);

lcd.print(“LOAD1 ON”);
delay(1000);
lcd.clear();
}

else if(!strcmp(msg,msg2))
{
digitalWrite(7,HIGH);
Serial.print(“AT+CMGS=”);
Serial.print(‘”‘);
Serial.print(mob1);
Serial.println(‘”‘);
Serial.print(“LOAD1 OFF”);
Serial.write(0x1A);

lcd.print(“LOAD1 OFF”);
delay(1000);
lcd.clear();
}

else if(!strcmp(msg,msg3))
{
Serial.print(“AT+CMGS=”);
Serial.print(‘”‘);
Serial.print(mob1);
Serial.println(‘”‘);
Serial.print(“CONSUMPTION per Day: 0.4KWH”);
Serial.write(0x1A);

lcd.print(“QUERY”);
delay(1000);
lcd.clear();
}

delay(1000);
}

You might also like