ThisCalculator

Everyday

AT Commands: Control Modems & Mobile Devices

Updated · Standard formula, shown below

AT commands are a set of text-based instructions that let you directly control modems, mobile phones, and other communication hardware. They allow you to send SMS, make calls, check signal strength, configure network settings, and more—all from a terminal or script. This guide explains what you need and walks you through using AT commands step by step.

What You’ll Need

  • A device that supports AT commands: a USB modem, GSM/GPRS module, or a smartphone with an AT command interface (often via a serial terminal app).
  • A way to communicate with the device: a USB-to-serial adapter, a terminal program (like PuTTY or minicom), or a programming language with a serial library (e.g., Python with pyserial).
  • The correct driver for your device (usually installed automatically or available from the manufacturer).
  • The COM port number (Windows) or device name (Linux/macOS) that your device is assigned.
  • Basic familiarity with a terminal or command line.

Step-by-Step

  1. Connect your device to your computer via USB, serial cable, or Bluetooth. Make sure it’s powered on and recognized by your OS.
  2. Find the correct port:
    • Windows: Open Device Manager, expand “Ports (COM & LPT)”. Note the COM number (e.g., COM3).
    • Linux: Run ls /dev/ttyUSB* or ls /dev/ttyACM* to see the device (e.g., /dev/ttyUSB0).
    • macOS: Run ls /dev/cu.* to see the serial device.
  3. Open a serial terminal (PuTTY, minicom, screen, or a custom script). Configure it with the correct port, baud rate (usually 9600 or 115200), 8 data bits, no parity, 1 stop bit, and no flow control.
  4. Test the connection: Type AT and press Enter. The device should respond with OK. If you get nothing, check your port and baud rate.
  5. Get basic device info: Send ATI to see the manufacturer/model, and AT+CGMI, AT+CGMM, AT+CGMR for manufacturer, model, and firmware version.
  6. Check signal strength: Send AT+CSQ. The response is +CSQ: <rssi>,<ber>. The first number is signal strength (0-31, with 31 being excellent, 99 means no signal).
  7. Send an SMS:
    1. Set text mode: AT+CMGF=1 and wait for OK.
    2. Send the message: AT+CMGS="+1234567890" (replace with the recipient’s number). Press Enter, then type your message, and end with Ctrl+Z (ASCII 26). The device will respond with +CMGS: <index> and OK.
  8. Make a voice call: Send ATD+1234567890; (note the semicolon at the end). The device will dial. To hang up, send ATH.
  9. Answer an incoming call: Send ATA.
  10. Read SMS messages: After setting text mode (AT+CMGF=1), send AT+CMGL="ALL" to list all messages, or AT+CMGR=<index> to read a specific one.
  11. Check network registration: Send AT+CREG?. Response +CREG: 0,1 means registered on home network; 0,5 means registered roaming.
  12. Set APN for data (if needed): AT+CGDCONT=1,"IP","your.apn" then AT+CGACT=1,1 to activate the PDP context.
  13. Close the connection: When done, exit the terminal properly (e.g., in PuTTY, just close the window; in minicom, Ctrl+A then X).

Common Mistakes

  • Wrong baud rate: If you see garbled characters or no response, try other common rates (4800, 9600, 19200, 115200).
  • Forgetting the semicolon for calls: ATD12345 (without semicolon) may attempt a data call, not a voice call. Always use ATD12345; for voice.
  • Not waiting for OK: Some commands require a pause before the next one. Sending too fast can cause errors.
  • Using wrong line endings: Most devices expect carriage return (\r) only, not line feed. In PuTTY, set “Implicit CR in every LF” or use a script that sends \r.
  • Incorrect SMS number format: Use international format with + and country code, e.g., +14155552671.
  • Not checking device power: Some modules need a separate power button or a GPIO pin to be enabled.

Tips

  • Use a terminal that shows non-printable characters (like line feeds) to debug responses.
  • For scripting, use Python with pyserial to automate AT commands. Example: ser.write(b'AT\r') and read the response.
  • Always read the device’s AT command manual—each manufacturer has slight variations.
  • Use AT&F to reset to factory defaults if you mess up settings.
  • For GPS modules, use AT+CGPSINFO or similar to get location data.
  • Test with a simple command first (like AT) to confirm communication before trying complex operations.

Troubleshooting

  • No response to AT: Check that the device is powered, the port is correct, and the baud rate matches. Try a different USB port or cable.
  • Garbled output: Usually a baud rate mismatch. Try all common rates.
  • Error messages: If you get ERROR, the command syntax may be wrong. Check the manual for exact command format. Some commands require a preceding setup (e.g., AT+CMGF=1 before SMS).
  • Device not recognized by OS: Install the correct driver. For some modules, you may need to install a virtual COM port driver.
  • Commands work but SMS not sent: Ensure you have a valid SIM with credit, the number is correct, and the device is registered on the network (AT+CREG?).
  • Call fails: Check signal strength (AT+CSQ) and that the number is in international format with a semicolon.

Frequently Asked Questions

What does AT stand for?

AT stands for “Attention”. It’s a prefix that tells the modem that a command follows.

Can I use AT commands on any phone?

Most phones with a serial interface (like older models or Android with a USB-to-serial app) support AT commands. Modern smartphones often hide this interface, but USB modems and GSM modules work well.

How do I find the correct baud rate?

Common rates are 9600 and 115200. Check the device’s datasheet. If unsure, try a few—some devices auto-detect.

Is it possible to send AT commands over Bluetooth?

Yes, if the device supports Bluetooth SPP (Serial Port Profile). Pair the device, find the COM port (Windows) or /dev/rfcomm0 (Linux), and connect as usual.

Can AT commands damage my device?

Most commands are safe, but some (like AT&F or firmware update commands) can reset or alter settings. Avoid unknown commands from untrusted sources.

How do I exit AT command mode?

There’s no universal exit. For modems, you can send ATO to return to data mode if in online mode, or just close the terminal. For phones, you may need to disconnect the serial connection.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.