GSM shield SMS receiving without Serial Monitor

Hello All,

I have a working code about SMS receiving. But it only works if I connect my Arduino Uno+GSM shield to my PC. If I power on the Arduino from a wall-wart (without plugging the USB into the PC) then the SMS receiving/reading does not work. The motion sensor (PIRpin) does not turn off based on the sent SMS. If I plug the USB cable into my PC then I am able to control the PIRpin with the SMS.

Here is my code from the loop:

void loop()
{
  
 if (started)
  {
    sms_position = sms.IsSMSPresent(SMS_UNREAD);
    if (sms_position)
    {
      Serial.print("SMS postion:");
      Serial.println(sms_position, DEC);
      sms.GetSMS(sms_position, phone_number, sms_text, 100);
      Serial.println(phone_number);
      Serial.println(sms_text);
      
      if(strcmp(sms_text,"on")==0) {         
        pinMode (pirPin, INPUT); //activate PIR sensor 
        delay(100);
      }

      if(strcmp(sms_text,"off")==0) {
        pinMode (pirPin, OUTPUT); //deactivate PIR sensor 
        delay(100);
      }
    }
  delay(2000);
}
}

Could you please help how I could solve this? How should I change the code? I'd like to control the PIRpin with a simple SMS while it is on a remote location.

Thank you in advance, Laszlo

You’ve already determined the code does what you want it to without changing anything other than the power source. Start exploring and understanding power supplies - as they relate to USB, the Arduino and the modem shield.

This may help https://forum.arduino.cc/index.php?topic=498224.0

Hi; I do not change the power supplies. I remain the wall warts plugged and if I simultanously plug the Usb then the Sms receiving works fine. But if only the jacks are plugged I cannot control the pirpin with the sms. I think this could be a programmng issue...but I might be wrong. It may be a business of the serial port/monitor. The sms can be read in the serial monitor and then it works well. Anyway for your info I use a 9V 0.6A to the arduino uno and a 12V 2A power supply into the Gsm shield.

Thanks for any help

I think this could be a programmng issue...but I might be wrong.

You are. Count on it.

The code has NO idea how you are powering the Arduino and GSM shield. What is DOES know is when the hardware is not working because you are not supplying enough current.

When connected to USB, there is enough current for the Arduino and power-hungry GSM shield. On the wall wart that you've told us nothing about, who knows?

Just to be sure... Is there a common 0V/Gnd connection between the power supplies, Arduino and shield?

Hi Guys,

I placed/plugged the GSM shield onto the top of the Arduino as a common connection. Please see the image. And then I plug each DC adapters into them.

I think that there is enough current. Now I share with you the entire code. It has a part when calling is initiated. And dialing is working if the devices are feeded with power supply voltages. And I think that the calls have higher current demand than SMS sending/receiving. So that is why I still think it is not a power issue…
Sorry I did not share my whole code with you and I apologise as there could be unnecessary code lines. Just ignore them.

Any help is appreciated.

#include <SoftwareSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
SoftwareSerial SIM900(7, 8);

#define ACTIVE LOW

int numdata;
int i;
char inchar;
char smsbuffer[160];
char n[20];
char sms_position;
char phone_number[20];
char sms_text[100];

int char_count;
const int ledPin =  13;      // the number of the LED pin
boolean started = false;
int pirPin = 3;    // the number of the pir pin
boolean calling = false;
String NumberToCall = "+3630xxxxxxxxxx"; //my phone number
String in_sms_text;
int calibrationTime = 20;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime; 

void setup()
{
  SIM900.begin(9600);  // for GSM shield
  gsm.begin(9600);        // for GSM shield    
  Serial.begin(9600); // for serial monitor
  delay(1500);
  pinMode (pirPin, INPUT);
  
  pinMode(ledPin,OUTPUT);
  digitalWrite(pirPin, LOW);
  
  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
   started = true;

    
}



