Controlling 8-relays via GSM not working after unplugging and reconnecting power

Help needed - Sketch controlling 8-relay module via a GSM SIM 800L module not working after unplugging and reconnecting power to the setup!?

Hi folks

I am new to the world of electronics and Arduino, but are eager to learn, because I think it is really cool and fun to make your own electronic gadgets, and use them afterwards to various practical things.

I have made a setup, that consists of 1 pcs Arduino Uno, 1 pcs 8 channel relay module, 1 pcs GSM SIM 800L module & 1 pcs 5 volt 2,5 Amp power supply. The power supply, supplies all the modules with a common GND (see also power connections description in the sketch).

I have made a sketch, which is patched together from other coders sketches, and own minor changes and additions.

After uploading the sketch to the Uno, the setup works fine, and as intended, but only if the power supply are turned on and connected to the setup as well during upload. The setup continues to work fine, after unplugging the USB cable from the computer, with the power supply still turned on and connected.

If the power to the setup is unplugged and then later reconnected to the setup, nothing works!? In order to get the setup to work again, I have to reconnect the USB cable and either start the seriel monitor from IDE, or upload the sketch again with the power supply turned on and connected !?

I have attached the sketch (it was too long to insert here)

I have spend weeks searching the web to find a explenation/solution, but without luck, so I am hoping one of you guys can help with an explanation to what is wrong, and a solution to resolve this problem.

Thanks in advance

GSM_SIM800L-8_RELAYS-UNO-FORUM_SKETCH.ino (10.1 KB)

My first idea is that powering the entire setup at the same time might cause a current rush that the pwr source doesn't handle.
Can You pwr up the UNO first and then the other parts, one by one?

Reloading the sketch to the UNO can't really be needed. That sounds really strange. Have You tried using the reset button to start up when this hanging occurs?

This sounds very much like a power issue. We will need to see a schematic, even a hand-drawn one

So, now I have tried to power the UNO up first, then the relay module and last the GSM module, but with the same result.

I have also tried resetting the UNO, but again with the same result.

I have noticed, when I upload the sketch, all of the relays turn on for a few seconds, and the turns off one by one, and the same happens when the seriel monitor is opened; and after doing one of those two things, everything works.

When all the modules are powered up at the same time, again all of the relays turn on for a few seconds, and the turns off one by one, but hereafter nothing works.

I have attached the wiring schematics i an excel doc, and you can also find it at the start in the attached sketch.

Well, I tried to attach an excel doc with the wiring schematics, but a pop-up said, that something went wrong, so now I will try to attach a picture instead, and if I get the same pop-up, you will have to look in the start of the sketch where it is also described.

Try putting some of the Serial debug prints back in to see how far you are getting to in loop().

What do you see with this uncommented

Serial.println(inputString);

What is sending the incoming message, and how is it timed to the startup of the code?

@ cattledog: I am not quite sure, what it is I should try, but I have tried inserting “Serial.println(inputString);” lots of different places in the sketch, but without any change.

I have also opened the serial monitor while sending SMS (text) commands to the setup, but nothing pops up there.

I am using my smartphone (Samsung Galaxy X-cover 4) to send SMS commands to the setup. Regarding timing of sending SMS codes, relative to the startup of the code, I wait until the GSM module have found signal to the 4-G net, before I SMS codes.

You must uncomment the line //Serial.begin(9600) That is Serial handled by USB.
Software Serial is totally differet, uses hardware I/O pins.
You onle "begin the software serial.

Okay, now I think I get it;

