Skip to content

Instantly share code, notes, and snippets.

@heyitsnovi
Last active March 31, 2023 06:03
Show Gist options
  • Save heyitsnovi/b1e6985e2d4cf6ac6dea49d1a9e84ed1 to your computer and use it in GitHub Desktop.
Save heyitsnovi/b1e6985e2d4cf6ac6dea49d1a9e84ed1 to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
SoftwareSerial sim(10, 11);
void setup() {
Serial.begin(9600);
Serial.println("System Starting...");
sim.begin(9600);
delay(1000);
Serial.println("Initializing SIM800L Module...");
delay(1500);
listenIncomingMessage();
}
void loop() {
if (Serial.available() > 0){
Serial.read();
}
if (sim.available() > 0){
String sms = sim.readString();
String sender_number = sms.substring(9,22);
String message_content = sms.substring(49,sms.length());
Serial.write(sim.read());
if(sms.indexOf("+CMT") > 0){
Serial.print("\n \n" + message_content);
}
}
}
void listenIncomingMessage()
{
Serial.println ("Wating For New Messages....");
sim.println("AT+CMGF=1");
delay (200);
sim.println("AT+CNMI=1,2,0,0,0");
delay(200);
Serial.write (".....");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment