1

Dear friends I have written a code to identify the caller and send a reply SMS to them using sim 800L and pro mini. My program is to identifying the caller number but continuously sending the SMS in an infinite loop. I am not getting what is the reason, kindly help me, thanks in advance. Code is attached

#include <SoftwareSerial.h>
SoftwareSerial Serial1(4,3); 
String a;
String CellNumtemp;
String CellNum;

void setup() { Serial.begin(9600); Serial1.begin(9600); Serial1.println("AT"); delay(1000); Serial1.println("AT+CSMP=17,167,0,0"); delay(1000); Serial1.println("AT+CLIP=1"); delay(1000); }

void loop(){ if (Serial1.available() > 0){ String a = Serial1.readString(); String CellNumtemp = a.substring(a.indexOf("+91")); CellNum = CellNumtemp.substring(0,13); Serial1.println("ATH"); delay(500); Serial.println(CellNum); delay(500); if (a.indexOf("+91") >= 0){ sendSMS(); } } CellNum = "\0"; }

void sendSMS(){ // Function that sends SMS Serial1.println("AT+CMGF=1\r"); delay(1000); Serial1.print("AT+CMGS="); Serial1.print("&quot;"); Serial1.print(CellNum); Serial1.print("&quot;"); Serial1.println("\r"); // to send SMS delay(1000); Serial1.println("Happy to see your call. I am good"); delay(1000); Serial1.println((char)26); delay(1000); Serial1.println(); delay(5000); Serial1.flush(); delay(2000); }

  • what do you see in the serial monitor? ... use more Serial.println` statements to debug the code ... display the value of variables to see if the values are what you expect – jsotola Mar 12 '21 at 15:50

0 Answers0