MakerGram Logo

    MakerGram

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Users
    • Groups

    SIM800L is not working after disconnecting with PC

    Arduino
    2
    17
    1966
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rafitc99
      rafitc99 last edited by

      I'm trying to send some and receive SMS using SIM800L. After checking using Arduino Serial monitor all worked well. But after connecting on a PerfBoard using ATMEGA328 and clock circuit. It not sending/ receiving SMS. But the same while connecting with PC and open serial monitor It's working properly. Why this is occurring?

      Some messages are sent But it was some blank messages.
      I'm powering SIM800L through DC-DC buck Convertors .So, no way to issues with power. Not adding my messy code Right Now. If you wanna look at code too for a solution. Let me know.
      Thanks in advance.

      salmanfaris 1 Reply Last reply Reply Quote 0
      • salmanfaris
        salmanfaris @rafitc99 last edited by

        @rafitc99 Can you share code and buck booster you are using?

        1 Reply Last reply Reply Quote 0
        • rafitc99
          rafitc99 last edited by rafitc99

          @salmanfaris
          I'm using LM2596 buck converter.

          Following this setup
          alt text

          salmanfaris 1 Reply Last reply Reply Quote 0
          • salmanfaris
            salmanfaris @rafitc99 last edited by

            @rafitc99 Can you share your code too!

            1 Reply Last reply Reply Quote 0
            • rafitc99
              rafitc99 last edited by rafitc99

              @salmanfaris
              This is my messy code.

              #include <SoftwareSerial.h>
              //#include <avr/wdt.h>
              
              //Create software serial object to communicate with SIM800L
              SoftwareSerial mySerial(9, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
              
              String content = "";
              int Pulses = 3; //connect water flow sensor
              volatile int pulsecount; //Variable to count number of pulses
              unsigned long curr, prev, interval = 5000;
              int led = 11;
              
              long count = 0;
              unsigned long onCall_prev_time, onCall_interval = 15000;
              unsigned long timer;
              bool ledFlag = 0;
              bool smsFlag = 0; // sms flag
              bool ackFlag = 0; //acknowledge flag
              bool ackFlag_1 = 0; //acknowledge flag
              bool recSmsFlag = 0; //Receive SmS flag
              int statusAck = 0;
              bool onCall_flag = 0; //to check call status
              int c = 0;
              bool terminate_flag = 0; //Flag to terminate whole event
              
              bool terminate_flag_1 = 0; //Flag to terminate whole event
              
              String number_1 = "YYxxxxxxxxxx";
                String number_2 = "YYxxxxxxxxxx";
                String number_3 = "YYxxxxxxxxxx";
                String number_4 = "YYxxxxxxxxxx";
                String test = "YYxxxxxxxxxx";
                String userName;
              
              void setup() {
                pinMode(led, OUTPUT);
                
                pinMode(Pulses, INPUT_PULLUP);
                attachInterrupt(digitalPinToInterrupt(Pulses), CountPulses, FALLING);
                //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
                Serial.begin(9600);
                //Begin serial communication with Arduino and SIM800L
                mySerial.begin(9600);
                Serial.println("Initializing...");
                delay(500);
                Serial.println("Watchdog Enabled ");
                mySerial.println("AT+IPR=9600");
                updateSerial();
                //wdt_enable(WDTO_8S);
              }
              
              void updateSerial()
              {
                //wdt_reset();
                detachInterrupt(CountPulses);
                delay(500);
                while (Serial.available())
                {
                  mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
                }
                while (mySerial.available())
                {
                  Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
                }
               
              }
              
              void recSerial()
              {
                String msg;
                detachInterrupt(CountPulses);
                delay(500);
                while (Serial.available())
                {
                  mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
                }
                while (mySerial.available())
                {
                  detachInterrupt(CountPulses);
                  msg = mySerial.readString();//Forward what Software Serial received to Serial Port
                  processMsg(msg);
                }
              }
              
              
              void loop() {
                //wdt_reset();
                Serial.println("Loop strated----++++---++");
                
                pulsecount = 0;  //Start counting from 0 again
                interrupts();    //Enables interrupt on arduino pin 3
                delay(1000);
                detachInterrupt(CountPulses);
                //Calculating the water flow rate in Milli Liters per minute
                long flowRate;
                flowRate = (pulsecount * 2.22 * 60);
                Serial.print("Flow rate=");
                Serial.print(flowRate);   //Print milli liters per minute on serial monitor
                Serial.println("mL/minute");
                recSerial();
                digitalWrite(led, ledFlag); //Set or reset led based on the flow
              
                if (ackFlag_1) {
                  Serial.println("Acknowledge Received-----------------------");
                  content = "ACK received from " + userName +" paused all notifications ";
                  smsSend_5(content);
                  ackFlag_1 = false;
                }
               
                if (terminate_flag_1) {
                  content = "GOT 'TERMINATE' From "+userName;
                  smsSend_5(content);
                  terminate_flag_1 = false;
                }
                
                if (onCall_flag) {
                  Serial.println(c++);
                  if (c >= 15) {
                    Serial.println("Calling Event Completed");
                    mySerial.println("ATH");
                    updateSerial();
                    onCall_flag = false;
                    c = 0;
                  }
                }
                if (statusAck) {
                  if (pulsecount != 0) {
                    smsSend_5("No problem. it's working perfectly!");
                    statusAck = 0;
                  }
                  else if (pulsecount == 0) {
                    smsSend_5("It's Not working!!!!");
                    statusAck = 0;
                  }
                }
              
                if (!recSmsFlag) {
                  Serial.println("Setting into Receive Mode");
                  recMode();
                  recSmsFlag = true;
                }
              
                if (flowRate > 1) {
                  Serial.println("Reseted all countors for new event ---++");
                  count = 0; //Reset countor
                  prev = 0; //reset timer;
                  ackFlag = false; //reset ACK flags
                  smsFlag = false; //Sent sms flag
                  terminate_flag = false; //Reset Terminate flag
                  ledFlag = 1; //Set LED Flag
                }
              
                if (flowRate == 0.00) {
                  curr = millis();
                  Serial.println("flowrate is Zero!!");
                  ledFlag = 0; //Reset flag
                  //wdt_reset();
                  Serial.println("Reseted Watchdog");
                  
                  if (curr - prev >= 1000) {
                    prev = curr;
                    Serial.print(count++);
                    Serial.println(" Seconds");
              
                    if (count == 30 && ackFlag == 0) {
                      Serial.println("ALERT 1 - FLow not working for 30 Seconds");
                      //ackFlag = 0;
                      smsSend_5("Flow is Zero about 30 Seconds!!!");
                      smsFlag = true; //set sms flag
                      //Send To other number too!
                      //wdt_reset();
                      Serial.println("Reseted Watchdog");
                      //Send SMS
                      
                    }
                    
                    if (count == 40 && ackFlag == 0) {
                      Serial.println("ALERT 1 - FLow not working for 40 Seconds");
                      //ackFlag = 0;
                      //smsSend_5("Flow is Zero about 40 Seconds!!!");
                      smsFlag = true; //set sms flag
                      //Send To other number too!
                      //wdt_reset();
                      makeCall(test);
                      onCall_flag = 1;
                      Serial.println("Reseted Watchdog");
                      //Send SMS
                    }
                    if (count == 50 && ackFlag == 0) {
                      Serial.println("ALERT 1 - FLow not working for 50 Seconds");
                      //ackFlag = 0;
                      smsSend_5("Flow is Zero about 30 Seconds!!!");
                      smsFlag = true; //set sms flag
                      //Send To other number too!
                      //wdt_reset();
                      Serial.println("Reseted Watchdog");
                      //Send SMS
                    }
                    if (count == 60 && ackFlag == 0) {
                      Serial.println("ALERT 1 - FLow not working for 60 Seconds");
                      //ackFlag = 0;
                      smsSend_5("Flow is Zero about 30 Seconds!!!");
                      smsFlag = true; //set sms flag
                      //Send To other number too!
                      //wdt_reset();
                      Serial.println("Reseted Watchdog");
                      //Send SMS
                    }
                    if (count == 90 && ackFlag == 0) {
                      Serial.println("Not working for 1.5 minutes");
                      makeCall(test);
              
                      //smsSend();
                      //SmS
                      //wdt_reset();
                      Serial.println("Reseted Watchdog");
                    }
                    if (count == 150 && ackFlag == 0) {
                      Serial.println("Not working for 2.5 minutes");
                      //        makeCall(test); //make call to Number 2
                      smsSend_5("Flow is Zero about 2.5 Minutes!!!");
                      //smsSend(number_2,"Flow is Zero about 2.5 Minutes!!!");
                      //smsSend(number_3,"Flow is Zero about 2.5 Minutes!!!");
                      //smsSend(number_4,"Flow is Zero about 2.5 Minutes!!!");
                      //SmS
                      //wdt_reset();
                      Serial.println("Reseted Watchdog");
                    }
                    if (count == 210 && ackFlag == 0) {
                      Serial.println("Not working for 3.5 minutes");
                      smsSend_5("Flow is Zero about 3.5 Minutes!!!");
              //        makeCall(number_1); //make call to Number 3
                      //smsSend();
                      //wdt_reset();
                      Serial.println("Reseted Watchdog");
                      //SmS
                    }
                    if (count == 270 && ackFlag == 0) {
                      Serial.println("Not working for 4.5 minutes");
                      smsSend_5("Flow is Zero about 4.5 Minutes!!!");
                      //        makeCall(number_2); //make call to Number 4
                      //smsSend();
                      //SmS
                    }
                    if (count == 180 && terminate_flag == 0) {
                      Serial.println("just a reminder");
                      smsSend_5("Blower is not working more than 8 minutes");
                     // smsSend_5("It's been 8+ Minutes Your blower is not working.");
                      //smsSend(number_3,"It's been 8+ Minutes Your blower is not working. Hope Now, You are working on that ;)");
                      //smsSend(number_4,"It's been 8+ Minutes Your blower is not working. Hope Now, You are working on that ;)");
                    }
                    if (count >= 600 && terminate_flag == 0) {
                      Serial.println("DANGER!!!");
                      smsSend_5("DANGER!! Flow is Not working more than 10 Minutes!!!");
                      count = 0;
                      ///SmS
                    }
                  }
                }
              } 
              
              void CountPulses()
              {
                pulsecount++; //Increment the variable on every pulse
              }
              void recMode(){
                Serial.println("Setting Recieve mode");
                mySerial.println("AT");
                updateSerial();
                mySerial.println("AT+CMGF=1");
                updateSerial();
                mySerial.println("AT+CNMI=1,2,0,0,0");
                updateSerial();
              }
              
              void smsSend_1(String content) {
                
                detachInterrupt(CountPulses);
                Serial.println("SMS sending");
                mySerial.println("AT");
                updateSerial();
                mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                updateSerial();
                mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                updateSerial();
                mySerial.print(content); //text content
                updateSerial();
                mySerial.write(26);
                Serial.println("sent!!");
                recSmsFlag = false; //Reset Rec SMS flag
              }
              
              void smsSend_2(String content) {
                //wdt_reset();
                detachInterrupt(CountPulses);
                Serial.println("SMS sending");
                mySerial.println("AT");
                updateSerial();
                mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                updateSerial();
                mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                updateSerial();
                mySerial.print(content); //text content
                updateSerial();
                mySerial.write(26);
                Serial.println("sent!!");
                recSmsFlag = false; //Reset Rec SMS flag
              }
              
              
              void smsSend_3(String content) {
                
                detachInterrupt(CountPulses);
                Serial.println("SMS sending");
                mySerial.println("AT");
                updateSerial();
                mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                updateSerial();
                mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                updateSerial();
                mySerial.print(content); //text content
                updateSerial();
                mySerial.write(26);
                Serial.println("sent!!");
                recSmsFlag = false; //Reset Rec SMS flag
              }
              
              
              void smsSend_4(String content) {
                detachInterrupt(CountPulses);
                Serial.println("SMS sending");
                mySerial.println("AT");
                updateSerial();
                mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                updateSerial();
                mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                updateSerial();
                mySerial.print(content); //text content
                updateSerial();
                mySerial.write(26);
                Serial.println("sent!!");
                recSmsFlag = false; //Reset Rec SMS flag
              }
              
              
              void smsSend_5(String content) {
              
                detachInterrupt(CountPulses);
                Serial.println("SMS sending");
                mySerial.println("AT");
                updateSerial();
                mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                updateSerial();
                mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                updateSerial();
                mySerial.print(content); //text content
                updateSerial();
                mySerial.write(26);
                Serial.println("sent!!");
                recSmsFlag = false; //Reset Rec SMS flag
                
              }
              void makeCall(String number1) {
                
                detachInterrupt(CountPulses);
                recSmsFlag = 0; //Reset Rec SMS flag
                mySerial.print (F("ATD"));
                mySerial.print (number1);
                mySerial.print (F(";\r\n"));
                updateSerial();
                onCall_prev_time = millis();
                Serial.print("----Calling to ");
                Serial.println(number1);
                onCall_flag = true;
                //delay(15000);
              
              }
              String getName(String nameOfuser) {
                String user;
                detachInterrupt(CountPulses);
                Serial.print("Get Name is Running ----------");
              
                  if(nameOfuser.indexOf(number_1)>0){
                  user = "Rashad"; //name of first user
                  return user;
                  }
                  else if(nameOfuser.indexOf(number_2)>0){
                  user = "Hashim"; //name of second user
                  return user;
                  }
                  else if(nameOfuser.indexOf(number_3)>0){
                  user = "Rasil"; //name of third user
                  return user;
                  }
                  else if(nameOfuser.indexOf(number_4)>0){
                  user = "Anas"; //name of fourth user
                  return user;
                  }
                  else if(nameOfuser.indexOf(test)>0){
                  user="Rafi";
                  return user;
                  }
                  else{
                    user = "Unknown";
                    return user;
                  }
              }
              void processMsg(String msg){
                Serial.print(msg);
                detachInterrupt(CountPulses);
                Serial.println("process started!!!!!----------");
                digitalWrite(11,1);
                delay(500);
                digitalWrite(11,0);
                if ((msg.indexOf("Stop")>0)) {
                    Serial.print("Got ACK from------ ");
                    //wdt_reset();
                    Serial.println("Reseted Watchdog");
                    userName = getName(msg);
                    ackFlag_1 = 1;
                    ackFlag = 1;
                  }
                  else if ((msg.indexOf("Check")>0)) {
              //      detachInterrupt(CountPulses);
                    Serial.println("Status Test MSG Received --------");
                    userName = getName(msg);
                    statusAck = 1;
                  }
                  else if ((msg.indexOf("Terminate") > 0)) {
              //      detachInterrupt(CountPulses);
                    userName = getName(msg);
                    Serial.print("Terminated all notification until next event by ");
                    //Serial.println(userName);
                    // wdt_reset();
                    Serial.println("Reseted Watchdog");  
                    terminate_flag_1 = 1;
                    terminate_flag = 1;
                 }
                 else{
                  Serial.println("Not a admin commend ");
                 }
              }
              
              salmanfaris 1 Reply Last reply Reply Quote 1
              • salmanfaris
                salmanfaris @rafitc99 last edited by

                Hi @rafitc99, May I know why you are using this same function definition with different function name?

                void smsSend_1(String content) {
                
                  detachInterrupt(CountPulses);
                  Serial.println("SMS sending");
                  mySerial.println("AT");
                  updateSerial();
                  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                  updateSerial();
                  mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                  updateSerial();
                  mySerial.print(content); //text content
                  updateSerial();
                  mySerial.write(26);
                  Serial.println("sent!!");
                  recSmsFlag = false; //Reset Rec SMS flag
                }
                
                void smsSend_2(String content) {
                  //wdt_reset();
                  detachInterrupt(CountPulses);
                  Serial.println("SMS sending");
                  mySerial.println("AT");
                  updateSerial();
                  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                  updateSerial();
                  mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                  updateSerial();
                  mySerial.print(content); //text content
                  updateSerial();
                  mySerial.write(26);
                  Serial.println("sent!!");
                  recSmsFlag = false; //Reset Rec SMS flag
                }
                
                void smsSend_3(String content) {
                
                  detachInterrupt(CountPulses);
                  Serial.println("SMS sending");
                  mySerial.println("AT");
                  updateSerial();
                  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                  updateSerial();
                  mySerial.println("AT+CMGS=\"+ YYxxxxxxxxxx\"");//("AT+CMGS=\"" +number+ "\""); //change ZZ with country code and xxxxxxxxxxx with phone number to sms
                  updateSerial();
                  mySerial.print(content); //text content
                  updateSerial();
                  mySerial.write(26);
                  Serial.println("sent!!");
                  recSmsFlag = false; //Reset Rec SMS flag
                }
                
                rafitc99 1 Reply Last reply Reply Quote 1
                • rafitc99
                  rafitc99 @salmanfaris last edited by

                  @salmanfaris
                  Sorry, leave that part
                  Actually I was using ("AT+CMGS=\"" +number+ "\""); this part and passing number into the funciton. This different functions all are done part of debugging.😀 just checking Is there any problem in string handling.

                  salmanfaris 1 Reply Last reply Reply Quote 1
                  • salmanfaris
                    salmanfaris @rafitc99 last edited by salmanfaris

                    @rafitc99 Ok, are you connecting all the ground as common in the circuit when using the LM2596 buck converter to power up the module/Arduino? and check the resistor that you are using stepdown Tx signal from Arduino to the SIM800L.!

                    rafitc99 1 Reply Last reply Reply Quote 1
                    • rafitc99
                      rafitc99 @salmanfaris last edited by

                      @salmanfaris Yes. I'm providing common ground. Resistors also working.

                      salmanfaris 1 Reply Last reply Reply Quote 0
                      • salmanfaris
                        salmanfaris @rafitc99 last edited by

                        @rafitc99 Great, can you try this simple code that only includes the SMS sending part! if it's working fine with and without the computer connection we can look it to the other parts!

                        #include <SoftwareSerial.h>
                        
                        //Create software serial object to communicate with SIM800L
                        SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
                        
                        void setup()
                        {
                          //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
                          Serial.begin(9600);
                        
                          //Begin serial communication with Arduino and SIM800L
                          mySerial.begin(9600);
                        
                          Serial.println("Initializing...");
                          delay(1000);
                        
                        
                        }
                        
                        void loop()
                        {
                        
                          mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
                          mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
                          mySerial.println("AT+CMGS=\"+ZZxxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
                          mySerial.print("SMS Test "); //text content
                          updateSerial();
                          mySerial.write(26);
                        
                          delay(7000);
                        
                        }
                        
                        rafitc99 1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Recent Posts

                        • @codelery Awesome. That's great news. Kudos to @rafitc99 . 🙌

                          @codelery Please keep us updated about your project, looking forward to seeing it in action 🤩

                          • read more
                        • C

                          @rafitc99 I changed the buffer and that solved the problem. Thanks a lot for coming to my rescue.

                          • read more
                        • C

                          @salmanfaris I did change the buffer size and everything is working perfectly. Thanks coming to my rescue.

                          • read more
                        • @codelery said in Help needed: Arduino Wireless Notice Board project:

                          I am using the hardware serial (pin 0 and 1 on Arduino Uno)

                          As @rafitc99 mentioned, you need to expand the Serila buffer, in the hardware serial also the Arduino board package implements a 64-byte ring buffer for send and receive on the hardware serial messages. So you need to change that to 256 as per your message length.

                          • read more
                        • C

                          @rafitc99 The thing is that I am not using the SoftwareSerial library in receiving the message from the first microcontroller. I am using the hardware serial (pin 0 and 1 on Arduino Uno)

                          • read more
                        By MakerGram | A XiStart Initiative | Built with ♥ NodeBB
                        Copyright © 2023 MakerGram, All rights reserved.
                        Privacy Policy | Terms & Conditions | Disclaimer | Code of Conduct