Arduino Uno连接SIM900 Shield无AT指令响应问题求助
Hey there! I see your Arduino Uno + SIM900 Shield works perfectly when running your SMS-sending code, but you can't get an "OK" response when sending AT commands manually via the Serial Monitor. Let's break down why this is happening and fix it step by step:
1. No Serial Traffic Bridge Between PC and SIM900
Your code uses SoftwareSerial (pins 7 and 8) to communicate with the SIM900, but the Serial Monitor connects to Arduino's hardware USB serial port (pins 0 and 1). Right now, there's no code to pass messages between these two ports—so your PC's AT commands never reach the SIM900, and the module's responses never make it back to your monitor.
Fix this by updating your code to act as a serial bridge:
#include <SoftwareSerial.h> SoftwareSerial SIM900(7, 8); void setup() { SIM900.begin(19200); // Add this to initialize hardware serial for Serial Monitor Serial.begin(19200); delay(20000); sendSMS(); } void loop() { // Forward SIM900's responses to Serial Monitor if (SIM900.available()) { Serial.write(SIM900.read()); } // Forward Serial Monitor commands to SIM900 if (Serial.available()) { SIM900.write(Serial.read()); } } void sendSMS() { SIM900.print("AT+CMGF=1\r"); delay(100); SIM900.println("AT+CMGS=\"+212625429762\""); delay(100); SIM900.println("Message example from Arduino Uno."); delay(100); SIM900.println((char)26); delay(100); SIM900.println(); delay(5000); }
2. Baud Rate Mismatch
Double-check that your Serial Monitor is set to 19200 baud—the exact same rate you used in SIM900.begin(19200);. If the rates don't match, you'll see garbled text (or nothing at all) instead of the expected "OK" response.
3. Incorrect AT Command Format
SIM900 expects AT commands to end with a carriage return (\r). When sending manually:
- Make sure you send
AT\r(not just "AT") - Stick to standard formatting (avoid extra spaces like
AT + CMGF=1—useAT+CMGF=1\rinstead) - Set the Serial Monitor's line ending option to "Both NL & CR"—this automatically appends the required
\r\nto your commands
4. Module Busy State (Unlikely, But Worth Checking)
After uploading your original code, the SIM900 might take a few seconds to finish processing the SMS or network registration. Wait 10-15 seconds after uploading the updated code before sending AT commands to ensure the module is idle.
Quick Test After Fixes:
- Upload the updated code with the serial bridge
- Set Serial Monitor to 19200 baud and "Both NL & CR"
- Send
AT—you should get an immediate "OK" response
That should resolve the issue! Let me know if you hit any other roadblocks.
内容的提问来源于stack exchange,提问作者amansour

