#include <SoftwareSerial.h> //Include the NewSoftSerial library to send serial commands to the cellular module.
char inchar; //Will hold the incoming character from the Serial Port.
SoftwareSerial cell(2,3); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
int led1 = 11;
int led2 = 12;
int led3 = 13;
void setup()
{ // prepare the digital output pins
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//Initialize GSM module serial port for communication.
Serial.begin(9600);
delay(3000); // give time for GSM module to register on network etc.
Serial.println("AT+CMGF=1"); // set SMS mode to text
delay(200);
Serial.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt
delay(200);
}
void loop()
{ //If a character comes in from the cellular module...
if(Serial.available() >0)
{
inchar=Serial.read();
if (inchar=='#') // OK - the start of our command
{
delay(10);
inchar=Serial.read();
if (inchar=='a')
{
delay(10);
inchar=Serial.read();
if (inchar=='0')
{
digitalWrite(led1, LOW);
}
else if (inchar=='1')
{
digitalWrite(led1, HIGH);
}
delay(10);
inchar=Serial.read();
if (inchar=='b')
{
inchar=Serial.read();
if (inchar=='0')
{
digitalWrite(led2, LOW);
}
else if (inchar=='1')
{
digitalWrite(led2, HIGH);
}
delay(10);
inchar=Serial.read();
if (inchar=='c')
{
inchar=Serial.read();
if (inchar=='0')
{
digitalWrite(led3, LOW);
}
else if (inchar=='1')
{
digitalWrite(led3, HIGH);
}
delay(10);
}
}
Serial.println("AT+CMGD=1,4"); // delete all SMS
}
}
}
}
You have a sketch that includes statements to turn the LEDs on and off. Does it compile? Does it do what you want? If not, what do you want it to do, what does it actually do, and what circuits do you have connected to it?
j have arduino uno and sim900 modem, i need to turn on/off led using sms from mobile... this is the code i tried... but through sms is nt wrking... if we give code in serial monitor it works.... but not wrking in sms #a1b1c1 is the code to turn on the 3 led connected to pin 11,12,13.....
The program you have shown only does I/O on the hardware Serial port (ie the one connected to the USB). I do not see any calls to the softwareserial"cell" you have opened...?
Also look at Arduino - Home which shows a sort of "echo" between the hardware port and the softwareserial - you should do something similar to see what you actually receive on the modem.
Lastly (in other words there is more than one error) whilst you wait correctly for the first character (Serial.available()>0) you simply assume the other 6 characters have arrived. They may or may not have arrived (I noticed the delay(10) - probably a workaround you found worked, sort of) . Either do a (Serial.available()>0) before each Serial.read OR do a (Serial.available()>=6) which means at least 6 characters have arrived.
You are sending your modem commands to the hardware serial port instead of the SoftwareSerial port 'cell' that you have created, which presumably is connected to the modem. You would presumably also need to read the responses from the cell SoftwareSerial port.