We control the socket via SMS. Budget GSM alarm with Arduino brains

An article for those who want to force Arduino to send SMS through this GSM module . The NEOWAY M590 module based on the SIM900 chip is suitable for creating homemade alarm system, smart home. There is also an alternative GSM module that connects directly to Arduino via 5 Volts: Sim800L EVB v2.0

Formulation of the problem

  • Using only Arduino and a GSM module, control the LED via a call from your phone.
  • Send SMS (while via a command coming through the port monitor in the Arduino IDE)

Connecting to Arduino

We connect the GSM module to Arduino.
5V module -> 5V Arduino
Module GND -> Arduino GND
TX module -> digital pin2 Arduino
RX module -> digital pin3 Arduino
The pinout can be seen in the photo. The order of contacts is as follows: 1 - +5V, 2 - GND, 7 - TX, 8 - RX.


The module can be powered from 4V to 5V, I used the 5 volt output.

The module requires separate power because it consumes up to 2A at peak. A capacitor most likely won't help. Therefore, when powered by Arduino, it may not work or may fail.

The ground of the Arduino and the GSM module with separate power supply must be connected, but first you need to measure the voltage between these “grounds” with a multimeter. Some computer blocks The power supplies have a potential drop across the case and USB ground of up to 100V. The current there is tiny and cannot kill, but it is easy to destroy an Arduino or a GSM module or both together.

Sketch

#include< SoftwareSerial. h> SoftwareSerial mySerial(2, 3); // RX, TX int ch = 0 ; int led = 13 ; String val = "" ; void setup() (
delay(2000); //time to initialize the module pinMode (led, OUTPUT) ; digitalWrite(led, LOW); Serial. begin(9600); //port speed Serial. println ("GSM tester v1.0" ) ; mySerial. begin(9600); mySerial. println ("AT+CLIP=1" ) ; //turn on caller ID delay (100) ; mySerial. println ("AT+CMGF=1" ) ; //SMS encoding mode - normal (for English) delay(100); mySerial. println("AT+CSCS=\"GSM\"" ) ; //text encoding mode delay(100); ) void loop () ( if (mySerial . available () ) ( //if the GSM module sent us something, then while (mySerial.available()) ( //save the input string into the val variable ch = mySerial. read(); val += char (ch); delay(10); ) if (val . indexOf ( "RING" ) > - 1 ) ( //if a call is detected, then check the number if (val . indexOf ( "71234567890" ) > - 1 ) ( //if the caller's number is ours. Enter your number without "+" Serial. println( "--- MASTER RING DETECTED ---") ; mySerial. println("ATH0"); //break the connection digitalWrite(led, HIGH); //turn on the LED for 3 seconds delay(3000); digitalWrite(led, LOW); //turn off the relay ) ) else Serial. println(val); //print the received line to the port monitor val = "" ; ) if ( Serial. available () ) ( //if something is entered in the port monitor while ( Serial. available () ) ( //save the string to the variable val ch = Serial. read(); val += char (ch); delay(10); ) //mySerial.println(val); //transfer of all commands typed in the port monitor to the GSM module if (val . indexOf ( "sendsms" ) > - 1 ) ( //if you see the command to send SMS sms(String("hello world"), String("+71234567890")); //send SMS to number +71234567890) val = "" ; //clear ) ) void sms (String text , String phone ) //procedure for sending SMS { Serial. println("SMS send started" ) ; mySerial. println ("AT+CMGS=\"" + phone + "\"" ) ; delay(500); mySerial. print(text); delay(500); mySerial. print ((char ) 26 ) ; delay(500); Serial. println("SMS send complete"); delay(2000); )

Examination


GPRS

In the module version 1.30 under review, GPRS support is reduced. I was unable to connect to the server by its DNS name (for example mysite.ru), I only succeeded by its IP address. There were no such problems in the other SIM800L module.

List of some AT commands:

This library allows you to perform most of the basic operations performed by a GSM phone: work with voice calls, send and receive SMS, and connect to the Internet via GPRS.

The GSM expansion board contains a modem that transmits data received to it via the GSM network. serial port. All operations are performed by the modem as a sequence of AT commands. To improve code readability, the library abstracts low-level functions that work with the modem and SIM card. The GSM modem interacts with Arduino via a serial interface using the SoftwareSerial library.

Each command executed by the modem, as a rule, is a fragment of a sequence of commands aimed at performing a function. The GSM library is designed with this in mind, and is capable of receiving/returning information at any stage of the command sequence.

Library structure

The functionality of the GSM library is quite wide, so it combines several various classes:

  • Class GSM is responsible for controlling the radio modem. This class contains low-level functions for connecting and registering an expansion card in a GSM network. An instance of this class must be declared in all programs that use GSM/GPRS.
  • Class GSMVoiceCall is responsible for voice calls.
  • Class GSM_SMS is responsible for sending and receiving SMS messages.
  • Class GPRS is responsible for connecting to the Internet.
  • In class GSMClient a client similar to the client in the Ethernet and WiFi libraries has been implemented.
  • In class GSMServer a server similar to the server in the Ethernet and WiFi libraries has been implemented. Note: Some ISPs/operators block incoming connections from global Internet network, allowing only intranet connections. Check with your carrier for applicable data restrictions.
  • Lots of helper classes like GSMScanner, GSMModem and etc.

Ethernet library compatible

The developers have made every effort to ensure that the GSM library is as compatible as possible with the Ethernet library. Thanks to this, transferring code that uses Ethernet or WiFi libraries to an Arduino with a GSM expansion board should be quite simple. However, to run programs written for Ethernet on a GSM expansion card, it is not enough to simply copy the code. This may require minor changes in the program, such as connecting GSM and GPRS libraries, obtaining network settings from the provider, etc.

Examples

All examples of working with a GSM expansion card can be divided into two groups. The first group is examples demonstrating the board's capabilities (for example, sending SMS messages, connecting to the Internet, etc.). The second group is tools with which you can debug the functionality of the Arduino library and hardware at a low level.

You can also send SMS messages, all you need for this is a special module Arduino GSM/GPRS SIM900. This board The extension is suitable for common Arduino UNO, MEGA and Leonardo boards. With its help you can make a bunch of different projects using GPRS internet or access to GSM network. It will work wherever it is mobile network. Using this module you can do GSM alarm, which, together with a video surveillance system, will provide excellent protection for your home.

The module allows you to use networks of GSM 850, GSM 900, GSM 1800, GSM 1900 standards and supports TCP protocol with access to the GPRS network.

Arduino GSM The SIM900 module can also be used to make calls; you can both receive and make calls. For this purpose, the board has special connectors for connecting a microphone and speaker. The module can also be connected to a computer and send and receive data directly from the PC. For example, you can do mass mailing to subscribers recorded on the SIM card in automatic mode.

Features of connecting the GSM board to Arduino Leonardo and Arduino Mega boards

The GSM expansion board works with Arduino directly thanks to the Software Serial library. At standard settings, to interact with the modem and Arduino, digital pins No. 2 and No. 3 are connected. Arduino Uno These settings are suitable, but for proper operation shield on Arduino Leonardo or Arduino Mega amendments need to be made.

The GSM_TX pin, also called pin #2 on the expansion board, sends information to Arduino. To know exactly at what moment it is necessary to read information, Arduino uses an interrupt mechanism: when changing digital level signal at this pin, a corresponding interrupt occurs. However, on Arduino Leonardo and Arduino Mega, pin #2 does not support interrupts.

In order for the shield to function normally on Arduino Mega or Leonardo, you don’t need to change it at all program code, the library itself changes the Arduino RX pin number when selecting the appropriate model in the "Tools" menu of the development environment.

Arduino Leonardo


To function correctly with Leonardo, the GSM library uses digital pin No. 8. To do this, digital pins No. 2 and No. 8 must be connected with a conductor on the GSM expansion board.

On the back of the GSM board, you need to bend the pin corresponding to pin No. 2 to the side so that it does not come into contact with the Arduino Leonardo.

Arduino Mega2560


The GSM library for correct operation with Mega uses digital pin No. 10. On the GSM expansion board, it is necessary to short-circuit digital pins No. 2 and No. 10 with a conductor, as with the Arduino Leonardo. Don't forget to bend the reverse side GSM board towards the pin contact corresponding to pin No. 2, so that it does not touch the Arduino Mega.

Arduino is a hardware platform used for quick creation various electronic devices, including security ones. Thanks to the simple design, simplicity of the programming language, as well as the use of open codes, even a non-professional can independently make a multifunctional alarm system to protect their home, cottage, apartment or garage. The Arduino GSM module will be the best option for creating a budget security system that can be optimally configured for a specific object.

Application area

The Arduino hardware platform is widely used in the process of creating various electronic systems and devices that can receive and process signals from various functional analogue or digital sensors and sensors. The results of processing the received signals can be controlled by external actuators and systems connected to Arduino.

An example of using these modules in the video:

Purpose

The Arduino hardware platform makes it possible to effectively interact with the controlled environment through a wide range of functional sensors that can control various parameters. Thanks to this, on the basis of such platforms, it is possible to form security complexes that will monitor movements along the protected perimeter, the opening of windows and doors, and damage to glass. In addition to security type sensors, you can also use temperature sensors, water or gas leakage control sensors.

Using with platform Arduino GSM module, information about a danger or emergency situation at a facility can be provided to the owner as quickly as possible. For this purpose, one of the networks of mobile operators is used.

Distinctive feature Arduino devices is that their microcontroller can be programmed by the user himself using Arduino language, based on Wiring. Thanks to this, anyone can program the operating algorithm of the created burglar alarm as required for a specific protected object and the specifics of its application.

Benefits of use

Today there are many hardware platforms and microcontrollers that can receive information from external sensors, process it and send control signals to executive systems. The Arduino platform simplifies the implementation of the listed processes as much as possible and has a wide range of advantages over other devices of this kind.

  1. Low cost. The platforms are quite cheap devices compared to their analogues, which in no way affects their functionality.
  2. Cross-platform. Arduino software works effectively under such operating platforms, like Windows, Linux, Macintosh-OSX.
  3. Ease of programming. To configure microcontrollers, the Processing programming environment is used. It is optimally suitable for both professional and small experienced users, which work with Arduino devices.
  4. Possibility of improvement. Specialized Arduino software is different open source, which allows experienced users to adapt it to specific requirements.

High reliability of the hardware platform. Arduino boards are produced with ATMEGA8 and ATMEGA168 microcontrollers (earlier models) and with ATmega32u4, Atmel ATmega328 controllers (newer models), which are characterized by high functionality and reliability.

Principle of operation

To ensure full functionality security systems or other devices built using Arduino platforms, you need to have a GSM module for Arduino. It can be used to access the Internet, make voice calls or send SMS messages.

The GSM board uses a special M10 radio modem, interaction with which is ensured through special AT commands. Information exchange with the modem is implemented using software serial interface, owning digital codes.

The GSM modem used in Arduino is a 4-band modem that can operate at the following frequencies: GSM 850MHz and 900MHz, PCS1900MHz and DCS1800MHz. The modem supports protocols such as TCP/UDP and HTTP, providing connections via GPRS. The transmission speed of information packets in this mode will be about 90 kbit/sec.

Sending SMS via Arduino and GSM module is implemented if available installed SIM card one of the mobile operators."

In addition, it will be possible to transfer voice messages, make calls - for this you additionally need a microphone and external speaker. Installing a SIM card will allow you to use Arduino in cellular communication or GPRS.

How to connect modules to Arduino

Before connecting the GSM module to the Arduino in its slot, you should install a suitable SIM card from one of the cellular operators. After this, the module is connected to the Arduino hardware platform in accordance with the instructions and its firmware is flashed. For this purpose, a PC is used, which is connected to the device using a USB cable. After downloading Arduino environment You should press the Upload button, which will start the software download process. Once this process is complete, the platform can be disconnected from the computer and powered from external system nutrition.

