0

I'm using a GSM Module with Arduino along with Node MCU. I have a supply of 9V, 2A in the DC jack of the Arduino and the GSM Shield. The Node MCU is powered from the 3.3V of the Arduino. I can receive messages fine in the GSM when the USB port of the Arduino (including the power supply I mentioned earlier) is connected to the laptop through and monitored using the serial monitor. However if I remove the USB port, the GSM cannot receive the messages anymore but when I press the reset button of the Arduino, it will start receiving messages again. Why does it only works when I reset the Arduino first after powering it up?

#include <SoftwareSerial.h>
#include <Wire.h>

SoftwareSerial gsmSerial(2, 3);

char incomingByte;
String inputString;

// Pin configurations.

const int outlet1Pin = 4;
const int outlet2Pin = 5;
const int outlet3Pin = 6;

const int ping1Pin = 7;
const int ping2Pin = 8;
const int ping3Pin = 9;
const int ping4Pin = 10;
const int ping5Pin = 11;
const int ping6Pin = 12;
const int signalPin = 13;

const int pingWaitTime = 3000;

void setup()
{
  Serial.begin(9600);
  gsmSerial.begin(9600);

  pinMode(outlet1Pin, INPUT);
  pinMode(outlet2Pin, INPUT);
  pinMode(outlet3Pin, INPUT);

  pinMode(ping1Pin, OUTPUT);
  pinMode(ping2Pin, OUTPUT);
  pinMode(ping3Pin, OUTPUT);
  pinMode(ping4Pin, OUTPUT);
  pinMode(ping5Pin, OUTPUT);
  pinMode(ping6Pin, OUTPUT);
  pinMode(signalPin, OUTPUT);

  initGSM();
  //Serial.flush();
  //gsmSerial.flush();
  //sendSMS("Test send.");


}

void loop()
{
  if (gsmSerial.available())
  {
    digitalWrite(signalPin, HIGH);

    delay(500);

    //Serial.println("Serial available.");

    while (gsmSerial.available())
    {
      incomingByte = gsmSerial.read();
      inputString += incomingByte;
    }

    inputString.toUpperCase();



    checkCommandAction(inputString);


    if (inputString.indexOf("OK") == -1)
    {
      gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
      delay(1000);
    }

    inputString = "";
    gsmSerial.flush();

  }
  digitalWrite(signalPin, LOW);

}

void sendSMS(String text)
{
  Serial.println("Sending Text...");

  gsmSerial.println("AT+CMGF=1");
  delay(1000);

  gsmSerial.print("AT+CMGS=\"+numberhere\"\r");

  delay(1000);

  gsmSerial.print(text);
  delay(1000);

  gsmSerial.print((char)26);
  delay(1000);

  gsmSerial.println();
  Serial.println("Message sent!");
  delay(1000);
}

void initGSM()
{
  gsmSerial.println("ATE0");
  while (!gsmSerial.available())
  {
    gsmSerial.println("AT");
    delay(500);
    Serial.println("Connecting...");
  }

  Serial.println("Connected!");

  gsmSerial.println("AT+CMGF=1");
  delay(500);
  gsmSerial.println("AT+CNMI=1,2,0,0,0");
  delay(500);
  gsmSerial.println("AT+CMGL=\"REC UNREAD\"");
  delay(500);
  gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
  delay(500);

  Serial.println("All messages deleted!");

  Serial.println("Sending Text...");

  gsmSerial.println("AT+CMGF=1");
  delay(500);

  gsmSerial.print("AT+CMGS=\"+639776811077\"\r");

  delay(500);

  gsmSerial.print("Device Initialized!");
  delay(500);

  gsmSerial.print((char)26);
  delay(500);

  gsmSerial.println();

  Serial.println("Message sent!");
  delay(500);
}

void checkCommandAction(String command)
{

  //Serial.println("Check Command.");

  if (command.indexOf("O1ON") > -1)
  {

    digitalWrite(ping1Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping1Pin, !HIGH);
    Serial.println("O1ON Enter");
    sendSMS("Outlet 1 Turned ON by text.");

  }
  else if (command.indexOf("O1OFF") > -1)
  {
    digitalWrite(ping4Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping4Pin, !HIGH);
    Serial.println("O1OFF");
    sendSMS("Outlet 1 Turned OFF by text.");
  }
  else if (command.indexOf("O2ON") > -1)
  {
    digitalWrite(ping2Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping2Pin, !HIGH);
    Serial.println("O2ON");
    sendSMS("Outlet 2 Turned ON by text.");
  }
  else if (command.indexOf("O2OFF") > -1)
  {
    digitalWrite(ping5Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping5Pin, !HIGH);
    Serial.println("O2OFF");
    sendSMS("Outlet 2 Turned OFF by text.");
  }
  else if (command.indexOf("O3ON") > -1)
  {
    digitalWrite(ping3Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping3Pin, !HIGH);
    Serial.println("O3ON");
    sendSMS("Outlet 3 Turned ON by text.");

  }
  else if (command.indexOf("O3OFF") > -1)
  {
    digitalWrite(ping6Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping6Pin, !HIGH);
    Serial.println("O1OFF");
    sendSMS("Outlet 3 Turned OFF by text.");
  }
  else if (command.indexOf("CHECKSTATE") > -1)
  {
    int state1 = !digitalRead(outlet1Pin);
    int state2 = !digitalRead(outlet2Pin);
    int state3 = !digitalRead(outlet3Pin);

    String toSend = "";
    toSend += "Outlet 1: ";
    toSend += String((state1) ? ("ON") : ("OFF"));
    toSend += "Outlet 2: ";
    toSend += String((state2) ? ("ON") : ("OFF"));
    toSend += "Outlet 3: ";
    toSend += String((state3) ? ("ON") : ("OFF"));

    sendSMS(toSend);
  }
}

void turnPingsOn()
{
  // The pins where the pings are connected are
  // configures as INPUT_PULL up, so we need to high
  // it by default.

  digitalWrite(ping1Pin, HIGH);
  digitalWrite(ping2Pin, HIGH);
  digitalWrite(ping3Pin, HIGH);
  digitalWrite(ping4Pin, HIGH);
  digitalWrite(ping5Pin, HIGH);
  digitalWrite(ping6Pin, HIGH);
}
  • Please show us the sketch you are using. – VE7JRO May 30 '18 at 21:48
  • Updated, I use AT commands for sending and receiving SMS. It works fine if I connect it to the computer and open the serial monitor. However when I just use the dc jack, it won't receive any message. – LinkedRom May 30 '18 at 22:10
  • how do you know that messages are not being received? – jsotola May 30 '18 at 23:52
  • A relay will open if a certain message is received. – LinkedRom May 31 '18 at 3:07
1

In theory you shouldn't rely on the 3.3V supply of the Arduino to power the NodeMCU board, it doesn't have enough power particularly when WIFI data is being transmitted.

Are you removing the USB while the system is live? If so you are probably spiking various bits that don't like being spiked and that's why it breaks.

If you are removing the USB and THEN powering up the system, what happened when you power down you system and power it back up again after 10 seconds? My guess is that it won't receive messages. So there is a difference between applying power and resetting the board, which implies that you are very marginal on your power supply.

If you are using the SIM800 (?) module they need 2Amps to transmit, so if you are only supplying 2A it might not have enough power to cold start, but when reset it does. So if you can try more power that might help.

Another thought might be you haven't got a proper ground (wall warts aren't normally grounded) so your USB connection is acting as a ground. If this is the case then it should work when you PC is turned off.

Sorry this is a bit vague, but your question needs model names and part number for people to be a bit more specific.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.