Program is so UNSTABE, sometimes work sometimes NOT

Hello,

I am new to programming and I need help. I'm working on a project that will remotely read voltage and send me an SMS. BUT ... BUT so far I've made multiple versions of a program (more that 17 versions of it) that, along with the hardware, at start WORK at my work (I've reset modules more than 20 times, to check if it will work), and when if I take it home to test …it stop working. Then I bring that same hardware and program back to work and it does NOT work. First I used SIM900 GSM module… also at the beginning worked, after some time stops … so I replaced It with SIM800L. I pull out the AT328P from the Arduino board and load it into the project board ... the same story ... it works at start. I doubt the Arduino Rev board .. not an original product. When I pull out my SIM card from SIM800L ... after sending 10 SMS messages and insert it into my Android phone ... messages are in the SIM card memory ... have not been deleted. I delete them .. using phone, insert the SIM card again into the SIM800L module ... it doesn't work again. THERE IS NO LOGIC AT ALL.
The biggest problem is in SETUP ...

if (messageIndex > 0)

once recognize it .... several times DO NOT. There are no rules when it will stop working!!!
Sometimes VOID setup () works perfect and sudenly stops... Sudenly everything works.... and then stops. I have changed several AT328P it is the same....

HELP....HELP....HELP....HELP....HELP

I am using:

  1. Arduino Uno Rev.3 board (made in Italy), bought from eBay
  2. SIM800L V2.0 5V Wireless GSM GPRS Module, bought from eBay
  3. Power Supply Step down Module LM2596s 3A DC to DC Buck converter

Connections are:

SIM800L ARDUINO Uno Rev3 DC/DC Module LM2596s

board Digital pin

Tx 7
Rx 8
Power 5/4V +
Power GND -
UART GND GND

This is CODE:

#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include "DHT.h"
#include "HX711.h"
HX711 scale(A1, A0);
#define DHTPIN 2
#define PIN_TX 7
#define PIN_RX 8
#define BAUDRATE 9600
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
/*kod kod kod kod kod kod kod */
#define code "0404"
/*kod kod kod kod kod kod kod */
int messageIndex = 0;
#define DHTTYPE DHT22
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
DHT dht(DHTPIN, DHTTYPE);
char smsbuffer[160];
char n[20];
char phone[16];
char telefon[16];
char datetime[24];
int analogInput = A2;
float vout = 0.0;
float vin = 0.0;
char string[160];

void setup() {
for (int i = 2; i <= 6; i++)
{
pinMode(i, OUTPUT);
}
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(analogInput, INPUT);

Serial.begin(9600);

delay(1000);
while (!gprsTest.init()) {

Serial.println("Modem is NOT connected");
delay(30000);
}

Serial.println("Modem IS connected");
delay(5000);
Serial.println("Deleting message index");
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
Serial.println("1 NO code before");

nocode:

Serial.println("1 NO code after");
Serial.println("Waiting 30 seconds to send CODE");
delay(30000);
messageIndex = gprsTest.isSMSunread();
Serial.println("Reading messages");
if (messageIndex > 0) {

Serial.println("There is some message in memory");

gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
Serial.println("Readind message parameters");
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
if (strcmp (message, code) == 0) {

Serial.println("Code IS OK");

}
else {

Serial.println("Waiting 20 seconds to send CODE BEFORE");
delay(20000);
Serial.println("Waiting 20 seconds to send CODE AFTER");
goto nocode;
}

}
else if (messageIndex <= 0) {
delay(20000);
Serial.println("2 There is NO code before");

goto nocode;

Serial.println("2 There is NO code after");

}

delay(5000);
mesageeee:
delay(5000);
}

void loop() {
Serial.println("Message before");

for (int i = 1; i <= 288; i++) {
messageIndex = gprsTest.isSMSunread();
if (messageIndex > 0) {
Serial.println("At least, there is one UNREAD SMS... LOOP");
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
Serial.println("In order not to full SIM Memory, is better to delete it...LOOP");
gprsTest.deleteSMS(messageIndex);
Serial.println("Message is sent LOOP");

}

delay(297500);
}
}

void mesageeee()
{
Serial.println("Message is sent SETUP");

}

CODE.txt (2.99 KB)

At the begining of my code some lines found initially are irrelevant ... all related to .. DHT..HX711...LCD...

How are you powering that SIM800?
GSM modens are current hungry so you should power it by an external power source not the USB.If you have a weak signal it will drain even more current.That could explain what you are describing ...

SIM800 is powering directly from DC/DC Module LM2596s. And it is not restarting ...it is stable. When once "catch" GSM network, LED blink once in 3 seconds. Problem is that is so unstable... serial monitor shows that SIM800L is connected to network but when must recogniye input string ...nothing hepens..
Command if(mesageindex)>0 should be executed but nothing hapens...Several times works and stops...

Please read the forum guides and correct/repost your first post with posted inline.
Many of us can’t see it on mobile devices.

I'm with hugo007. When I did one, I ended up having to run a lipo battery almost the size of my palm to keep it happy. 1,200 mah @ 3.7V I think it ended up being. I couldn't run it off an external power supply because it needed the big battery as a capacitor.

Also, signal was a big issue. Is yours set up to show you the signal strength as it runs?

-jim lee

It is running with switching power suply 12V/3A.

I’d love to help with hundreds of SIMCOM modems in the field , but you need to work with us.

"I'd love to help with hundreds of SIMCOM modems in the field , but you need to work with us."

What shall I do ...?