Hello! I am currently using Arduino Uno and a compatible GSM Shield. I am trying to receive an SMS with some characters("#ok" in my code), analyze these characters, and if they match with what Arduino is expecting(#ok), Arduino must control the state of a digital port and send an SMS to a defined number.
Please someone can help me? I am getting nowhere... :(
Here is my code.
#include
SoftwareSerial SIM900(7, 8);
int checkPin = 10;
char inchar;
bool check1=LOW;
bool input;
void setup()
{
pinMode(checkPin,INPUT);
SIM900.begin(19200);
delay(7000);
SIM900.print("AT+CMGF=1\r");
delay(100);
}
bool receiveSMS(){
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
if(SIM900.available()>0){
inchar=SIM900.read();
if(inchar=='#'){
delay(10);
inchar=SIM900.read();
if(inchar=='o'){
delay(10);
inchar=SIM900.read();
if(inchar=='k'){
return true;
}
}
SIM900.println("AT+CMGD=1,4");
}else{
return false;
}
}
}
void sendSMS()
{
SIM900.println("AT + CMGS = \"+393272275551\"");
delay(100);
check1 = check();
if(check1==true){
SIM900.println("Button pressed!");
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(5000);
}else{
SIM900.println("Button not pressed!");
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(5000);
}
}
bool check(){
if(digitalRead(checkPin)==HIGH){
return true;
}else{
return false;}
}
void loop()
{
input = receiveSMS();
if(input == true){
sendSMS();
}
do {} while (1);
}