SIM900 not working with Arduino

619 views Asked by At

Recently I bought a SIM900A module and an Arduino Mega 2560 to run my old code for sending SMS and call, but now there is a problem as I am unable to send SMS or call. My code is attached below.

#include <SoftwareSerial.h>

SoftwareSerial gsm(2, 3);

void setup() {
  gsm.begin(9600); // Setting the baud rate of GSM Module
  Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}

void loop() {
  if (Serial.available() > 0)
    switch (Serial.read()) {
      case 's':
        Send();
        break;
      case 'r':
        Receive();
        break;
      case 'S':
        Send();
        break;
      case 'R':
        Receive();
        break;
    }
  if (gsm.available() > 0)
    Serial.write(gsm.read());
}

void Send() {
  Serial.print("Sending");
  gsm.println("AT+CMGF=1");
  delay(1000);
  gsm.println("AT+CMGS=\"+xxxxxxxxxxxx\"\r"); // Replace x with mobile number
  delay(1000);
  gsm.println("Hello I am GSM modem!!!");// The SMS text you want to send
  delay(100);
  gsm.println((char)26); // ASCII code of CTRL+Z
  delay(1000);
}

void Receive() {
  Serial.print("Receiving");
  gsm.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
}
0

There are 0 answers