-
-
Save heyitsnovi/73d3e133a5f2002c2e6cf47138efd498 to your computer and use it in GitHub Desktop.
Read SMS using SIM800L and Print the message content in I2C LCD Display .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment