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
![](https://i2.wp.com/2150692.ru/images/faq/neoway_m590/port1.png)
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:
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 |