void loop()
{
  
 if (started)
  {
    sms_position = sms.IsSMSPresent(SMS_UNREAD);
    if (sms_position)
    {
      Serial.print("SMS postion:");
      Serial.println(sms_position, DEC);
      sms.GetSMS(sms_position, phone_number, sms_text, 100);
      Serial.println(phone_number);
      Serial.println(sms_text);
      
      if(strcmp(sms_text,"on")==0) {         
        pinMode (pirPin, INPUT); //activate PIR sensor 
        delay(100);
      }

      if(strcmp(sms_text,"off")==0) {
        pinMode (pirPin, OUTPUT); //deactivate PIR sensor 
        delay(100);
      }
    }
  delay(2000);
}
  
    
  
 if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       SIM900.println("ATD + " + NumberToCall + ";"); // dial a number
       delay(300);
       Serial.println("dialing");
       delay(30000);  // wait for 30 seconds...
       SIM900.println("ATH"); // hang up
      }
 
     if(digitalRead(pirPin) == LOW){      
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state
        }
    delay(5000); //wait 5 seconds before the next loop
}

Any idea from someone? Thanks.

These kind of comncern me…
Multiple declarations of the same asset.

#include <SoftwareSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
SoftwareSerial SIM900(7, 8);

followed in setup() with

 SIM900.begin(9600);  // for GSM shield
  gsm.begin(9600);        // for GSM shield

Do you have TWO modem shields ?
One called sms(SIM900), and one called gsm ?

gsm appears to be using pins 1&2
sms appears to be using pins 7&8

Your libraries and function calls may be getting tangled up.
I didn’t crawl through your code in detail, but I have written a lot of SMS/GSM and GPRS code - but I never had to use two separate libraries.
Perhaps you’ve fused two other blocks of code together to make your sketch… this isn’t the way to do it.

I have only one GSM shield. Unfortunately I am not able to write such codes from scratch (yet :) ) that is why I used libraries and code fragments. Anyway I'd like my project to work properly. That is why I turned to this forum to seek for help. I will correct those duplicated rows from the codes to see if it helps. The only problem is that calling works well but SMS receiving does not work well without Serial Connection to PC. This is very weird. I am trying to cleanse my code it may help. Thanks for any advice.

Hi guys, I’m taking this topic back to life. I am trying to do an Arduino relay control via SMS and I have a problem. So, if I connect the Arduino with the usb to my computer, open Serial Monitor and there it writes all his initialization process the whole device works perfectly. If I power down the circuit and then power it up without connecting the usb it does not respond to any command. I use a sim800l with my Arduino, it’s powered up from the same power source with arduino but it has a step down module to 3.3V, I also used a logical level converter from 5v to 3.3v. So the Arduino , gsm shield and converter are al three powered up from the same power source (so common ground) this may not be a problem.
I attach my code so maybe somebody with more experience can tell me where I am wrong.
On short, I want my device to work properly by only powering it up and not needing to connect it to laptop’s USB. Thank you!
PS. If I plug it to USB and it does his initialization and then I unplug the USB with the other power source still plugged in it still works :cold_sweat:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(3,2);  // (Rx,Tx  > Tx,Rx) 

char incomingByte; 
String inputString;
int relay = 6;// Output for Relay Control
int relay1 = 9;
int relay2 = 13;
void setup() 
{
      pinMode(relay, OUTPUT);
      pinMode(relay1, OUTPUT);
      pinMode(relay2, OUTPUT);
      digitalWrite(relay, LOW);
      digitalWrite(relay1, LOW);
      digitalWrite(relay2, LOW);// Initial state of the relay
      Serial.begin(9600);
      mySerial.begin(9600); 

     while(!mySerial.available()){
        mySerial.println("AT");
        delay(1000); 
        Serial.println("Connecting...");
        }
      Serial.println("Connected!");  
      mySerial.println("AT+CMGF=1");  //Set SMS to Text Mode 
      delay(1000);  
      mySerial.println("AT+CNMI=1,2,0,0,0");  //Procedure to handle newly arrived messages(command name in text: new message indications to TE) 
      delay(1000);
      mySerial.println("AT+CMGL=\"REC UNREAD\""); // Read Unread Messages
     }

void loop()
{  
  if(mySerial.available()){
      delay(100);

      // Serial Buffer
      while(mySerial.available()){
        incomingByte = mySerial.read();
        inputString += incomingByte; 
        }

        delay(10);      

        Serial.println(inputString);
        inputString.toUpperCase(); // Uppercase the Received Message

        //turn RELAY ON or OFF
        if (inputString.indexOf("ON") > -1){
          digitalWrite(relay, HIGH);
          delay(1000);
          digitalWrite(relay1, HIGH);
          delay(3000);
          digitalWrite(relay2, HIGH);
          delay(2000);
          digitalWrite(relay2, LOW);
          
          }
         if (inputString.indexOf("OFF") > -1){
          digitalWrite(relay, LOW);
          digitalWrite(relay1, LOW);
          }          

        delay(50);

        //Delete Messages & Save Memory
    
        if (inputString.indexOf("OK") == -1){
        mySerial.println("AT+CMGDA=\"DEL ALL\"");

        delay(1000);}

        inputString = "";
  }
}

What’s your power supply arrangements? The modem takes short bursts of up to 2A while registering and switching cells (or in low signal areas), which really needs to be considered.

An accurate schematic of your current setup will help.

This is my electrical scheme, I used 3 red LED s to simulate the relays. I looked on my power supply and it says it can feed up to 400mA :confused: I will try to put the arduino to my car’s battery as I don t have another power source .

yeah, I think the max. 400mA PSU limit [u]will[/u] cause problems - if not now, then certainly later. And your separate regulator for the modem is a good idea.

I found a PC source and tried with it, it does exactly the same :frowning: . It also started to don’t see the characters properly(when I sent On it recevied a square and ‘n’) but I modified the baud rate from 9600 to 19200 and it is ok now. Other ideas? I think something in the code may be wrong, like he does not respect de code if it doesen’t see the initialization on the serial monitor of the laptop . I can hear the gsm module’s little noise when it receives a SMS even if it’s not connected to the pc.

Unfortunately I don’t have the same hardware, but as an engineer, I avoid software serial for the ‘workaround that it is’ I use 1280/2560/1284 chips and SIM 5320 and 7600 modems exclusively - also because my code tends to be a bit larger, and I use a fair bit of EEPROM and RAM.

Hardware serial just works, and doesn’t introduce ‘conditions’ you have to be aware of.

I’ve never seen the most common problems often posted in the forum. But in all computer projects, you can’t cut corners on the power supply planning. ...and in fact, I’ve cheated on cellular modem power supplies (in good signal areas), I use 1.2A on the 5V rail with no problems.

But that’s about as low as you can go with 470uF after the regulator.

I understand, but now I don t see any problem in my power supply planning, the new source cand provide 16A at 12V , far more than my setup needs. Maybe somebody else has been throw something similar cand can help me with an advice :D thank you for your time @lastchancename !

ok, i’ll look a bit closer. Hope i can help.

In your photo and drawing, you show two different modems, and in the drawing, what looks like a 3v3 level converter.
What’s the buck converter doing…
As a UNO plug-on shield, it’s probably 5v compatible, so the level conversion isn’t necessary (they’ll be onboard the modem shield). Check your docs.

Extra observations…
You should lose the String buffers, and explore c-strings to avoid memory problems in the future.

As mentioned previously, I prefer to use direct SMS reception, the buffer isn’t a problem, but gives you more work.
It’s certainly odd that it works with USB, but not without…

As far as I read some people recommend to use the logical converter because the sim800l runs on 3.3v(it's power voltage is between 3.3 and 4.3V). I will give it a try without the converter

Careful, check the datasheet for YOUR board, but as a plug-in UNO shield, it is most likely to be UNO 5v compatible.