Receive an SMS on an Arduino Uno
The GSM receive sketch on a SIM900A, on a simulated network: type sms hello in the modem’s serial box and the Uno prints the +CMT line and the text. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The parts retail for about $43. On Mokxi they're free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Receive an SMS: the "receive" sketch the GSM tutorials print, here on a
// SIM900A board.
//
// SIM900A TXD -> pin 3 (the sketch's RX)
// SIM900A RXD <- pin 2 (the sketch's TX)
// SIM900A VCC -> a 5 V 2 A adapter, GND -> the adapter's - and the Uno's GND
//
// The SIM900A board's regulator takes 5 V, but the modem draws 2 A when it
// transmits, more than the Uno's 5 V pin can give: it has an adapter of its own.
//
// AT lets the modem's autobaud find 9600 baud, AT+CMGF=1 picks text mode, and
// AT+CNMI=1,2,0,0,0 asks for every new message to be printed as it arrives,
// as +CMT with the number and the time, then the text.
//
// There is no real phone network here. The modem has its own line in the
// serial monitor, and that line is the simulated network: type sms hello in it
// and the Uno prints the message. Type AT commands in the Uno's line to talk
// to the modem yourself.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); // RX, TX: the SIM900A's TXD and RXD
void updateSerial() {
delay(500);
while (Serial.available()) {
mySerial.write(Serial.read()); // the serial monitor to the modem
}
while (mySerial.available()) {
Serial.write(mySerial.read()); // the modem to the serial monitor
}
}
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); // the handshake: the modem answers OK
updateSerial();
mySerial.println("AT+CMGF=1"); // text mode
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0"); // print new messages as they come
updateSerial();
}
void loop() {
updateSerial();
}
Parts list
3 parts, plus the jumper wires. They retail for about $43; on Mokxi they're free.
How it is wired
4 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; GSM modem, SIM900A pin GND; DC jack and adapter pin V-
- Arduino Uno R3 pin 3; GSM modem, SIM900A pin TXD
- Arduino Uno R3 pin 2; GSM modem, SIM900A pin RXD
- GSM modem, SIM900A pin VCC; DC jack and adapter pin V+
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.