Hi I'm new to Arduino coding and I have a problem in my project that I don't know how to solve it
I want to receive an SMS and then save the text in a variable and check if it is equal to a string or not
if it is equal I want to send an SMS to my phone number
#include <SoftwareSerial.h> //include SoftwareSerial library for sim800l communication
SoftwareSerial sim800l(5, 4); //define sim800l communication pins
String receivedSMS; //variable to store received SMS
void setup() {
Serial.begin(9600); //initialize serial communication
sim800l.begin(9600); //initialize sim800l communication
delay(1000); //wait for sim800l to initialize
Serial.println("SIM800L initialized.");
sim800l.println("AT+CMGF=1"); //set sim800l to text mode
delay(1000);
sim800l.println("AT+CNMI=2,2,0,0,0"); //set sim800l to forward received SMS to serial
delay(1000);
Serial.println("Ready to receive SMS.");
}
void loop() {
if (sim800l.available()) { //check if sim800l has received SMS
receivedSMS = sim800l.readString(); //read received SMS and store in variable
receivedSMS.trim();
receivedSMS.toLowerCase();
Serial.println("Received SMS: " + receivedSMS); //print received SMS to serial monitor
if (receivedSMS == "direction") { //check if received SMS is "Direction"
sim800l.println("AT+CMGS=\"+989146764006\""); //replace +1234567890 with the number you want to send the custom text to
delay(1000);
sim800l.println("Custom text"); //replace "Custom text" with the text you want to send
delay(1000);
sim800l.write(26); //send Ctrl+Z to indicate end of message
delay(1000);
Serial.println("Custom text sent.");
}
else{
Serial.println("not match.");
}
}
}
The problem is that it always returns "not match.".