Right; I have uncommented (removed the //) in front of “Serial.begin(9600);” in void stup(), and uncommented all off the following “Serial.println(inputString);” both in void setup() and in void loop().

This is what I see in the serial monitor, when I opens it, right after upload of the altered sketch:

22:38:31.102 -> connecting....
22:38:31.102 -> Connected..
22:38:39.254 -> AT
22:38:39.254 -> OK
22:38:39.254 -> AT+CMGF=1
22:38:39.287 -> OK
22:38:39.287 -> AT+CNMI=1,2,0,0,0
22:38:39.287 -> OK
22:38:39.329 -> AT+CMGL="REC

This is what I see in the serial monitor, after sending the text “On1”:

22:42:56.759 ->
22:42:56.759 -> +CMT: "+46xxxxx (my phone number, but missing the last 3 digits, I think)
22:42:57.859 -> 163","","20/03/30,22:42:52+08"
22:42:57.894 -> On1
22:42:57.894 -> AT+CMGDA="DEL ALL"

22:42:57.927 -> OK
22:42:57.927 ->
22:43:01.003 -> SMS sent
22:43:01.103 -> AT+CMGS="0046xxxxxxxx" (my phone number)

22:43:01.103 -> > Switched ON1
22:43:04.228 -> SMS sent
22:43:05.350 ->
22:43:05.350 -> +CMGS: 185
22:43:05.350 ->
22:43:05.350 -> OK
22:43:05.350 -> AT+CMGDA="DEL ALL"

22:43:05.383 -> OK
22:43:05.383 ->

And this is what I see in the serial monitor, after sending the text “Off1”:

22:47:19.368 ->
22:47:19.368 -> +CMT: "+46xxxxx (my phone number, but missing the last 3 digits, I think) 22:47:20.466 -> 163","","20/03/30,22:47:15+08"
22:47:20.500 -> Off1
22:47:20.500 -> AT+CMGDA="DEL ALL"

22:47:20.534 -> OK
22:47:20.534 ->
22:47:23.527 -> SMS sent
22:47:23.594 -> AT+CMGS="0046xxxxxxxx" (my phone number)

22:47:23.629 -> > Switched OFF1
22:47:26.644 -> SMS sent
22:47:27.755 ->
22:47:27.755 -> +CMGS: 186
22:47:27.789 ->
22:47:27.789 -> OK
22:47:27.789 -> AT+CMGDA="DEL ALL"

22:47:27.789 -> OK
22:47:27.824 ->

Good. What conclusions do You make from it?

I will have a good look at it tomorrow, and then get back to you, hopefully with good answers!?

Do that!

This is what I see in the serial monitor, when I opens it, right after upload of the altered sketch:

Great. Looks like what you'd expect with a working sketch.

What do you see when you press the reset button?
What do you see when you pull the power and then plug it back in?

Hi,
Can you please post your schematic, hand draw it and post an image of it.

Thanks.. Tom.. :slight_smile:

@Railroader:

So, now I have taken a look at the feedback-text from the serial monitor, and here is what I get out of it.

It seems that the 3 last digits, in referral to my cell phone number, are missing.
I think this is due to that I have changed the delay (the first delay in void loop() in the sketch) from a delay of 100 in the original sketch I used to a delay of 10 in the adjusted sketch, in order to reduce the number of auto-reply text messages from 2 to 1, from the GSM module to my cell phone, and or, due to that I have also changed another delay (the second delay in void loop() in the sketch) from a delay of 10 in the original sketch I used to a delay of 20 in the adjusted sketch.

@ cattledog:

Nothing displays in the serial monitor when I press the reset button, when the setup is in a “working state” & Nothing displays in the serial monitor when I cut the power and reconnect it again.

@TomGeorge: I have earlier tried to upload an excel doc with the wiring schematics, but a pop-up said, that something went wrong, and afterwards a picture, but with the same result. I will give it one more go, otherwise you will have to look in the start of the sketch where it is also described.

Delay is very often not soo good to use. The first delay looks odd. If there is serial available, why wait reading?
The other delays, I will not analyze them. Sending characters I believe that Software Serial will queue them up. If the buffer gets filled serial.write will not return. If the receiver needs pauses, it looks like hard to run an effective communication.

Nothing displays in the serial monitor when I press the reset button, when the setup is in a "working state" & Nothing displays in the serial monitor when I cut the power and reconnect it again.

     Serial.begin(9600);
     mySerial.begin(9600); 

// Check if you're currently connected to SIM800L
      while(!mySerial.available()){
        mySerial.println("AT");
        delay(1000);
        Serial.println("connecting....");
        }
      Serial.println("Connected..");

It is a mystery to me why you do not see either the "connecting" or "Connected" or both messages on a reset.

I want to confirm that you are indeed getting to setup() and are hanging there for some reason. If you are actually not returning to setup() with the reset something else is happening

Try a print statement before the checking for connection. Do you see that you are indeed in setup?

     Serial.begin(9600);
     mySerial.begin(9600); 
     Serial.println("In setup()");

// Check if you're currently connected to SIM800L
      while(!mySerial.available()){
        mySerial.println("AT");
        delay(1000);
        Serial.println("connecting....");
        }
      Serial.println("Connected..");

The line of code   while(!mySerial.available()){ waits for something to come from serial and then the action is serial.write. Is that as it should be, a character comming from serial upon .begin?

waits for something to come from serial and then the action is serial.write. Is that as it should be, a character comming from serial upon .begin?

What he is doing at startup to detect a connection is checking if there is anything to read in the software serial buffer. There should not be, so the code enters the while loop and sends the module "AT". The module should send back an "OK". When code sees that reply, it breaks from the while loop.

He should see either the print out from inside the while loop, or the print out after he breaks from it, or both.

Fully correct. My mistake, being too tired I suppose.