Skip to content

Instantly share code, notes, and snippets.

@salmanfarisvp
Created November 21, 2019 08:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save salmanfarisvp/5547bc028bb96751f16a2a0f7f231ffb to your computer and use it in GitHub Desktop.
Save salmanfarisvp/5547bc028bb96751f16a2a0f7f231ffb to your computer and use it in GitHub Desktop.
Read SMS using SIM800L and Print the message content in I2C LCD Display .
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
String Grsp;
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
lcd.begin();
lcd.setCursor(0, 0);
lcd.print("Data");
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while (mySerial.available())
{
//Serial.write(mySerial.read());
String sms = mySerial.readString();
Serial.println(sms);
int index = sms.indexOf(';');
String message = sms.substring(index);
Serial.println("Message is :" + message );
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Data");
lcd.setCursor(0, 1);
lcd.print(message);
}
}
@amin-k2001
Copy link

hi . the code does not work for me . it always shows : massage is : . and nothing print for massage . what should i do to detect the recieved massage ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment