Hello,
I have a project with Arduino and a GPRS module Libelium and I must receive an SMS and an LED light. For example I send "1" and turn the first LED, or "2" and the second LED light ...
I have this program that should work but it does not work?
If anyone has an idea?
#include "Wire.h"
#include <WString.h>
int led = 13;
int onModulePin = 2;
int error=0;
String inString = String(50);
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void getSerialChars(){
while(Serial.available()>0){
char inchar = Serial.read();
if (inString.length() < 50) {
inString.append(inchar);
}
}
}
int smsCommand() {
int retval=0;
delay(1500);
Serial.print("AT+CMGL=");
Serial.print(34,BYTE);
Serial.print("REC UNREAD");
Serial.println(34,BYTE);
delay(3000);
if (Serial.available() > 0) {
inString = "";
delay(500);
getSerialChars();
if (inString.contains("1")) return 1;
}
return 0;
}
void setup(){
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
Serial.begin(115200);
switchModule();
delay(10000);
Serial.println("AT+CMGF=1");
}
void turnLEDon() {
digitalWrite(led,HIGH);
}
void loop(){
switch(smsCommand()){
case 1:
turnLEDon();
error=0;
break;
}
}
Thank you!