Go Down

Topic: GSM character only not word (Read 987 times) previous topic - next topic

vrooms23

I had try to put word 'Lamp on' and others in inchar each but not work, I realize that only one character each, correct? somehow need more word than one character other code?

Code: [Select]
  if(cell.available() >0)
  {
      delay(10);
    inchar=cell.read();
    if (inchar=='a')
    {

    }
       

davidgoth

Hi,

Can you copy all your sketch, please?.

vrooms23


Hi,

Can you copy all your sketch, please?.


Code: [Select]
#include <SoftwareSerial.h>
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 = 6;
int led2 = 10;
int led3 = 11;
int led4 = 12;

void setup()
{
  // prepare the digital output pins
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
  //Initialize GSM module serial port for communication.
  cell.begin(2400);
digitalWrite(led4, HIGH);
delay(15000); // give time for GSM module to register on network etc.
digitalWrite(led4, LOW);
  cell.println("AT+CMGF=1"); // set SMS mode to text
  delay(200);
  cell.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(cell.available() >0)
  {
    inchar=cell.read();
    if (inchar=='#')
    {
      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);
        inchar=cell.read();
        if (inchar=='b')
        {
          inchar=cell.read();
          if (inchar=='0')
          {
            digitalWrite(led2, LOW);
          }
          else if (inchar=='1')
          {
            digitalWrite(led2, HIGH);
          }
          delay(10);
          inchar=cell.read();
          if (inchar=='c')
          {
            inchar=cell.read();
            if (inchar=='0')
            {
              digitalWrite(led3, LOW);
            }
            else if (inchar=='1')
            {
              digitalWrite(led3, HIGH);
            }
            delay(10);
            inchar=cell.read();
            if (inchar=='d')
            {
              delay(10);
              inchar=cell.read();
              if (inchar=='0')
              {
                digitalWrite(led4, LOW);
              }
              else if (inchar=='1')
              {
                digitalWrite(led4, HIGH);
              }
              delay(10);
            }
          }
          cell.println("AT+CMGD=1,4"); // delete all SMS
        }
      }
    }
  }
}

Go Up