This Journey can take you a head toward the wireless communication and the automatic control techniques that may help you start your great projects. It also can provide you with some important commands and processes that everyone can follow and apply then eventually be a creative one.
At the first, I going to explains some important AT command that Arduino Libraries used such as the great GSM library. You may wonder why to understand the AT Command while there is a helpful and great library can every used.
So Why AT command ?!.
I can say that there is a great library and easy to use, but we can't ignore the size of a program while including more than one library in one multi functions great program. The great program can become not stable and heavy in hex file result in poor in performance and mistakes could occurred while operating that great program.
On the other hand, AT command is much lighter, faster, and Errors can be easily detect beside a general purpose famous ("Software Serial Library")that can combine with other libraries in more efficient way. The only challenge is to be considering how much delay time each Command need to execute probably. This all information can be found in the Quectel M10 Data sheet.
Quectel M10 At command file is the only document you need in order to start write your own program for your great project. I`m highly recommend you going through the PDF file, Its has such a valuable information I hope you like.
If you understand what going on here, I expect you to have the ability to make a smart home, some security and safety applications, real time monitoring systems, wireless control systems. And you may create your cool project that I did not think about. Please make cool things and share them so we can learned more.
In this Journey I will cover the Arduino GSM shield in this Area:
- Making a real-time GPS tracking via SMS.
_Hardware_
- Arduino GSM Shield 2.
- Arduino Uno OR Arduino Mega 2560/ADK.
- Breadboard/ Jumper Wires.
- Adafruit Ultimate GPS Breakout.
- Waterproof GPS Active Antenna.
- Lithium Ion Battery Pack.
- Lithium Ion/Polymer Charger.
- 5V USB Boost.
- Power Adapter. ( Optional you can use instead of the solar system).
- Sim Card !!!. ( Depends on your country).
_ Software_
- Arduino IDE.
- Terminal Emulator. ( you can download OR use any other program you like).
_Libraries required_
Step 2: The Arduino GSM Shield !! (Overview):Description
The Arduino GSM Shield allows an Arduino board to connect to the internet, make/receive voice calls and send/receive SMS messages. The shield uses a radio modem M10 by Quectel (datasheet). It is possible to communicate with the board using AT commands. The GSM library has a large number of methods for communication with the shield. The shield uses digital pins 2 and 3 for software serial communication with the M10. Pin 2 is connected to the M10’s TX pin and pin 3 to its RX pin. See these notes for working with an Arduino Mega, Mega ADK, or Leonardo. The modem's PWRKEY pin is connected to Arduino pin 7. The M10 is a Quad-band GSM/GPRS modem that works at frequencies GSM850MHz, GSM900MHz, DCS1800MHz and PCS1900MHz. It supports TCP/UDP and HTTP protocols through a GPRS connection. GPRS data downlink and uplink transfer speed maximum is 85.6 kbps. To interface with the cellular network, the board requires a SIM card provided by a network operator. See the getting started page for additional information on SIM usage. The most recent revision of the board uses the 1.0 pinout on rev 3 of the Arduino Uno board.
Power requirements
It is recommended that the board be powered with an external power supply that can provide between 700mA and 1000mA. Powering an Arduino and the GSM shield from a USB connection is not recommended, as USB cannot provide the required current for when the modem is in heavy use. The modem can pull up to 2A of current at peak usage, which can occur during data transmission. This current is provided through the large orange capacitor on the board's surface.
On board indicators
The shield contains a number of status LEDs:
On: shows the Shield gets power.
Net: blinks when the modem is communicating with the radio network.
- Status: turns on to when the modem is powered, and data is being transferred to/from the GSM/GPRS network.
- Net: blinks when the modem is communicating with the radio network.Status: turns on to when the modem is powered, and data is being transferred to/from the GSM/GPRS network.
- On: shows the Shield gets power.Net: blinks when the modem is communicating with the radio network.Status: turns on to when the modem is powered, and data is being transferred to/from the GSM/GPRS network.
For more Information see Getting Started with the Arduino GSM Shield
Also you can see GSM library.
The datasheet for the Quectel M10 modem can be found here.
Step 3: Getting Started!We will use two methods:
- The Terminal Emulator. (brief introduction see pics)
- Using Arduino code (Uno/Mega) compatible.
Now we will prepare the Arduino board for communicating with the PC by UART protocol. Emulate a second serial port (UART) using software on the digital pins D2 and D3 and patch through all the communication between this second software serial port and the actual hardware serial port. By doing this, all the data coming from the computer (connected to the actual hardware UART) would be relayed as is to the GPRS Shield (connected to software UART).
- Run Arduino IDE 1.0 or later
- Download the the terminal emulate codes and upload to your arduino.
Now all done to start use Arduino with either method.
1. Using AT commands Via
- Open your favorite serial terminal software, choose the COM port for Arduino and press connect.
- Press and hold the power button a short while (Over 3 seconds) on the GMS Shield to turn it on.
- Now, type and send "AT" (without the quotes) followed by carriage return (enter key) to the Arduino board. The GPRS Shield should respond by sending back an "OK". This would mean that you have been able to successfully setup your GPRS Shield can now play around with various AT Commands.
Sending a text message (SMS) –AT COMMAND
- Install GSM shield in Arduino board and connect power cord.
- Open your serial monitor program (I use SSCOM)
- Through your serial terminal software, send AT+CMGF=1 and press the Enter key. The GPRS Shield can send SMSes in two modes: Text mode and PDU (or binary) mode. Since we want to send out a human readable message, we will select the text mode. The GPRS Shield will respond with an OK.
- Send AT+CMGS="+966XX6541231" and press the Enter key (include the quotes). This will instruct the GPRS Shield to start accepting text for a new message meant for the phone number specified (replace the number with the phone number of the target phone). The GPRS Shield will send a > signaling you to start typing the message at the last of the massage type "*" (without the quotes).
Make a Call –AT COMMAND
- Type ATD 0566996070; // Write phone number you want to call
- Respond OK, you will receive a call.
- Type ATH to end a call.
GPS tx/rx to the arduino digital pins 8/9
This program can provide user by GPS location if a SMS is sent.
please connect tx/rx of the GPS to arduino digital pin 8 / 9.
SEND Do to have the location
The Codes!!
<p>/********************************************************************<br> * AltSoftSerial always uses these pins for Serial communication: *
* *
* Board Transmit Receive PWM Unusable *
* ----- -------- ------- ------------ *
* Teensy 3.0 & 3.1 21 20 22 *
* Teensy 2.0 9 10 (none) *
* Teensy++ 2.0 25 4 26, 27 *
* Arduino Uno 9 8 10 *
* Arduino Leonardo 5 13 (none) *
* Arduino Mega 46 48 44, 45 *
* Wiring-S 5 6 4 *
* Sanguino 13 14 12 *
*********************************************************************/</p>
<p>#include <br>#include
#include
SoftwareSerial GPRS(2, 3); // RX, TX
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
AltSoftSerial ss;
char c;</p><p>void setup() {
pinMode(12,OUTPUT);
pinMode(7, OUTPUT);
Power_gsm();
ss.begin(9600); // begin the GPS serial connection
GPRS.begin(9600); // Start software serial
delay(2000);
GPRS.println("AT+CMGF=1"); // AT+CMGF Select SMS Massage Format
delay(100);
GPRS.println("AT+CNMI=1,2,0,0,0"); // AT+CNMI New SMS Massage INdication
delay(100);
GPRS.println("AT+CMGD=1,4"); // AT+CMGD=1,4 Range of SMS on SIM card Can be deleted
delay(1000);
//SMSsend("SYSTEM IS ON:)");//2
GPRS.flush(); // deleting all massages at the first boot
delay(100);
}</p>
<p>void loop() {</p><p> while (ss.available() > 0)
if (gps.encode(ss.read()))
while (GPRS.available()) {
delay(3);
c = GPRS.read();
if (c == 'D') {
if (GPRS.available()) {
delay(3);
c = GPRS.read();
if (c == 'o') {
digitalWrite(12,HIGH);
Senddata();
}
else if (c == 'c') {
digitalWrite(12, LOW);
}
}
}
}
GPRS.flush();
}</p>
<p>void Power_gsm() {<br> digitalWrite(7, HIGH);
delay(3000);
digitalWrite(7, LOW);
}</p>
<p>void Senddata() {<br> GPRS.print("AT+CMGF=1\r"); // Carriage return
delay(100);
GPRS.println("AT+CMGS=\"+966566996070\""); // replace x by your number ("AT+CMGS=\"+966xxxxxxxxx\""); to yours
delay(100); // (+966) is the country code replace it with yours
GPRS.print("https://www.google.com/maps/place/");
GPRS.print(gps.location.lat(), 6);
GPRS.print(",");
GPRS.print(gps.location.lng(), 6);
GPRS.println((char)26);
GPRS.println();
delay(100);
GPRS.println("AT+CMGD=1,4"); // some AT Commands
delay(100);
GPRS.println("AT+CMGF=1");
delay(100);
GPRS.println("AT+CNMI=1,2,0,0,0");
delay(200);
}</p>
You can have HERE
OR you can choose arduino GSM library (another code for same function)
#include <GSM.h>
#include <TinyGPS++.h>
#include <AltSoftSerial.h> //Include all relevant libraries - see above
#define PINNUMBER "" // PIN Number for the SIM - leave blank unless your SIM has a pin, this is inserted between ""
static const uint32_t GPSBaud = 9600; //Baud rate for communication with the GPS, Adafruit GPS = 9600, your GPS may well be 4800, check the spec
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
AltSoftSerial ss; // The serial connection object to the GPS device
String yourPassword = "1234"; // Put the password here between the ""
String password; // Temporary variable used for comparison of passwords
GSM gsmAccess; // Initialise the library instances
GSM_SMS sms;
char senderNumber[20]; // Array to hold the number a SMS is retreived from
void setup()
{
ss.begin(GPSBaud); // begin the GPS serial connection
Serial.begin(9600); // begin Serial communication with the computer at 9600 baud rate
Serial.println("Where is my Car?"); // Print to the computer
Serial.println("Initialising...");
boolean notConnected = true; // connection state
while (notConnected) // until it connects
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY) // if it succeeds connecting
notConnected = false; // connected
else
{
Serial.println("Not connected"); // print to the computer
delay(1000); //delay
}
}
Serial.println("GSM initialized"); // print to the computer
Serial.println("Waiting for messages");
}
void loop()
{
while (ss.available() > 0) //while there is stuff in the buffer
if (gps.encode(ss.read())) //if it can successfully decode it, do it. Else try again when more charachters are in the buffer
if (sms.available()) // if a text has been recieved
{
Serial.println("Message received from:"); // print to the computer
sms.remoteNumber(senderNumber, 20); // assign the sender number to the "senderNumber" variable
Serial.println(senderNumber); // print the sender number to the computer
password = ""; // flush the temporary variable
char c;
while (c = sms.read())
{
password += c; // append the sms to the "password" variable
}
Serial.println(password); // print the contents of the sms
Serial.println("\nEND OF MESSAGE"); // print to the computer
sms.flush(); // delete message from modem buffer
Serial.println("MESSAGE DELETED"); // print to the computer
if (password == yourPassword) // if the sms contains the correct password
{
Serial.println("\nPASSWORD VALID"); // print to the computer
sms.beginSMS(senderNumber); // begin an sms to the sender number
sms.print("https://www.google.com/maps/place/");
sms.print(gps.location.lat(), 6); // append the lat to the sms
sms.print(","); // append a comma
sms.print(gps.location.lng(), 6); // append the lon to the sms
sms.endSMS(); //send the sms
}
else {
Serial.println("\nPASSWORD NOT VALID"); // print to the computer
}
}
delay(1000); // delay
}
Comments