1

I am writing an SIM900A + arduino(Arduino UNO with Atmega 328P) code to just send the current time stamp every 20 minutes. The code keeps crashing in the SendMessage() function as the setup prints keep coming again and again. Please let me know what I am doing wrong. Thanks in advance

#include <SoftwareSerial.h>
#include <LowPower.h>
SoftwareSerial mySerial(9, 10);
char msg;
char call;
int ctr;

#define TIME_STR_LEN 100  // the actual number of characters for date and time

char timeStamp[TIME_STR_LEN]; // holds the time string

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println("GSM SIM900A BEGIN");
  mySerial.println( "AT+CLTS=1");
  delay(1000);
  ctr = 0;
  delay(10000);
}

void loop()
{  

  if(mySerial.available()>0)
  {
    while (mySerial.available()>0)
    {
      mySerial.read();
    }  
  }
  
  if (ctr%1 == 0)
  {    
    delay(1000);
    SendMessage();
    delay(100);
    ctr = 0;
    Serial.println("just sent a message");
  }
  delay(60000);
  ctr++;
  //LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);  
}

void SendMessage()
{
 mySerial.println( "AT+CCLK?" );
 delay(2000);

 int i = 0;

 if (mySerial.available()>0)
 {
      while (mySerial.available()>0 && i < TIME_STR_LEN) 
      {
        timeStamp[i]=(mySerial.read());
        i++;              
      }
  }
  delay(2000);
  
  mySerial.println("AT+CMGF=1");
  delay(1000);  
  mySerial.println("AT+CMGS=\"xxxxxxxxxx\"\r"); 
  delay(1000);
  mySerial.println("Motor is ON ");
  delay(100);
  mySerial.println(timeStamp);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}
3
  • Might be a brownout. Are you sure your power supply is powerful enough? The SIM900A needs quite a lot of current.
    – StarCat
    Mar 18, 2021 at 17:40
  • Currently I have just powered the sim 900A using the 5V and GND pins of the Arduino
    – Ash96
    Mar 18, 2021 at 18:27
  • And how is the Arduino powered? We need to know the maximum current and also how the power supply is connected (though barrel jack, through USB or directly to the 5V pin)
    – chrisl
    Mar 18, 2021 at 19:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.