In embedded development, the Internet of Things, and debugging communication modules, there is an important tool that you will inevitably encounter — AT Commands.
Whether it is making calls and sending messages with GSM modules, connecting to the internet with WiFi modules, pairing with Bluetooth modules, or obtaining positioning with GNSS modules, AT commands serve as a bridge for human-machine communication.
What Can AT Commands Do? (Based on Module Scenarios)
The essence of AT commands is “sending text commands via serial port to directly control module functions“. Depending on the different modules, the tasks that AT commands can accomplish can be roughly divided into two categories:
① Mobile Communication Modules (GSM / GPRS / LTE)
-
Device Control: Power on the module, reset, query version information
-
Network Access: Register with the operator’s network, check signal strength
-
Calls and Messages: Make calls, send/receive messages
-
Mobile Data: PPP dial-up internet, establish TCP/UDP connections, report data to the server
② Terminal Communication Modules (WiFi / Bluetooth / GNSS)
-
WiFi Module: Connect to router, establish TCP/UDP, MQTT
-
Bluetooth Module: Search, pair, data transmission
-
GNSS Module: Enable positioning, output latitude and longitude, query positioning status
In simple terms: AT commands are the “remote control for modules”. In GSM/LTE modules, they can make calls, send messages, and access the internet;
In WiFi/Bluetooth/GNSS modules, they can connect to routers, pair with phones, and obtain positioning. Mastering AT commands allows you to directly operate all core functions of communication modules.
1. What are AT Commands?
AT commands (Attention Command) are a command set used to control modems or communication modules.
Today, they are widely used in:
-
Mobile Modules: GSM / GPRS / LTE modules (SIM800, Quectel, Fibocom)
-
Terminal Modules: WiFi modules (ESP8266, ESP32), Bluetooth modules (HC-05), GNSS modules (Neo-6M)
The essence is: sending “text commands” via serial port to control the behavior of the module.
In simple terms: the essence of AT commands is “send text commands, and the module will comply”. Originally used for modems, now almost all communication modules support them.
2. Basic Format of AT Commands
| Type | Description | Example |
|---|---|---|
| Test Command | Check if the module supports the parameter | <span>AT+CMD=?</span> |
| Query Command | Read the current configuration of the module | <span>AT+CMD?</span> |
| Set Command | Configure module parameters | <span>AT+CMD=parameter</span> |
| Execute Command | Perform a specific operation | <span>AT+CMD</span> |
General Rules:
-
All commands start with AT;
-
Commands end with Carriage Return (\r or \r\n);
-
The return results are usually:
-
<span>OK</span>: Execution successful -
<span>ERROR</span>: Command error or illegal parameter -
<span>+CMD: xxx</span>: Return query result
In simple terms: the format of AT commands is very regular: test, query, set, execute. Remember: they all start with AT and end with a carriage return, and a return of
<span>OK</span>means success.
3. Common Module AT Command Examples
Mobile Module (SIM800 as an example)
AT // Test if the serial port communication is normal
AT+CSQ // Query signal strength
AT+CREG? // Query network registration status
ATD10086; // Make a call
AT+CMGF=1 // Set SMS to text mode
AT+CMGS="phone number" // Send SMS
WiFi Module (ESP8266 as an example)
AT // Test if the module responds
AT+CWMODE? // Query current working mode
AT+CWMODE=1 // Set to Station mode
AT+CWJAP="SSID","PWD" // Connect to WiFi
AT+CIPSTART="TCP","ip",port // Establish TCP connection
AT+CIPSEND=5 // Prepare to send data
GNSS Module (ATGM as an example)
AT+CGPS=1 // Turn on GPS
AT+CGPSINFO // Get positioning information
AT+CGPSSTATUS? // Query positioning status
In simple terms: the AT commands for different modules are quite similar: GSM modules can make calls and send messages, WiFi modules can connect to the internet and transmit data, and GNSS modules can obtain latitude and longitude. It is a set of “question-and-answer language” that does the job wherever it is used.
4. AT Command Debugging Tools
Common serial port debugging tools:
-
Windows: SSCOM, XCOM, SecureCRT
-
Arduino IDE Serial Monitor (suitable for ESP32, Bluetooth, etc.)
-
Linux: minicom, picocom
Common serial port configurations:
-
Baud Rate: 9600 / 115200 (depending on the module)
-
Data Bits: 8
-
Stop Bits: 1
-
Parity: None
-
End Character:
<span>\r</span>or<span>\r\n</span>
In simple terms: To communicate with the module, you need a “serial port chat tool”. Configuring the baud rate and end character correctly is essential for the module to understand you.
5. Practical Debugging Tips
-
Check Serial Port Connectivity:
<span>AT</span>→ returns<span>OK</span>if normal -
Module “Hangs”: Use
<span>AT+RST</span>to reset, or check if the power supply is sufficient -
Batch Testing Commands: Use the “macro command/script” feature of the serial port assistant to send automatically
In summary: Debugging secret: first send
<span>AT</span>to see if you get<span>OK</span>; if not, reset + check power supply, and if there are many commands, use scripts for efficiency.
6. Custom AT Commands (Advanced Play)
In STM32 / MCU projects, you can also write your own AT commands by mimicking the modules:
if (strncmp(cmd, "AT+LED=ON", 9) == 0) {
led_on();
send_response("OK\r\n");
} elseif (strncmp(cmd, "AT+LED=OFF", 10) == 0) {
led_off();
send_response("OK\r\n");
} else {
send_response("ERROR\r\n");
}
In simple terms: You can not only use the AT commands of the module but also write your own. Others can control your device just by sending commands, which is the fun of DIY.
7. Frequently Asked Questions (FAQ)
-
Q: Can AT commands send Chinese characters?A: Not directly, most modules only support ASCII and need to be converted to UCS2/PDU.
-
Q: Why do I get an ERROR response?A: Illegal parameters, format errors, the module is not initialized, or does not support that state.
-
Q: Why is the response slow?A: The module needs to wait for initialization, for example, GSM modules take 5-10 seconds to power on.
In simple terms: Common pitfalls with AT commands: Chinese needs encoding; ERROR is mostly a command/state issue; slow response is because the module is not ready yet.