I am struggling with getting a task done. I have a sim800L module hooked up to an arduino nano. I want to be able to turn on and off a relay when a text is received by the module, but I also want it be happen when I text either "start" or "stop" to the module.
I ran my code using the serial monitor for testing, and it works. The issue is that when I receive a text it comes along with a lot of other information I dont need, and I dont know how to filter it out.
ex) +CMT: "+1xxxxxxxxx","","21/01/04,00:03:17-20"
start
Can anyone help me, like i said I need the words "start" and "stop" to use as my triggers
just focus on the Loop, not the rest of the stuff
#include <SoftwareSerial.h>
SoftwareSerial sim(2,3); // RX, TX
byte outputPin= 5;
byte triggerDelay=2000;
char c;
String readstring="";
void setup() {
Serial.begin(9600); //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
sim.begin(9600); //Begin serial communication with Arduino and SIM800L
Serial.println("Initializing...");
delay(1000);
sim.println("AT"); //Assuring Communication is Succesful
//updateSerial();
sim.println("AT+CMGF=1"); // Configuring TEXT mode
//updateSerial();
//sim.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
//updateSerial();
Serial.println("Waiting for Messages...");
pinMode(outputPin, OUTPUT);
digitalWrite(outputPin, LOW);
}
void loop() {
while(sim.available()){
c=sim.read();
readstring+=c;
}
Serial.println(readstring);
if(readstring=="start"){
digitalWrite(outputPin, HIGH);
delay(triggerDelay);
digitalWrite(outputPin, LOW);
Serial.println("Message Received");
}
if(readstring=="stop"){
digitalWrite(outputPin, HIGH);
delay(triggerDelay);
digitalWrite(outputPin, LOW);
Serial.println("Message Received");
}
readstring="";
delay(500);
}
void updateSerial(){
delay(500);
while (Serial.available()){
sim.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(sim.available()){
Serial.write(sim.read());//Forward what Software Serial received to Serial Port
}
}