Last active
March 31, 2023 06:03
-
-
Save heyitsnovi/b1e6985e2d4cf6ac6dea49d1a9e84ed1 to your computer and use it in GitHub Desktop.
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> | |
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