Read SMS

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!

I have this program that should work but it does not work?

Is that a question or a statement?

If it is a statement, you need to explain what you expect to have happen, and what actually happens.

A link to the module and a description about how you have the module connected would be useful, too. Are there any lights on the module that indicate that it is working? When it sends data? When it receives data? Is the module's ground connected to the Arduino ground?

Which model Arduino are you using? Does it's voltage match that of the module?