Introduction.

If you love DIY electronics, you’ve probably heard about Arduino. It’s a fun and simple way to get into robotics and programming. But did you know you can also use it to send text messages and make phone calls? That’s right! With a little help from a GSM module (like the kind in your cellphone), you can start sending messages and calling from your Arduino project. This article will show you how, step by step. Whether you’re making a smart mailbox, a home alarm system, or just want to learn something new, this guide has got you covered.

What You Need.

Understanding 2G Network Compatibility.

Power Supply Considerations for SIM900A

Understanding Power Needs: GSM modules, including the SIM900A, can be sensitive to power supply fluctuations. Their power consumption varies based on network signal strength and the operations they are performing (like sending an SMS or making a call).
SIM900A Specifications: According to its datasheet, the SIM900A module operates efficiently on a 12V, 2A power supply. This specification is critical for the module’s performance and longevity.
Why Correct Voltage and Current are Important:

Checking the Datasheet: Always consult the datasheet of the GSM module for precise power requirements. The datasheet is the most reliable source for technical specifications and will provide guidance on the optimal operating conditions.
Power Supply Options:

Monitoring Power Delivery:

In your project, include a means to monitor the power supply to the GSM module. This can be through voltage regulators or by using Arduino to detect and respond to power fluctuations.

Connections.

Make the connections as per the below connection diagram.

What is AT Commands.


AT Commands, short for Attention Commands, are a set of instructions used to control modems. Originating in the early days of computer telecommunications, these commands provide a standard language for modems and other communication devices to interpret and execute commands. Here’s a general overview:

1.History: AT Commands were initially developed for the Hayes Smartmodem 300 in the early 1980s. They have since become a standard for controlling modems.

2.Syntax: The commands typically start with the prefix “AT” (which stands for Attention) to get the modem’s attention. Following this prefix are various commands that instruct the modem what to do. For example, “ATD” followed by a phone number would instruct the modem to dial that number.
Types of Commands:

 4.Uses: While originally designed for dial-up modems, AT commands have found uses in a variety of other telecommunications devices. For instance, they are widely used in GSM and GPRS modems and devices for sending SMS messages, making calls, or accessing internet services.

5.Execution: The commands can be executed via a serial interface (RS-232), over a network, or even within a system (like a computer or a mobile device) depending on the device and its capabilities.

6.Modern Relevance: Even though dial-up modems have largely become obsolete with the advent of broadband internet, AT commands are still relevant in areas like IoT (Internet of Things), where they are used to control and configure GSM/GPRS modules and other telecommunication devices.

NextPCB: Your One-Stop Solution for PCB Manufacturing and Assembly.

This project is successfully completed because of the help and support from NextPCB -Reliable Multilayer PCB Manufacturer. NextPCB is one of the most experienced PCB manufacturers in Global, has specialized in the PCB and assembly industry for over 15 years.

Unmatched Reliability and Quality
NextPCB prides itself on offering high-reliability PCB solutions. With over 15 years of in-house fabrication expertise, they guarantee 100% quality on their products, promising to remake them free of charge if any issues arise. Their commitment to quality is reflected in their impressive 99.6% on-time delivery rate, ensuring that your projects adhere to the stipulated timelines without any hitches.

Free PCB Assembly Services
In a bid to support engineers and enthusiasts in their endeavors, NextPCB offers free PCB assembly services, allowing individuals and businesses to experience reliable PCB assembly from NextPCB without any cost. This initiative stands as a testament to NextPCB's commitment to fostering innovation and supporting the PCB community.

Code.

Click here to download the code.

#include <SoftwareSerial.h>

int i;
SoftwareSerial mySerial(9, 10);

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
     Serial.println("Sending text Message through GSM Module");
     mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
     delay(1000);  // Delay of 1 second
     mySerial.println("AT+CMGS=\"+918543053029\"\r"); // Replace x with mobile number
     delay(1000);
     mySerial.println("Hello from GSM Module");// The SMS text you want to send
     delay(100);
     mySerial.println((char)26);// ASCII code of CTRL+Z for saying the end of sms to  the module 
      delay(1000);
      break;

     case 'r':
      mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
      delay(1000);
      break;

      case 'c':
      if(i==0)//i variable to ensure that only one call request will be sent by gsm during pressing and holding the pushbutton;
        {
          Serial.println("Calling through GSM  Module");
          delay(1000);
          mySerial.println("ATD8543053029;"); // ATDxxxxxxxxxx; semicolon should be at the last ;AT command that follows UART protocol;
          Serial.println("Calling 8543053029");
          delay(1000);
          i++;
         }
   i=0;
      
      break;
  }

 if (mySerial.available()>0)
   Serial.write(mySerial.read());
}

This Arduino code is designed to interface with a GSM module using AT commands for sending SMS messages, receiving live SMS, and making phone calls. The code uses the SoftwareSerial library to create a serial communication interface with the GSM module. Let’s break down the code section by section: 

#include <SoftwareSerial.h>

int i;
SoftwareSerial mySerial(9, 10);

The setup Function

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of 4G LTE Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}

This function initializes the serial communication.

The loop Function

This function continuously runs, checking for input from the Serial Monitor and responding accordingly.

Sending SMS (‘s’ command)

void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
     Serial.println("Sending text Message through 4G LTE Module");
     mySerial.println("AT+CMGF=1");    //Sets the 4G Module in Text Mode
     delay(1000);  // Delay of 1 second
     mySerial.println("AT+CMGS=\"+91XXXXXXXXXX\"\r"); // Replace x with mobile number
     delay(1000);
     mySerial.println("Hello from 4G LTE Module");// The SMS text you want to send
     delay(100);
     mySerial.println((char)26);// ASCII code of CTRL+Z for saying the end of sms to  the module 
      delay(1000);
      break;

Checks if there is data available to read from the Serial Monitor.

If the character ‘s’ is received, it triggers the SMS sending sequence:

Receiving SMS (‘r’ command)

 case 'r':
      mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
      delay(1000);
      break;

If the character ‘r’ is received, it configures the GSM module to notify when a new SMS is received.

Making a Call (‘c’ command)

case 'c':
      if(i==0)//i variable to ensure that only one call request will be sent by gsm during pressing and holding the pushbutton;
        {
          Serial.println("Calling through 4G LTE Module");
          delay(1000);
          mySerial.println("ATD8543053029;"); // ATDxxxxxxxxxx; semicolon should be at the last ;AT command that follows UART protocol;
          Serial.println("Calling 8543053029");
          delay(1000);
          i++;
         }
   i=0;
      
      break;

If the character ‘c’ is received, it initiates a phone call:

Reading from GSM Module

if (mySerial.available()>0)
   Serial.write(mySerial.read());

Testing It Out.

Conclusion.
Combining Arduino with a GSM module is a fantastic way to add communication to your projects. You can make things like a gadget that tells you when you have mail, or a home security system that calls you if something’s wrong. It’s not just fun – you’ll learn a lot about electronics and programming too. Remember, this is just the beginning. There’s so much more you can do with Arduino and GSM!