gsm - How to read an SMS from Arduino and get LED to switch on or off -


#include <softwareserial.h> char inchar; //will hold incoming character serial port. softwareserial cell(2,3); //create 'fake' serial port. pin 2 rx pin, pin 3 tx pin.   int led1 = a2;   void setup()  {      // prepare digital output pins      pinmode(led1, output);      digitalwrite(led1, high);       //initialize gsm module serial port communication.      cell.begin(19200);      delay(30000); // give time gsm module register on network, etc.      cell.println("at+cmgf=1"); // set sms mode text      delay(200);      cell.println("at+cnmi=3,3,0,0"); // set module send sms data serial out upon receipt       delay(200);  }   void loop()   {      //if character comes in cellular module...      if(cell.available() >0)      {          delay(10);          inchar=cell.read();           if (inchar=='a')          {              delay(10);              inchar=cell.read();              if (inchar=='0')              {                  digitalwrite(led1, low);              }               else if (inchar=='1')              {                  digitalwrite(led1, high);              }              delay(10);              delay(10);          }          cell.println("at+cmgd=1,4"); // delete sms      }  } 

this code receiving smses cellular network. using arduino gboard sim900. there no error in code, led on board doesn't switch on or off in response sms.

why?

you should first know response before attempting parse it.

try simple following code (note: untested!) feeling of should for:

void loop() {     if(cell.available() > 0) {         char ch = cell.read();         serial.print(ch);     } } 

my guess you'll see more '0' or '1' :)


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -