SIM800L Not Sending Messages/Not Calling

I'm coding some sort of mini flood detection device. The sensors are working properly but the SIM800L.

Here is my code:

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial sim800l(rxPin, txPin);

String _buffer;
const String phone_num = "09XXXXXXXXX";

#define sensorPower 7
#define sensorPin A0

// LED
#define greenLed 4
#define yellowLed 5
#define redLed 6

// BULB
#define bulb 8

// BUZZER
#define buzzer 10

// READING WATER LEVEL
int level = 0;

int _timeout;

void setup() {
	pinMode(sensorPower, OUTPUT);
	digitalWrite(sensorPower, LOW);
	
  pinMode(greenLed, OUTPUT);
	digitalWrite(greenLed, LOW);
  pinMode(yellowLed, OUTPUT);
	digitalWrite(yellowLed, LOW);
  pinMode(redLed, OUTPUT);
	digitalWrite(redLed, LOW);

  pinMode(buzzer, OUTPUT);
	digitalWrite(buzzer, LOW);

  pinMode(bulb, OUTPUT);
	digitalWrite(bulb, LOW);

  sim800l.begin(9600);

	Serial.begin(9600);
}

void loop() {
	int level = readSensor();

  Serial.print("Water Level: ");
	Serial.println(level);
	
  if (level < 100) {                                // GREEN LED
    digitalWrite(greenLed, HIGH);
    digitalWrite(yellowLed, LOW);
    digitalWrite(redLed, LOW);
    digitalWrite(bulb, HIGH);
    digitalWrite(buzzer, LOW);
  } else if (level >= 100 && level < 150) {         // YELLOW LED + BUZZER
    digitalWrite(greenLed, LOW);
    digitalWrite(yellowLed, HIGH);
    digitalWrite(redLed, LOW);
    digitalWrite(bulb, HIGH);
    digitalWrite(buzzer, HIGH);

    Alert();

    delay(9600);
  } else if (level >= 150) {                        // RED LED + BUZZER
    digitalWrite(greenLed, LOW);
    digitalWrite(yellowLed, LOW);
    digitalWrite(redLed, HIGH);
    digitalWrite(bulb, HIGH);
    digitalWrite(buzzer, HIGH);

    Warning();
    delay(9600);
    callNumber();
    delay(10000);

    digitalWrite(greenLed, LOW);
    digitalWrite(yellowLed, LOW);
    digitalWrite(redLed, LOW);
    digitalWrite(bulb, LOW);
    digitalWrite(buzzer, LOW);

    //exit(0);
  }

	delay(1000);
}

int readSensor() {
	digitalWrite(sensorPower, HIGH);
	delay(10);
	level = analogRead(sensorPin);
	digitalWrite(sensorPower, LOW);
	return level;
}

void Alert() {
  Serial.println("Sending SMS.");
  sim800l.print("AT+CMGF=1");                   // SMS Mode
  delay(1000);
  sim800l.print("AT+CMGS=\"+639XXXXXXXXX\"");
  /*delay(3000);
  sim800l.print("SIM800l is working");
  delay(5000);*/
  sim800l.print((char)26);
  delay(500);
  sim800l.println();
  Serial.println("Message Sent.");
  delay(1000);
}

void Warning() {
  Serial.println("Sending SMS.");
  sim800l.print("AT+CMGF=1");                   // SMS Mode
  delay(1000);
  sim800l.print("AT+CMGS=\"+639XXXXXXXXX\"");
  /*delay(3000);
  sim800l.print("SIM800l is working");
  delay(5000);*/
  sim800l.print((char)26);
  delay(500);
  sim800l.println();
  Serial.println("Message Sent.");
  delay(1000);
}

String _readSerial() {
  _timeout = 0;
  while (!sim800l.available() && _timeout < 12000) {
    delay(13);
    _timeout++;
  } if (sim800l.available()) {
    return sim800l.readString();
  }
}

void callNumber() {
  sim800l.print(F("ATD"));
  sim800l.print(phone_num);
  sim800l.print(F(";\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}

It's printing "Message Sent." in the serial monitor but the phone number is not receiving messages/calls even though I just sent load to the sim card inside the SIM800L.

Please help. Thank you!

Why did you start a topic in the Uncategorised category of the forum when its description is

:warning: DO NOT CREATE TOPICS IN THIS CATEGORY :warning:

Your topic has been moved to the appropriate category

You're making the classic mistake of just using "blind" delays after each AT command.

That's like trying to drive blindfold down a busy street, relying only on delays for when to turn the wheel!

You need to wait for the response from each AT command, and verify that it's a "success" response, before proceeding to the next command.

Also, before doing this in the Arduino, do it manually in a terminal - to verify that you have the correct command sequence, you are actually getting network service, the responses to expect, etc, etc, ... Use AT+CMEE=1 to enable error messages

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.