Back to Tutorial

ESP32 with SIM900A GSM Module


📡 What is SIM900?

The SIM900 is a GSM/GPRS module from SIMCom. It allows microcontrollers like ESP32 or Arduino to:

✅ Send/receive SMS
✅ Make/receive phone calls
✅ Connect to the Internet (GPRS)
✅ Send data to servers via HTTP, MQTT, TCP/IP

It communicates via UART (TX/RX) and uses AT commands.


📦 Features of SIM900

FeatureDescription
Network2G GSM (850/900/1800/1900 MHz)
CommunicationUART (AT commands)
Baud RateDefault 9600
SIM CardStandard-size SIM (2G supported)
Power Supply5V–12V, 2A recommended
AntennaRequired for GSM signal
OptionalMic & Speaker (for calls)

🔌 SIM900 to ESP32 Connection

SIM900 PinESP32 Pin
TXGPIO 16 (ESP32 RX)
RXGPIO 17 (ESP32 TX)
GNDGND
VCC⚠️ External 5V 2A power supply

⚠️ DO NOT power SIM900 directly from ESP32 or USB. It needs high current, especially during network operations.


🧾 Arduino Code Example – Sending SMS with ESP32 + SIM900

🧰 Libraries Required:

You don’t need extra libraries – just Serial and AT commands.

⚙️ Wiring

  • SIM900 TX → ESP32 RX (GPIO 16)
  • SIM900 RX → ESP32 TX (GPIO 17)
  • SIM900 GND ↔ ESP32 GND
  • SIM900 VCC → External 5V 2A📱 Other Useful AT Commands:CommandFunctionATCheck moduleAT+CSQSignal strengthAT+CCIDSIM card numberAT+CREG?Network registrationATD+91XXXXXXXXXX;Make a callATHHang upAT+CMGR=1Read SMS from slot 1AT+CMGD=1Delete SMS from slot 1⚙️ Using Serial Monitor to TestYou can manually send AT commands via Serial Monitor using this setup:
    • Use Serial passthrough sketch to forward Serial to SIM900.
    📡 Real-World Projects Using SIM900 + ESP32ProjectDescription🚨 GSM Alarm System   Send SMS when motion or fire is detected📦 Asset Tracker  Send location data via SMS (with GPS)🛜 IoT without WiFi  Use GPRS to send data to cloud🔐 Smart Door Lock  Unlock with OTP via SMS📈 Remote Sensor  Send sensor values (temperature, moisture, etc.) to phone⚠️ Power Supply Tips
    • SIM900 can draw up to 2A peak. If underpowered, it may restart or fail to send SMS.
    • Use external power supply (e.g., 5V 2A adapter or battery pack).
    • Keep GND common between ESP32 and SIM900.
    ❓ Common Issues and FixesProblemSolutionNo SMS sent  Check SIM is active, balance, and signalModule keeps restarting  Power supply issue – use 2A sourceAT commands don’t respond  Check TX/RX pins or baud rate”SIM not inserted”Clean SIM contacts and reinsert
HOW TO OPERATE

 


// Define ESP32 hardware serial port for SIM900
#define SIM900_TX 17  // ESP32 TX connected to SIM900 RX
#define SIM900_RX 16  // ESP32 RX connected to SIM900 TX
#define PWRKEY 4      // SIM900 Power Key pin (adjust if needed)
#define GSM_BAUD 9600
// Initialize hardware serial for SIM900
HardwareSerial sim900(2);

void powerOnSIM900() {
    pinMode(PWRKEY, OUTPUT);
    digitalWrite(PWRKEY, LOW);
    delay(1000);  // Hold PWRKEY low for 1 second
    digitalWrite(PWRKEY, HIGH);
    delay(9000);  // Wait for the module to initialize
}

void setup() {
    Serial.begin(115200);  // Serial Monitor
    sim900.begin(GSM_BAUD, SERIAL_8N1, SIM900_RX, SIM900_TX);  // SIM900 UART
   
    powerOnSIM900();

    Serial.println("Testing AT communication...");
   
    // Test AT command
    sendATCommand("AT");

    // Set SMS text mode
    sendATCommand("AT+CMGF=1");

    // Send SMS
    Serial.println("Sending SMS...");
    sim900.println("AT+CMGS=\"+919305706040\"");  // Replace with recipient's number
    delay(1000);
    sim900.print("Hello from ESP32 and SIM900");
    sim900.write(26); // CTRL+Z to send
    delay(5000);
    printResponse();
}

void loop() {
    // Add code to handle incoming messages or other functionalities
}

// Function to send an AT command and print response
void sendATCommand(const char *command) {
    Serial.print("Sending: ");
    Serial.println(command);
    sim900.println(command);
    delay(1000);
    printResponse();
}

// Function to print response from SIM900
void printResponse() {
    while (sim900.available()) {
        Serial.write(sim900.read());
    }
    Serial.println("----------------------");
}
ESP32 with SIM900A GSM Module

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial