Thursday, November 10, 2011

How to Turn On SIM900 with arduino.

We were getting some strange behavior out of the SIM900 module.
Some times the module was working ok, and others not so ok. :)

The main problem was in turning on method of the SIM900.

The solution:
Turn off and Then Turn on the SIM900.

The arduino code with the NewSoftSerial:


#define GSM_ON_PIN 8


int AvrHardwareHelper::TurnOffGsm()
{

mySerial.println("AT+CPOWD=1");

delay(3000);
digitalWrite(GSM_ON_PIN, LOW);
delay(2000);
digitalWrite(GSM_ON_PIN, HIGH);
delay(2500);

return atCommandResult;
}

int AvrHardwareHelper::TurnOnGsm(char* pin, int pinSize)
{
mySerial.println("AT+CFUN=1");
delay(600);
mySerial.flush();
mySerial.println("AT");
delay(600);

int numberOfBytesRead = 0;
while((mySerial.read()) > 0)
{
numberOfBytesRead++;
}

if(numberOfBytesRead==0)
{
digitalWrite(GSM_ON_PIN, HIGH);
delay(1200);
digitalWrite(GSM_ON_PIN, LOW);
delay(2500);
}

mySerial.flush();
delay(2000);

.... Do the rest here, at+cpin, etc....
}




pinMode(GSM_ON_PIN, OUTPUT); // sets pin 5 as output
mySerial.begin(9600);
TurnOffGsm();
TurnOnGsm("1234", 4);


This is the main difference with all the samples on the web.
If someone is searching for more info, please just leave a comment.