Comparative characteristics of GSM modules

The consumer market offers a wide selection of different GSM modules for Arduino. Below are the main characteristics of the most popular ones.

Neoway M590

Arduino GSM module M590 is wireless communication device used for receiving and transmitting information in networks mobile communications. The module of this series is created on a board with minimal wiring and is positioned as a GSM module for the Arduino hardware platform.

With this device you can establish mobile communications with external telephone, send SMS messages, exchange information using the GPRS Class-10 standard. The module of this design does not have a microphone input, which limits the possibility of receiving voice communications - a connection can be established, but sound will not be transmitted.

To control the M590, AT commands are used, which are issued via serial communication. Frequencies from 900 MHz to 1800 MHz are used as operating radio frequencies. The supply voltage is within 3.3...5 V. Therefore, the Neoway M590 GSM module connects to Arduino through a special voltage converter 5 V to 3.3 V.

GSM module SIM800L

The compact Sim800l GPRS GSM module is a device that is used to support mobile communications. The module is built on the SIM-800L meringue, created by SIMCom Wireless Solutions and is designed to provide services to services information networks GPRS\GSM, using frequencies from 850 MHz to 1900 MHz. It can be used to send SMS messages, make calls, and exchange information via GPRS channels.

The GSM module is equipped with an antenna; if you need to improve the signal level, you can use additional antennas. To control the module, a PC can be used, connected via a special USB-UART interface conversion board or directly via the UART itself. If Sim800l GPRS GSM module is used , connection to Arduino must be implemented through a logic level converter. This is due to the fact that the SIM800L has a voltage value on the logical high level is 2.8 V, and in Arduino - 3.3...5 V.

GPRS Shield by Seeed Studio

Connection GSM module to Arduino will provide the ability to use GSM/GPRS data exchange technologies, as well as make calls and send SMS messages. Devices of this type are built using the SIMCom SIM900 module. They have a slot for installing a SIM card, a connector for connecting external antenna, a set of 3.5 mm jacks for audio input and output. Control and work with Arduino GSM Shield is carried out through Serial connections and a set of specialized AT commands.

This module is special fee, used to control digital devices remotely, as well as for information exchange. The use of SIM900 allows Arduino to work using GSM/GPRS technologies, providing voice communication, sending SMS and exchanging data using cellular and mobile networks.

To operate this module, a control controller, a power supply, an antenna are connected to it, and a SIM card is also installed mobile operator. Using special jumpers, you configure the method of data exchange with the controller. If necessary, you can connect a speaker and microphone.

I want to present you a very simple way remote control power supply
We will be using ready-made radio controlled sockets, so we won't need to solder anything. This is very cool, because it is better not to touch 220 V (for beginners).

Code

