the sim900 sometimes operates well and then stops operating correctly.

#define sensorPin A0
int timesTosend=1;
int count=0;
char phone_no[] = "xxxxxxxxxx";  //phone number to alert

void setup()
{
//pinMode(sensorPin,INPUT);
Serial.begin(9600);  //Open Serial connection at baud 9600
delay(2000);
Serial.println("AT+CMGF=1"); //set GSM to text mode
delay(200);
}

void loop()
{
  int data = analogRead(sensorPin);
  if (data >= 200)
  {
while(count<timesTosend){


Serial.print("AT+CMGS=\"");
Serial.print(phone_no);
Serial.println("\"");

delay(1000);  // delay is must it waits for > symbol

Serial.print("CAUTION...FIRE ALARM !!!!!!!!!!");  //SMS body
Serial.write(0x1A);  // sends ctrl+z end of message
//Serial.write(0x0D);  // Carriage Return in Hex
//Serial.write(0x0A);  // Line feed in Hex

//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(5000);
count++;
}
}
}

use external power supply (1000mA minimum) and try simple code like this
Edit :and turned the sim900 module to the hardware serial

1 Like