Arduino Emergency Caller Prototype with NodeMCU and Crowtail-4G SIM A7670E

I created a prototype device for elderly people to make single-button calls or send emergency SMS to their caregivers.
May 03, 2024 — 5 mins read — Arduino

Arduino Emergency Caller Prototype with NodeMCU and Crowtail-4G SIM A7670E

A few weeks ago, Elecrow reached out to me to see if I'm interested in creating a project with their Crowtail-4G SIM A7670E Module and since I've never worked with 4G before, I said yes.

The basic purpose of the module is to make calls and send messages so I decided to base my project on that and create a device for elderly people to call their caregivers or send an emergency SMS with just a single button press.

To interface the buttons and the 4G module, I'm using a NodeMCU board because it is directly compatible with the 3.3V UART on the module.


Project Video

I make videos of all my projects so if that is your thing, then you can watch it below.


Crowtail-4G SIM A7670E Module

The Crowtail series 4G module is a high-performance LTE Cat1 wireless unit powered by the SIM A7670E communication module from Simcom, managing data and voice communications over a UART interface. This module accommodates a range of LTE bands such as B1/B3/B5/B7/B8/B20, along with support for WCDMA and GSM networks. It is also compatible with various communication protocols including TCP/IP, FTP, and HTTP, and supports multiple satellite navigation systems like GPS, GLONASS, and BDS.

This module features a charging port and can operate on a 3.7V lithium battery or through a 5V type-C interface. It includes a 3.5mm headphone jack which, when connected to headphones with a microphone, allows for phone calls. The compact design of the module facilitates easy integration into various IoT devices, catering to diverse application needs. Its low energy consumption and dependable operation make it a popular choice in sectors such as IoT, smart home technology, automotive, and industrial control.


Tools and materials

Tools and materials used in the video:

Other interesting boards from Elecrow:


Project Wiring

The project uses a NodeMCU board to control the module and the two are connected through UART. Tx on the module is connected to pin D5 on the NodeMCU and Rx is connected to pin D6.

Both modules are powered separately, so for the communication to work, it is necessary that we connect the GND pins of both boards so they have the same 0V reference.

The push buttons are connected to GND on one side, and on the other, they connect to pins D1 and D2.


Arduino Code to Make calls and send SMS

The NodeMCU is programmed with the help of the Arduino IDE and you have the full sketch below.

Based on the detected button press, the NodeMCU sends the right AT commands to instruct the 4G module to start/stop the call or send an SMS.

#include <SoftwareSerial.h>

#define DEBUG true

SoftwareSerial mySerial(D5, D6); // RX, TX pin of Arduino connected to TX, RX of the module

// push buttons connected to pin 5 and 6 
const int callButton = D1;
const int smsButton = D2;

// Change to the caregiver's phone number
const String caregiverNumber = "00389XXXXXXXX"; // replace with actual number
const String emergencyMessage = "Emergency! The elderly person needs help.";

bool inCall = false; // Flag to track the call status

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

  pinMode(callButton, INPUT_PULLUP);
  pinMode(smsButton, INPUT_PULLUP);
}

void loop() {
  int callButtonState = digitalRead(callButton);
  int smsButtonState = digitalRead(smsButton);

  if (Serial.available()){
    String content = Serial.readString();
    content.trim();
    sendData(content, 1000, DEBUG);
  }

  // Check call status to handle instances where the call is ended by the caregiver
  checkCallStatus();

  if (callButtonState == LOW && !inCall) {
    // Call caregiver
    Serial.println("Calling caregiver...");
    sendData("ATD" + caregiverNumber + ";", 1000, DEBUG); // Initiates a call
    inCall = !inCall; // Toggle the inCall flag
    delay(500); // Small delay for button debounce
  } else if (callButtonState == LOW && inCall) {
    // Hang up the call
    Serial.println("Hanging up...");
    sendData("ATH", 1000, DEBUG); // Hangs up a call
    sendData("AT+CHUP", 1000, DEBUG); // Hangs up a call
    inCall = !inCall; // Toggle the inCall flag
    delay(500); // Small delay for button debounce
  }

  if (smsButtonState == LOW && !inCall) {
    // Send emergency SMS
    Serial.println("Sending emergency SMS in UCS2 format...");
    sendData("AT+CMGF=1", 1000, DEBUG); // Set SMS mode to Text Mode
    sendData("AT+CSCS=\"UCS2\"", 1000, DEBUG); // Set character set to UCS2
    sendData("AT+CSMP=17,167,0,8", 1000, DEBUG); // Set SMS parameters
    sendData("AT+CMGS=\"" + toUCS2(caregiverNumber) + "\"", 1000, DEBUG); // Send UCS2 encoded phone number
    mySerial.print(toUCS2(emergencyMessage)); // Actual UCS2 encoded SMS text
    mySerial.write(26); // Ctrl+Z to end SMS input
    delay(1000); // Small delay for button debounce
  }

  delay(200); // Brief pause for button debounce
}

// Function for sending AT commands to SIM-A7670E module
String sendData(String command, const int timeout, boolean debug)
{
    Serial.print("Sending command: ");
    Serial.println(command);
    String response = "";    
    mySerial.println(command); 
    long int time = millis();   
    while( (time+timeout) > millis())
    {
      while(mySerial.available())
      {       
        char c = mySerial.read(); 
        response+=c;
      }  
    }    
    if(debug)
    {
      Serial.print(response);
    }    
    return response;
}

String toUCS2(const String& str) {
  String ucs2;
  for (unsigned int i = 0; i < str.length(); i++) {
    int code = str[i];
    char buf[5];
    sprintf(buf, "%04X", code); // Convert to UCS2 hex code
    ucs2 += buf;
  }
  return ucs2;
}

void checkCallStatus() {
  if (inCall) {
    String callStatus = sendData("AT+CLCC", 1000, false); // Check the current call status
    if (callStatus.indexOf("+CLCC: 1,0,6,0") != -1) { // Status 6 indicates call is ended
      inCall = false; // Reset the in-call flag if call has ended
      Serial.println("Call ended by caregiver.");
    }
  }
}


Other uses for the module

Making calls and sending SMS is the basic capability of the Crowtail-4G SIM A7670E Module. The module can also make HTTP, FTP, and MQTT requests making it a versatile choice for all IoT-related projects for smart homes, security systems, automotive and asset tracking, as wells as other industrial control applications.

In its direct configuration, when connected to a computer, the device can act as a 4G modem to provide Internet connectivity to the computer.

If you have ideas for projects that we can do with the module, feel free to reach out, and don't forget to subscribe to my channel for more interesting projects in the future.

4G prototype arduino GSM
Read next

Repair attempt on a broken Bluetooth Mini Speaker

What initially seemed like an easy repair, turned out to be a never-ending spiral of fault finding, micro soldering, and general electronics...

You might also enojy this

AC Dimming and AC Motor Speed Control How To with Arduino/NodeMCU

On my quest to building an Arduino controlled pellet burner, I needed a way that I can control the speed of an AC fan so I played around wit...