If you are not using GSMSHIELD, but some other library, then the code will of course be different, but the principle will be the same. At certain intervals, we check if we have any unread SMS, parse them, and if a valid command has come from an authorized number, we send a radio signal with the mySwitch.switchOff or mySwitch.switchOn functions, passing them the address of the socket.
Note in my case, for the shield from Seeedstudio I had to go into GSM.cpp and change specified pins on 7 and 8./* Arduino GSM-switch example code Switch on/off radio controlled controlled outlets Author: Vladislav Ross, 2014 Contact: [email protected] You need to download: 1. rc-switch https://code.google.com/p/rc-switch/ 2. GSMSHIELD http://www.gsmlib.org/ For GSMSHIELD: * To change pins for Software Serial, use the two lines in GSM.cpp. * If you are using Mega, uncomment "#define MEGA" line in HWSerial.h * You can enable debug messages on serial port by defining DEBUG_ON */ #include "SIM900.h" #include #include "sms.h" #include "call.h" #include // 433MHz transmitter pin const byte RCpin = 12; char groupAddress = "11111"; char smsLetters = "ABC"; char* deviceAddresses = ( "10000", //A "01000", //B "00100" //C ); char adminNumber = "+74991356235"; //your phone number CallGSM call; SMSGSM sms; RCSwitch mySwitch = RCSwitch(); char number; byte stat=0; char smsText; byte position; int deviceLetterIdx = -1; byte i,j; void setup() ( gsm.begin(2400); delay(10000); for(i = 1; i<= 21; i++) { sms.DeleteSMS(i); } mySwitch.enableTransmit(RCpin); }; void loop() { //hang up all incoming calls /*stat=call.CallStatus(); if(stat==CALL_INCOM_VOICE) { call.HangUp(); }*/ position = sms.IsSMSPresent(SMS_UNREAD); //get new SMS if (position) { sms.GetSMS(position, number, smsText, 10); sms.DeleteSMS(position); if(strcmp(number, adminNumber) == 0) //accept SMS only from defined number { for (i = 0; i < sizeof(smsText) - 1; i++) { if(deviceLetterIdx != -1) { //got letter, now expecting 0 or 1 if(smsText[i] == "0") { mySwitch.switchOff(groupAddress, deviceAddresses); delay(500); } if(smsText[i] == "1") { mySwitch.switchOn(groupAddress, deviceAddresses); delay(500); } deviceLetterIdx = -1; } else { //waiting for letter A,B,C... for(j = 0; j < sizeof(smsLetters) - 1; j++) { if(smsLetters[j] == smsText[i]) { deviceLetterIdx = j; break; } } } } } } delay(10000); }; GitHub .

Problems?

If the sockets do not want to switch to any one, you can try to receive a signal from the original remote control to the receiver. rc-switch has sample code.

What's next?

How can this project be developed further?
Firstly, we still have a bunch of pins left on the Arduino itself and on the GSM shield. You can connect some sensors or devices to them. For example, do remote temperature monitoring or watering flowers.
Secondly, we only used SMS, and the module can also transmit voice and GPRS. GPRS can transfer much more data. In addition, you don’t have to hang up when calling, but, for example, accept the call and let them listen to what’s happening on the spot.
It is also possible that you want to receive control SMS not from one number, but from several. In this case, I would recommend storing the numbers in the address book; the library has the appropriate functions.
AT+CMGF=1 On text mode(SMS only in Latin)
AT+CSCS= "GSM" On regime
AT+CLIP=1 enable caller ID incoming call
If you send a command with 0, the number identification will be disabled and the module will only send the “RING” message instead of the caller’s number.
AT+CMGS="+79123456789" Sending SMS
ATI Get device information
AT+IPR=19200 port speed setting
AT+GSN will return the IMEI of the module
AT+CCLK? read the time from the module
AT+CCLK=“yy/mm/dd,hh:mm:ss+zz” where the order is “year/month/date, hour: minutes: seconds + time zone” The data must be sent with leading zeros, that is, for example, if our month is “4”, then “04” should be sent.
Get it back current time and the date can be sent by sending the same command, only with the “?” sign:
AT+CMEE=0 error information level. Can be from 0 to 2.
0 - disabled. It will simply write ERROR.
1 - error code. Will return digital code errors.
2 - description of the error. He will write down exactly what he doesn’t like about the team.
To work with the module through the terminal, the ATV1, ATE1 AT+CMEE=2 modes are more convenient; for communicating with the microcontroller, it is better to use ATV0, ATE0 and AT+CMEE=0 - this will make it easier to process the received responses.
These settings are not saved after the module is rebooted, so you must include these commands in the program code.
AT+CSQ information about signal quality.
The module will return two numbers +CSQ: 17.0
17 - signal level. Can be in the range 0..31 or 99. Than more topics better, but 99 means its absence.
0 - communication error rate (so-called RXQUAL). Can be from 0 to 7 than number fewer topics the quality of communication is better.
AT+COPS? information about the operator in whose network the module is registered
ATD+79121234567; dialing a number. (";" Necessarily)
The module will call the specified number and will return one of the options
BUSY - number is busy
NO DIALTONE - no signal on the line
NO CARRIER - no network or other problem (for example, no money in the account)
NA ANSWER - no answer
CONNECT - there is a contact!
AT+CMGR=3.0