GSM Cellphone (mobile) controller : AT commands
by Fahad Mirza
This project is about controlling various appliances without even touching it. Of course I mean on/off for now! And the controlling will be done by a mobile. Just send the instruction through the sms, device will decode it and take action accordingly. The device includes a microcontroller and a GSM modem. Instead of GSM modem you can use any cell phone.
Those who don’t know, any GSM modem or cell phone is based on AT (Attention) commands set. If you google, you can find the complete instruction. I use these instructions:
ATE0 – For turn off echo.
AT+CMGF – For choosing Text Mode.
AT+CNMI – For identification of new sms.
AT+CPMS – For preferred message storage.
AT+CMGD – For delete message.
AT+CMGR – Read message from.
AT+CMGS – For sending message.
The project controls a light (on/off) through a relay. It also can send back the status of the light (on/off). When you turn on the device it starts to initialize the modem. The GSM modem returns every instruction you give.
So for less traffic I turned it off by ATE0. Then it changes the sms mode in TEXT by AT+CMGF.
Those who don’t know, GSM devices have two types of sms mode TEXT and PDU. PDU is a little bit complicated. Then it configure what will modem do if a new message received by AT+CNMI. By AT+CPMS it set where will be message stored, which is for my project is SIM. That’s it!
Now the device will be waiting for any new messages. The messages I can send are: “Light on” / ”Light off” / “Status”. If you send anything other then these then device will be replied with a message “Invalid”.
Suppose I send the message “Light on” then the modem will send uC a message +CMTI: “SM”, 1. Where SM is where msg is stored and 1 is at what index.
When uC get CMTI, then it knows there is new sms.
So then it will send AT+CMGR to read the message and compare it with some pre-defined string. If it is Light on/off, then it will do so by on/off the relay.
If it is “Status” then it will check either relay is on/off and send sms in a predefined number.
Then it delete the sms by AT+CMGD and again wait for the new sms.