Sim900 connection. GSM module for remote control. Comparative characteristics of GSM modules


At the request of the workers, I continue the topic of GSM devices, namely the connection of the SIM900D module to ATmega. Which model doesn't matter. In this article, I will be using the ATmega8515. I used this controller exclusively for Feng Shui))) All the necessary information will be displayed on the MELT 20x4 LCD display. He was also chosen according to Feng Shui))) And also because he understands the Windows-1251 encoding, which greatly simplifies the output of Russian letters.

And now let's actually set the task.

  • 1. It is required to turn on and off 8 LEDs (relays, fans, etc.)
  • 2. Turn on and off according to the transmitted code via SMS.
  • 3. Display the level of GSM signal reception.
  • 4. Displaying the last command sent via SMS.
The task has been set. The GSM module communicates with the MK via UART. You can see the GSM module inclusion diagram. MK will operate at a frequency of 3.6864 MHz. This is necessary to reduce errors in the UART. The exchange rate is 19200. For the entire time of testing, there were no errors with the transfer. True, one MK died, which gave a headache for a couple of days, but then with the replacement with a new MK, everything went like clockwork. The LCD display is connected to port A. Port C is assigned to turn the LEDs on and off. Oh yes. there is one caveat. The GSM module can receive data on the RxD leg only at 3 volts and no more!!! It is important!!! From here it was decided to feed data through a resistor divider. I leave the calculation of the shoulders to you, since the MK can operate in different ranges from 2.8 to 5 volts. Personally, I feed the GSM module with 4 volts, and the MK is 5. So, we sort of figured out the hardware. Now let's go to the code. The first thing you need is a way to receive data from the GSM module. The module fires responses to queries like this:
Inquiry:
AT+CSQ\r\r\n
Answer:
\r\n+CSQ: 17.0\r\n\r\nOK\r\n
This shows that requests and responses are mixed with a bunch of \r and \n nonsense. Well, for a request, this is not a problem, since we write it ourselves, but here is the answer ... Rake up this whole zoo with each incoming byte in UDR is not comelfo, so we will use a ring buffer. Who does not know what it is, go here. When using a ring buffer, add a check to the interrupt handler upon arrival of data in the UDR to ignore \r and \n. ISR(USART_RX_vect) ( char temp = UDR; if(!(temp == 0x0A || temp == 0x0D)) InBuffer(temp); ) That is, we write everything to the buffer except \r and \n. As soon as we receive the data, we begin to process it. The first thing to look at is whether it is an SMS or a response to a command. Since the GSM module always returns a fixed response, and only changes the data, you can track it by the name of the response. For example, a request for the GSM reception level.
if(time == 30) ( time = 0; USART_STR("AT+CSQ"); USART_END(); _delay_ms(200); ) if(GetData()) ( _delay_ms(70); num = IndexNumber(); OutBufferStr (temp,num); ) Now the temp array contains the response from the GSM module. Now let's recognize it.
if((temp == "C") & (temp == "S") & (temp == "Q")) ( ) If the array contains the answer to the GSM level request, then the condition will be fulfilled and it can be processed at your discretion. What if the condition is not met? That most likely came SMS. How to calculate it? As soon as an SMS message arrives, the module returns a string of the form.
+CMTI: "SM",1 All that changes here is the last character, or rather the number. This is the SMS number. But the letters SM never change. So we need to check if these letters are in the message.
if((temp == "S") & (temp == "M")) ( ) Of course, it would not be bad to check the name of the command itself for a more accurate conviction, but I neglected this, since for now this is just an explanation of the operation of the MK with the GSM module. The field of how the acceptance of SMS was recognized would not be bad to read it. We throw a request for the form to the GSM module.
USART_STR("AT+CMGR="); USART_TXD(temp); USART_STR(",0"); USART_END(); _delay_ms(200); The temp array cell contains the SMS number. This command will be adequate for SMS messages less than 9. Well, it's understandable why. In general, in order not to fill the memory of the SIM card with SMS messages, after reading the SMS, I immediately delete it, so there is no more than 1 SMS in memory. But still, I did not use the number 1 rigidly, but rather tore it out of the array. I do not know why, but sometimes SMS do not always arrive immediately, but with some delay. If this happened, then such a jamb is possible, the SMS has not yet arrived, we think that it has not passed and send another one after it. Here time passes and they come two in a row one after one. We read the first one as 1, and the second came as 2. It is from such jambs that the array cell protects. Now, having requested the SMS text, the GSM module will return us a response of the form.
+CMGR: "REC UNREAD","+71234567890","","14/07/06,13:04:38+16" message OK After that, you can read the message. Since the answers are always fixed, you can safely start reading from temp ... and there may be a jamb))) I ran into him. While I was figuring out the GSM-module, Beeline sent me an SMS with a quiet glanders. Everything would be fine and the setup sat down in the place where the number of the sending SMS subscriber is registered. Instead of "+71234567890" I received "My Beeline". Well, you know what it smells like. In short, MK didn’t understand a damn thing and went into a stupor. So I decided to check the number anyway. Yes, and for safety it will not hurt. And then suddenly the envious neighbor finds out about the control of the boiler via SMS and sends a command to turn off the boiler in the winter))).
for(uint8_t i=0; i The meaning is simple. In the loop, we compare the cells of the buffer array responsible for the number with the array in which the required number was previously placed. While the digits match, the flag is 1, but as soon as the digit does not match, we reset the flag and exit the loop. If the flag is zero, then we do not read the SMS, and if it is one, then the SMS is ours. If all checks are passed, then we read the command. I made the commands. capital letter V means to turn on O means disable. In order to find out which LED to turn on or off, after the letter we write its number from 1 to 8. Example, you need to turn on the 4th LED. Helmet SMS with text V4, and to disable O4.
if(flag) ( if(temp == "V") ( lcd_xy(0,2); lcd_putsf("LED-"); lcd_putchar(temp); lcd_putsf(" On "); switch (temp) ( case 0x31: PORTC |= (1 Actually, here is the whole code. First, we check the letter and execute this or that command on it and simultaneously display the message on the LCD. And after we have finished working with SMS, we drop the flag and delete all SMS.
USART_STR("AT+CMGD=1.4"); USART_END(); _delay_ms(100); flag=0;
That's all. Below is a video of all this disgrace and an archive with the project.
Project
Hello!
The task here is to manage country house, keep an eye on the temperature, doors, windows. And then the question arose about the data transmission medium. Well, wires and a radio channel disappear due to the high cost, FOCL is just a dream, but GSM is what you need. First, the eye fell on the old phones "Motorola", "Nokia", "SonyEricsson". Looked, turned and changed his mind. First, I did not want to solder to the contacts of the buttons, and there is no feedback. Secondly, to deal with the software of the phone, well, it’s not at the cash desk at all. In general, in creative thinking and floating in the expanses of the World Wide Web, having caught a couple of viruses, a compromise was found. And work with software and without any buttons. All this is offered by the module SIM900D. What did he like me.
- The first is the ease of installation. You will see this later. - The second is communication via UART. (This means MK + SIM900D = normal connection) - The third is the power supply of the module from 3 to 4.8 volts. Hosh AVR, Hosh ARM. Taste. Well, enough lyrics, it's time to get down to business.
This module looks like this.

About the installation. As you can see, the module is sharpened for surface mounting. The dimensions of the contact pads are large enough even for a LUT. Below is a picture of my device.

As you can see, nothing complicated. Now let's talk about the wiring diagram of this miracle. We look at the manual. And we see the pinout.

Yes, there are many, but we won't use them all. The first thing we need is to tie all the "GND" pins. If you look at the upper right corner, you can see three separate pins. Two "GND" and "ANT". These conclusions are arranged in this way for a reason. Let's look at the documentation for the picture of connecting the antenna.

Pins 59 and 61 should be as close as possible to the antenna lead. Additional diagrams highlighted with a dotted line are needed to connect antennas with a cable. Therefore, I soldered the SMA connector as close as possible to pins 59, 60, 61 and did not bother with the matching circuit, while with an antenna on a 3-meter cable and in a place of very poor reception, I squeezed out 13 points out of 31 from the module. in the picture above. More precisely, the legs from it)) The connector itself is on the other side. In this case, contacts 59 and 61, as it were, hug the antenna. Well, something like this. Next, let's talk about the SIM card. To install it, I used this connector (SIM ICA-501-006-01-F7)

The most interesting thing is that I found 3 options for pinouts of SIM cards. Which one to use? I will not introduce intrigue, but for simplicity I give the pinout of this connector. View from above.

But that is not all. If you look in the manual at the SIM-card inclusion scheme, then there you can see a certain microcircuit called SMF05C. This microcircuit contains protective diodes as many as 5 pieces. Needed to protect the contacts of the SIM card. Of course, you can not put it, but then be careful and do not touch the contacts with your fingers !!! As a sinful person, I can’t vouch for myself, so I soldered the mikruha. And here is the diagram itself.

Of course, it is given for an 8-pin SIM card, but for 6 it will be the same. There are really two ambushes with this chip. The first is that where the hell can you find her. And the second is that its size ... When I received the order and took it out, I put it on the table ... In short, in the second picture from above, it is soldered between the SIM card and the battery. For comparison, resistors 0805. Well, on the right is a transistor in the SOT-23 package. So, well, it seems that we figured out the SIM card, let's move on. And then the lighting. Generally speaking, this is an amateur. Since all these signals can be brought directly to the MK, and let him figure it out there himself. I brought them all out of a sense of beauty. So decide for yourself.
- The first is the signal whether the module is enabled or not (STATUS) log 1 - The second is the network registration presence signal (NETLIGHT) log 1/0 (blinking) If it blinks at the same frequency, it means it has not registered in the network If it is a long interval, then there is a connection to the network . - The third is the ringtone / sms (RING) log 0 Lit if there is an incoming call and blinks when receiving an sms message. The first two signals must be connected through an NPN transistor in the key mode.

And the third signal (RING) must be connected through a PNP transistor. Another important signal is the button to turn the module on and off. (where without it). Here's what the manual suggests.

That is, a log 1 was applied to the base of the transistor for 1 second and the module turned on.
Now let's talk about nutrition. Yes, I wouldn't refuse a good plate of wrestling, would you? Okay, let's move on. The module is powered by a voltage from 3 to 4.8 volts. It seems simple, but it's not. At the time of a call, sending sms, searching for a network, the module may require up to 2A. How. So lovers of LM7805 and KRENOK may be upset. Fortunately, the manual contains two circuits based on MIC29302 chips (I didn’t find it on sale) and LM2596 (you can buy this one). But I’m lazy and I simply didn’t want to collect power with such a large amount of strapping. I searched the internet and found. There is such a good stabilizer for processors like "Stump", "AMD" at 3.3v and up to 7.5A. In, I think that what is needed and ARM can be powered by the module. Here is the outline of this miracle.

And here's what it looks like assembled.

I put the radiator out of fear, in principle, the microcircuit does not heat up even during a call. And the last thing you should pay attention to is the battery. It is needed to maintain the life of the real time clock. The most important thing is that you cannot leave this conclusion in the air. Personally, I agreed on connecting the battery, which is what I wish you. Of course, you can slap two AAs)) but somehow it’s a bit large, but in the form of a tablet 2032 at 3v, that’s what you need. Fortunately, they are not expensive and you can solder the compartments directly to the board. In my opinion this is the simplest solution. You decide. Well, like everything. Here's what it all looks like together and in working order.

In the next article, I will tell you how I broke this module, but already programmatically through the terminal using AT commands.
I spread the schemes in PCAD-2006
Archive with GSM module files.
Archive with stabilization block files.
Continuation of a series of articles about the GSM module.
AT Commands.
Communication of the module with ATmega8515.
Debug board based on SIM900D


Foli 14.03.13

I would like more details about AT commands, UART and directly working with this in CodeVision

Alexey 15.03.13

I'm familiar with AT commands. I do not want to lay out half of the work, as there are some questions. And with UART and CVAVR everything is simple there. As soon as I figure out the AT commands, I will immediately post which commands and how to submit them from CVAVR.

Anatok 04.11.13

All this is beautiful. But if the alarm worked at least at minus 30 degrees and was charged with hidden solar panels, especially in winter, then there would be a lot of people who want to have such a device.

Alexey 04.11.13

GSM module eats up to 2A when registering on the network or calling or communicating via GPRS. Such resources require a good battery, and at -30 the battery will not last long. Even in weather stations on outdoor sensors, it is recommended to use simple batteries.

Bear 11.11.13

If it's still relevant and interesting ... look at EAT for SIM900. There is an SDK inside it in which you can load applications into the SIM900 from which you can do a lot of things ... for example, send the same AT commands ... + keyboard + SPI display ... + 2 ADCs :) Have a boring evening :)

Bear 11.11.13

And yet it is very beautiful for him to make food for him on the L5973D. Yes, about 2A is written in the datasheet ... but in practice these are very short-term impulses. It works fine for me, for example, with Arduino Mega, which itself is powered by a USB port (which has a current of 0.5 A)

Alexey 11.11.13

Therein lies the rub. At first I also fed from 7805, everything worked, and then bam ... And when connected to the network, everything goes out, and then it goes into a restart. Apparently the guard dog restarts due to a fit of nutrition. And with the L7953D it will be beautiful, but where to get it and the osprey will it cost :) So I switched to IRU1075

Alexey 11.11.13

I'm sorry for the mistakes, it's the damn GOODROYD sculpting the croaker for me. He thinks he's smarter. I will not edit, let Google be ashamed of their work.

uncleMisha 12/24/13

When I register on the network, atmega goes into reboot. Though there is pulse dcdc. Capacitors for 200 microfarads. And sometimes it works stably. Already tormented.

Alexey 12/25/13

Scheme for the studio. It's hard to understand the problem in words.

uncle Misha 12/25/13
uncle Misha 12/25/13

Http://ybex.com/d/tk7kgiefpklpeujb1zbl4lo5 mrkf7ayvci04ouq3.html The MK is powered by 2.8 (even tried 3.7) Volt so as not to block the level converter.

Alexey 12/25/13
sergey 19.07.14

Hello Alexey! Do you have ready-made boards with sim900, is it possible to buy?

Alexey 19.07.14

Ready in what sense? The module itself has already been assembled and it remains to make a board with the required outputs and inputs for a specific device. The one in this article is just a demo board for debugging programs. For a specific device, dimensions, location of connectors, headphone and microphone outputs are required. Where is the antenna connector. Give more details about what you need.

Andrey 28.09.14

As I understand it, this is a prototype of the scarf that I can't wait for. Only in the commercial version was it married with a power supply and ennobled with audio outputs. What is a big buzz.

Alexey 28.09.14

Actually it is. I just killed a few birds with one stone. Solved the age-old problem with power and level matching on the UART. And for chic added audio input and output. Actually ready cell phone.

Andrey 28.09.14

I would like to contribute ratsuhu for the future. in fact, this board is a complete node. And it is PRACTICALLY possible to use it in the finished product. however, there is one BUT. With a meson canopy, it’s better to put it on top anyway (antenna connector, access to a sim card), so it’s quite advisable to leave holes for the same pins parallel to all pins for the “periphery” with the possibility of soldering them in the “down” direction. Those. I wanted to put this device on the microcontroller board, spread it under yours, soldered the reciprocal connectors into it and docked it. Also with

Andrey 28.09.14

Gobbled up half a message, but I hope the idea is clear-)

Alexey 28.09.14
Sergey 01.02.15

Tell me why the module is heating up and not catching the network?

Alexey 01.02.15

There are several reasons for this. First, the power supply is exceeded. The second is whether the plus got to the general one. You need to carefully look at the legs of the power supply. Third, whether the module touches the power lines with its belly. On the belly there are several technological contacts that must be isolated from any conductors. Fourth, is the antenna output shorted with general conclusion. And to be more precise, you need to look at the board. Drop me a fee to the post office and I'll see if something is wrong there.

Sergey 01.02.15

I have factory boards, MasterKit BM8039 and both have the same problem .. you insert a SIM card, the module starts to warm up and there is no network.

Alexey 01.02.15

Pretty hard to say. The scheme is factory, it is necessary to climb on the board. It can be seen from the documentation that there are no recommended protective diodes for the SIM card on the board. Does the card itself and the pins match? 300 module is old and in my opinion it only works with 5 volt sims, and now they are all 3v. But I can be wrong. You have to look at the board itself, it's so hard to say something. If the symptom is the same on both, then I would go in the direction of the connector and the voltage of the sims. Once again, modern 3-volt SIM cards.

Sergey 01.02.15

It costs sim900D ... there are no diodes. When I insert the card, power appears on the module and it starts to warm up, but for example, on a SIM card. does not go from 9 feet ..

Sergey 01.02.15

Initially, they worked fine .. then something bugged ... I can’t understand what ..

Sergey 01.02.15

Can I somehow check the module without soldering it?

Alexey 01.02.15

What exactly was short? If the power supply does not go to the SIM card, then I'm afraid the line for the SIM card has died. How many legs does Simka have? 6 or 8? To check, you can communicate with the module via the UART 3, 4 leg bus without inserting a SIM card. If he refuses to accept AT commands, then I think you can bury him.

ANONYMOUS 01.02.15

I don’t know for sure what shorted .. legs 8 .. but how to communicate then?

Alexey 01.02.15

And on the connector, too, 8? We take the FT232RL chip, assemble the USB adapter<->TTL, solder to the UART of the module, launch the terminal, for example Putty, write AT and press enter. If it returns OK, then all is not lost. If silence ... In the trash. And yes, what kind of LEDs are on the board? How is network registration determined?

Sergey 02.02.15 03:12

There are also 8 on the connector .. there are two green and red LEDs on the board, the presence of a network is determined by blinking green once every three seconds ... can I somehow insert a photo of the board?

Alexey 02.02.15 07:42

It's easier to go to the forum.

Sergey 02.02.15 14:02

If you do not insert a SIM card, then you need to supply power to the module?

Alexey 02.02.15 15:48

I can't guess on coffee grounds. I need either a schematic or a board. And where does the power supply of the module and the SIM card come from? There, most likely, it intersects with some kind of microcontroller. He supplies food. Basically, you need a diagram. It's like making a diagnosis over the phone.

Sergey 02.02.15 15:56

Where can I post a diagram on the forum?

Sergey 02.02.15 15:57

Power comes to the module only when you insert a SIM card

Alexey 02.02.15 19:27

Well, the SIM900D module does not have this. To turn on the module, it is necessary to hold the low level on pin 12, and then raise it. The SIM card cannot be inserted or removed at all when the module is turned on, there is a chance to burn the port. If you look at the documentation, you can find recommendations there for installing protective diodes on the SIM card port line. On the forum . Create a topic and post a photo.

Eugene 08.09.15 12:04

When I apply voltage to the module, there is a positive potential on the 12th leg, and it is also positive on the 5th leg (provided that these legs are hanging in the air). Tell me please, because on the 5th leg it seems like there should be zero? If not, please correct me.

Alexey 08.09.15 13:21

12 leg is the inclusion of the module. 1 hangs on it when power is applied. To turn on the module, you need to press the 12th leg to the common wire for a couple of seconds, that is, apply 0. When power is applied to module 5, the leg must be pulled to the common wire with two resistors (this can be seen from the switching circuit transistor in the key mode) and it should be 0, since the base must be pulled up to zero to completely close the transistor. After pressing the 12th leg to zero, 1 should appear on the 5th leg, and after a while a meander indicating the status of the presence and connection to the network.

The GSM and GPRS module in the Arduino projects allows you to connect to remote standalone devices via a regular cellular connection. We can send commands to devices and receive information from them using SMS commands or via an Internet connection open via GPRS. In this article, we will look at the most popular modules for Arduino, understand the connection and look at programming examples.

Modules GSM GPRS

The GSM module is used to expand the capabilities of conventional Arduino boards - sending SMS, making calls, exchanging data via GPRS. Exist different kinds modules, the most commonly used are SIM900, SIM800L, A6, A7.

Description of the SIM900 module

The SIM900 module is used in various automated systems. Using the UART interface, data is exchanged with other devices. The module provides the ability to make calls, exchange text messages. The operation of the module is based on the SIM900 component developed by SIMCom Wireless Solution.

Specifications:

  • Voltage range 4.8-5.2V;
  • In normal mode, the current reaches 450 mA, the maximum current in pulse mode is 2 A;
  • Support 2G;
  • Transmission power: 1 W 1800 and 1900 MHz, 2 W 850 and 900 MHz;
  • There are built-in TCP and UDP protocols;
  • GPRS multi-slot class 10/8;
  • Operating temperature from -30C to 75C.

Using the device, you can track the route of transport together with a GLONASS or GPS device. The ability to send SMS messages is used in wireless alarms and various security systems.

Description of the SIM800L module

The module is based on the SIM800L component and is used to send SMS, make calls and exchange data via GPRS. A micro SIM card is installed in the module. The device has a built-in antenna and a connector to which you can connect an external antenna. Power is supplied to the module from an external source or through a DC-DC converter. Control is carried out using a computer via UART, Arduino, Raspberry Pi or similar devices.

Specifications:

  • Voltage range 3.7V - 4.2V;
  • Support for 4-band network 900/1800/1900 MHz;
  • GPRS class 12 (85.6 kB/s);
  • Maximum current 500 mA;
  • Support 2G;
  • Automatic search in four frequency bands;
  • Operating temperature from -30C to 75C.

Description of module A6

The A6 module was developed by AI-THINKER in 2016. The device is used for SMS messaging and data exchange via GPRS. The board features low power consumption and small size. The device is fully compatible with Russian mobile operators.

Specifications:

  • Voltage range 4.5 - 5.5V;
  • Power supply 5V;
  • Operating temperature range from -30C to 80C;
  • Maximum current consumption 900mA;
  • GPRS Class 10;
  • Support for PPP, TCP, UDP, MUX protocols.

The module supports microsim cards.

Description of A7 module

A7 is the latest module from AI-THINKER. Compared to its predecessor, the A6 has a built-in GPS to simplify the design of the device.

Specifications:

  • Operating voltage range 3.3V-4.6V;
  • Supply voltage 5V;
  • Frequencies 850/900/1800/1900 MHz;
  • GPRS Class 10: Max. 85.6 kbps;
  • Echo and noise suppression.

The device supports micro SIM cards. The module supports the exchange of calls, exchange of SMS messages, data transmission via GPRS, reception of signals via GPS.

Where to buy GSM modules for arduino

As usual, before you start, a few tips and useful links to Aliexpress sellers.

Very high quality KEYES SIM900 GSM GPRS module SIM800C module for arduino from a trusted supplier
Arduino compatible development shield based on SIM900 GPRS/GSM module Inexpensive mini A6 GPRS GSM module

Connecting GSM GPRS Shield to Arduino

In this section, we will consider the issues of connecting GSM modules to the Aduino board. Almost all examples are based on Arduino Uno, but most of the examples will also work for Mega, Nano, etc. boards.

Connecting the SIM800 module

To connect, you need an Arduino board, a SIM800L module, a step-down voltage converter, wires for connection and a 12V battery. The SIM800L module requires a non-standard voltage of 3.7V for Arduino, for this you need a step-down voltage converter.

The pinout of the SIM800 module is shown in the figure.

The Arduino board must be connected to the computer via a USB cable. Connect a 12V battery through the converter: -12V to Arduino ground, from ground to converter to minus, +12V to converter to plus. The outputs from the TX and RX module must be connected to pins 2 and 3 on the Arduino. Several modules can be connected to any digital pins.

Connecting the A6 module

The A6 module costs less than the SIM900 and is very easy to connect to the Arduino. The module is powered by 5V, so additional voltage-lowering elements are not needed for connection.

To connect, you will need an Arduino board (in this case, Arduino UNO is considered), an A6 GSM module, and connecting wires. The connection diagram is shown in the figure.

The RX output from the GSM module must be connected to the TX on the Arduino board, the TX output must be connected to the RX pin on the Arduino. The ground from the module is connected to the ground on the microcontroller. The Vcc pin on the GSM module must be connected to PWR_KEY.

Connection using GSM-GPRS shield

Before connecting, it is important to pay attention to the power supply voltage of the shield. The current at the time of a call or sending data can reach values ​​​​of 15-2 A, so you should not power the shield directly from Arduino.

Before connecting to Arduino, you need to install a SIM card on the GSM-GPRS shield. You also need to set the TX and RX jumpers as shown in the figure.

The connection is made as follows - the first contact (yellow wire in the figure) from the shield must be connected to TX on the Arduino. The second pin (green wire) connects to RX on the Arduino. The ground from the shield connects to the ground from the aruino. Power is supplied to the microcontroller via a USB cable.

The layout of the connection between the shield and the Arduino board is shown in the figure.

To work, you will need to install the GPRS_Shield_Arduino library.

To check the correctness of the assembled circuit, you need to do the following: connect RESET and GND to the Arduino (this will cause the data to be transferred directly from the shield to the computer), insert the SIM card into the shield and turn on the power to the shield. You need to connect the Arduino board to the computer and press the power button. If everything is connected correctly, the red LED will light up and green will flash.

Brief description of interaction via AT commands

AT commands are a set of special commands for the modem, consisting of short text lines. In order for the modem to recognize the command given to it, the lines must begin with the letters at. The string will be accepted when the modem is in command mode. AT commands can be sent either using a communication software, or manually from the keyboard. Practically all commands can be divided into 3 modes - test, in which the module answers whether the command is supported; reading - issuing the current command parameters; write - new values ​​will be written.

List of the most used AT commands:

  • AT - to check the correct connection of the module. If everything is OK, OK is returned.
  • A/ - repeat the previous command.
  • AT+IPR? – getting information about the port speed. The response will be +IPR: 0 OK (0 in this case automatically).
  • AT+ICF? – transmission setting. The response will be +ICF: bit, parity.
  • AT+IFC? – transmission control. The answer will be +IFC: terminal from the module, module from the terminal (0 - no control, 1 - software control, 2 - hardware).
  • AT+GCAP - shows the capabilities of the module. An example of a response is +GCAP:+FCLASS,+CGSM.
  • AT+GSN - get module IMEI. Sample response 01322600XXXXXXX.
  • AT+COPS? – shows available operators.
  • AT+CPAS – module status. Answer +CPAS: 0. 0 - ready to work, 3 - incoming call, 4 - voice connection, 2 - unknown.
  • AT+CCLK? – information about the current time and date.
  • AT+CLIP=1 – enable/disable caller ID. 1 - enabled, 0 - disabled.
  • AT+CSCB=0 – receive special SMS messages. 0 - allowed, 1 - prohibited.
  • AT+CSCS= “GSM” – SMS message coding. You can select one of the following encodings: IRA, GSM, UCS2, HEX, PCCP, PCDN, 8859-1.
  • AT+CMEE=0 – get error information.
  • AT+CPIN=XXXX - Enter the PIN code of the SIM card.
  • AT&F - reset to factory settings.
  • AT+CPOWD=1 – urgent(0) or normal(1) module shutdown.
  • ATD+790XXXXXXXX – call to the number +790XXXXXXXX.
  • ATA - call answer.
  • AT+CMGS=”+790XXXXXXXX”>Test sms – send an SMS message to +790XXXXXXXX.

In this case, the main commands for the SIM900 module are considered. Commands may differ slightly for different modules. The data for the module will be submitted through a special terminal program that must be installed on the computer. You can also send commands to the module through the port monitor in the Arduino IDE.

Sketches for working with the GSM module

Sending SMS on the example of SIM900

Before sending a message, you need to configure the module. First of all, you need to convert the transmitted message into text format. To do this, there is a command AT+CMGF=1. It is necessary to transfer the encoding to GSM with the command AT + CSCS \u003d "GSM". This encoding is the most convenient, since there characters are represented in ASCII code, which is easily understood by the compiler.

Then you need to dial an SMS message. To do this, a command is sent with the subscriber's number AT + CMGS = "+79XXXXXXXXX" r, in response it is proposed to dial an SMS text. You need to send a message. Upon completion, you need to send the Ctrl + Z combination code, the module will allow sending the text to the addressee. When the message is sent, OK will be returned.

The interaction with the module is based on the indexes that are assigned to each new message. By this index, you can specify which of the messages to delete or read.

Receiving SMS. To read an SMS message, use the AT + CNMI = 2,2,0,0,0 command. When a text message arrives at the module, it will send to the +CMTI serial port: "SM",2 (in this case, 2 is the serial number of the message). To read it, you need to send the command AT+CMGR=2.

Receiving a voice call. First of all, for a conversation, you need to connect a speaker and a microphone to the module. When a call is received, the number from which it was made will be shown. To work, you need to enable the GSM library:

#include

If the SIM card is blocked, you need to enter its pin code. If a PIN is not required, this field should be left blank.

#define PINNUMBER ""

In setup(), the initialization of data transfer to the computer must be performed. The next step is to create a local variable to keep track of the network connection status. The sketch will not run until the SIM card is connected to the network.

boolean notConnected = true;

The gsmAccess.begin() function is used to connect to the network. When a connection is established, the GSM_READY value will be returned.

vcs.hangCall(); – a function indicating that the modem is ready to receive calls.

getvoiceCallStatus() - Gets the status of the sketch. If someone calls, it returns RECEIVINGCALL. To record the number, you need to use the retrieveCallingNumber() function. When the call is answered, TALKING will be returned. The sketch will then wait for a newline character to terminate the conversation.

Establish a GPRS connection and send data to a remote server

First you need to install the SoftwareSerial library, which allows you to provide serial information transfer and connect the GSM module and the Arduino microcontroller.

To send data to the server, you need to send the following commands:

AT+SAPBR=1,1 – Carrier opening.

The next three commands are related to setting network connection settings.

AT+SAPBR=3,1,\”APN\”,\”internet.mts.ru\” – select mts operator, access point name.

AT+SAPBR=3,1,\”USER\”,\” mts \” – user selection mts.

AT+SAPBR=3,1,\”PWD\”,\” mts \”

AT+SAPBR=1,1 – connection establishment.

AT+HTTPINIT - http initialization.

AT+HTTPPARA=”URL”, – URL address.

AT+HTTPREAD - waiting for a response.

AT+HTTPTERM stop http.

If everything is done correctly, lines with AT commands will appear in the port monitor. If there is no connection with the modem, it will show one line at a time. If the GPRS connection is successfully established, the LED on the module will start flashing.

Not so long ago, a friend offered me a job related to the creation of firmware for a microcontroller, which was supposed to communicate with the server using the SIM900D GSM module. Previously, I had nothing to do with programming microcontrollers, and I programmed in C last time in student days, but curiosity outweighed and I set to work. Documentation for this piece of hardware is available on the Internet, but good examples of working with TCP / IP in the code could not be found. There was nothing left but to cover with documentation, stock up on cigarettes and tea and start maneuvering between the rakes. And there were a lot of loot. Actually, that's why I wrote this article - to make it easier for others.

What was needed

It was necessary to write a code that could initialize the GSM module, establish a connection with the server, receive and send arbitrary data, check the connection status and work without failures. And also be compact enough to fit in the limited memory of the microcontroller and leave room for the main functionality and a little more in reserve.

What happened in the end

The result is a C code that can do everything that was needed. Due to the requirements of compactness, I had to parse the answers and generate strings using my own code, which I am even ashamed to show to honest people. Therefore, I recommend everyone to use regular expressions for this purpose. I am also going to transfer my code to a lightweight regular expression engine, but after creating a full-featured firmware.

The code requires functions / macros to work with the serial port, as well as the presence of the memset and memcpy functions. So it can be ported to another platform with relative ease without having to hook a bunch of libraries along the way.

And what does it look like?

Programming and testing was carried out under Windows 7. The resulting code became the main material for this article. I will not give the code in full and comment on it, but instead I will show the algorithm for setting up and working with the GSM module.

Functions required by the code:

  • uint16_t init_serial_port(char *port_name) This function sets up the specified serial port. Under Windows.
  • uint16_t puts_serial(uint8_t *buffer, uint16_t size) This one writes a string of bytes to this port.
  • gets_serial(uint8_t *buffer, uint16_t size) This one reads a string of bytes from the serial port.
The functions that the code provides:
  • init_gprs() & stop_gprs() Respectively initialize and cut down the GSM module.
  • uint16_t connect_gprs(uint8_t index, uint8_t mode, char *address, char *port) Connects to the server. It should be noted that the module can work with TCP and UDP protocols both as a client and as a client. A maximum of 8 simultaneous connections are supported.
  • uint16_t close_gprs(uint8_t index) Closes the specified connection.
  • uint16_t send_gprs(uint8_t index, uint8_t *buffer, uint16_t size) Send a message through the specified connection.
  • uint16_t recv_gprs(uint8_t index, uint8_t *buffer, uint16_t size) Receive message. A non-blocking function, which means it will not wait for data to appear in the stream, but will return control if there is nothing to receive. It is worth noting that this behavior is easier to implement than blocking.

How to work with serial port

It's simple enough. Under the target microcontroller, there are macros for sending / receiving data via USART, but since it is easier to debug such code from a desktop computer, I was provided with a bundle from a USB adapter<->USART and GSM module. It only remained to learn how to work with the serial port under Windows. It turned out to be easy. In short, the serial port is represented in the OS as a regular file, the transfer of information is carried out by the ReadFile and WriteFile functions. We only need to set some parameters using the SetCommTimeouts and SetCommState functions.

Here is what the port initialization function looks like:
uint16_t init_serial_port(char *port_name) ( COMMTIMEOUTS timeouts; DCB parameters; int result; serial_port_handle = CreateFile(port_name, // "\\\\.\\COMx" GENERIC_READ | GENERIC_WRITE, 0, // Values ​​of subsequent parameters are fixed when working with port NULL, OPEN_EXISTING, 0, NULL); if (serial_port_handle == INVALID_HANDLE_VALUE) ( printf("Error opening a serial port!\n"); return 1; ) // Maximum time between reading two bytes in a row timeouts.ReadIntervalTimeout = 100 ; // The next value is multiplied by the number of characters read from the port timeouts.ReadTotalTimeoutMultiplier = 0; // and added to this value, the maximum time to complete // the entire operation is obtained timeouts.ReadTotalTimeoutConstant = 1000; // Value is the same as the previous two parameters, but the timeout is counted as a write timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 1000; result = SetCommTimeouts(serial_port_handle, &timeouts); if (re sult == 0) ( printf("Error setting timeouts for serial port!\n"); close_serial_port(); return 1; ) // The most simple settings are entered in the port parameters - no // parity, no flow control, 1 stop bit. memset(¶meters,0,sizeof(parameters)); parameters.DCBlength = sizeof(DCB); GetCommState(serial_port_handle, &parameters); parameters.BaudRate = (DWORD)BAUD_RATE; parameters.ByteSize = 8; parameters.parity = NOPARITY; parameters.StopBits = ONESTOPBIT; parameters.fAbortOnError = TRUE; parameters.fDtrControl = DTR_CONTROL_DISABLE; parameters.fRtsControl = RTS_CONTROL_DISABLE; parameters.fBinary = TRUE; parameters.fParity = FALSE; parameters.fOutX = FALSE; parameters.fInX = FALSE; parameters.XonChar = (uint8_t)0x00; parameters.XoffChar = (uint8_t)0xff; parameters.fErrorChar = FALSE; parameters.fNull = FALSE; parameters.fOutxCtsFlow = FALSE; parameters.fOutxDsrFlow = FALSE; parameters.XonLim = 128; parameters.XoffLim = 128; result = SetCommState(serial_port_handle, &parameters); if (result == 0) ( printf("Error setting serial port parameters!\n"); close_serial_port(); return 1; ) return 0; )

How communication with the GSM module takes place

Once the serial port is configured, AT commands can be sent to it. The first command must be the "AT\r" sequence, which allows the module to automatically adjust the baud rate on the serial port. The response that can be received after that from the port will look like "AT\r\r\nOK\r\n" .

The command is a simple string of ASCII characters. In order for the command to be accepted by the module, you need to put a carriage return character "\r" at the end of it. In response, the module will send a character string consisting of two parts - the command to which the module responds and the response separated from it by "\r\r\n" characters, ending with "\r\n" characters. To make it easier to parse the responses, I created a macro that sets the pointer to the beginning of the response in the receiving buffer. If you want to print the response to the console, you need to add a null character to the end of the received message.

Void at_send(char *cmd, uint16_t size) ( uint16_t result; cmd = "\r"; result = puts_serial(cmd, size); return; ) uint16_t at_recv(uint8_t *buffer, uint16_t size) ( uint16_t result; result = gets_serial (buffer, size); return result; )
This is roughly what they look like secondary functions to send a command and receive a response.

Module initialization

The largest function in the code is responsible for setting up the module. Many AT commands are sent during initialization. I will describe them in the order they were sent to the module. I don’t specifically describe the arguments and answer options in detail, because they can be found in the documentation.
  • "AT+CPIN=pin-code" As you might guess, this command unlocks the SIM card by entering a pin code. To check if a PIN is required, you can use the command "AT+CPIN?" .
  • "AT+CREG?" This command returns the registration status of the module on the network. You need to execute it until the module answers that it is registered on the network.
  • "AT+CGATT=1" Forces the module to connect to GPRS. You can check if it is connected with the "AT + CGATT?" .
  • "AT+CIPRXGET=1" Enables manual retrieval of data sent over the connection. By default, this option is disabled and data is sent to the serial port as soon as it is received. This is not very convenient, although not critical - you can configure the module so that, along with the data, it also transmits IP headers, by which you can determine from whom the packet was received. I decided that it was easier to get data manually and I was not mistaken. As I understand it, this command is accepted only by SIM.COM GSM modules.
  • "AT+CIPMUX=1" By default, the module can only establish one connection. This setting enables the ability to create multiple connections. Sending and receiving data will differ by only one parameter - the connection index.
  • "AT+CSTT="internet"" APN - Access Point Name, access point name for GPRS. For my ISP it looks like this.
  • "AT+CIICR" Establishes a GPRS wireless connection. It may take some time, so it needs to be looped and checked for the answer.
  • "AT+CIFSR" Returns the module's IP address. I use it to check if the module is connected to the internet.
  • "AT+CDNSCFG="8.8.8.8","8.8.4.4"" This command sets the DNS servers that the module will use.
  • "AT+CIPSTATUS" In addition to connection status, this command provides information about whether the module is ready to establish connections. So you need to check her answer.
After executing these commands, the module will be ready to work. Well, or it won't. Here's how lucky.

Making and breaking connections

A connection is created using the command "AT+CIPSTART=index,"mode","address","port"" .
  • index specifies the serial number of the connection, can take values ​​from 0 to 7.
  • mode specifies the protocol to be used by the connection. May be "TCP" or "UDP".
  • address specifies the address of the server. If DNS servers were specified during configuration, then both the IP address and the domain name can be used.
  • port specifies the port of the server to connect to.
Note that when using the default UDP protocol, datagrams will be sent and received from only one address. In order to use UDP to its fullest and send/receive data from any address, you can use the so-called extended UDP mode, configured with the "AT+CIPUDPMODE" command. For details refer to the documentation.

In response to the command, you can get several answers. If everything is fine, then after the standard "OK" after a short period of time you can get one of three answers:

  • "index,ALREADY CONNECT" means that the connection with the given index has already been established and should be looked for.
  • "index,CONNECT OK" is obvious here.
  • "index,CONNECT FAIL" means there was a problem establishing a connection.
You can terminate the connection with the command "AT+CIPCLOSE=index" . You can terminate all connections and deactivate the GPRS interface with the "AT+CIPSHUT" command.

Data transfer

Data is sent with the command "AT+CIPSEND=index,length" , where index specifies the connection over which to send data, and length specifies the length of the data packet. By the way, you can find out the MTU for each connection using the "AT+CIPSEND=?" .

If all is well, the module will issue a ">" prompt in response to the command, after which you need to send data to the serial port. Once the module has received a number of bytes equal to length , it will say something like "index,SEND OK" . In general, you can not use the length parameter, however, in this case, the end of the data packet must be specified explicitly using the character 0x1A , in the terminal, the combination Ctrl + Z. Obviously, this option is not suitable for transferring arbitrary data.

As you can see, data transfer is not a very complicated process. Therefore, we turn to the most interesting thing - receiving data.

Data reception

As soon as the GSM module receives data, it signals this by sending a string like "+CIPRXGET:1,index\r\n" to the serial port. I honestly do not know what the unit means, because this function of the module is documented rather poorly, but I have it in all messages about receiving a packet.

I was not happy with the idea that I would have to monitor module messages in one way or another. However, after playing around with the debugger a little, I found out that the module does not send any other asynchronous messages, and that after executing any AT command, this message ends up at the beginning of the buffer. Since I had compiled a macro to separate the response from the command by looking for the substring "\r\r\n" , this didn't bother me in any way. So the function of receiving data was implemented quite simply.

So, you can receive data with the command "AT+CIPRXGET=2,index,length" . The two means the receive mode, in this case, the bytes are simply poured into the serial port. You can also set the data to be received as HEX text, apparently to prevent conflicts with programmatic flow control. I did not need it, because I do not use flow control at all. The length parameter specifies the size of the data packet we wish to receive at one time.

In response, we will get something like "+CIPRXGET:2,index,received,excess\r\n__DATA__\r\nOK\r\n" . The received field will contain the number of bytes that are in the __DATA__ data packet, and the excess field will contain the number of bytes waiting in the module's buffer. So if the received field is zero, you can safely say that there is nothing to receive. Actually, using this, I implemented a non-blocking function for receiving data.

Finally

I strongly recommend getting comfortable with AT commands using PuTTY before writing code, which works great with a serial port.

I hope the information in this article will help someone write the code for their SIM900. It is quite possible that the principles of working with a GSM module, outlined above, can be applied to modules of other models, and, possibly, manufacturers.

Work with GSM/GPRS shield SIM900 Now let's talk about cheap (about 150 rubles) module GSM NEOWAY M590.

The module is sold "in bulk" (the kit includes everything you need), so you will need soldering skills, however, there is nothing complicated there.

Comes with
The two little black things are resistors, polarity doesn't matter.
The square yellow thing is a tantalum capacitor, the polarity is important here, so we solder it as in the picture.
The black cylinder is a diode (in this design is responsible for lowering the voltage), be sure to observe the polarity, so we do as in the illustration.
A small transparent thing is an LED, again, the polarity is important, on the board the minus is located closer to the letter B oot.

The rest of the details, I think, do not raise questions.

For those who plan to distribute the board for the module on their own:

Connection and operation

NEOWAY communicates with arduino (or other device) via UART (RX, TX) using AT commands. In order to send commands, you need to find out the speed of the UART.
To find out the speed, you need to connect the assembled module to the computer using USB-UART bridge, this thing looks like this:

In this case we connect:

USB-UART <> NEOWAY

+5 <> +5
GND <> GND
TX <> RX
RX <> TX

Contact BOOT used to enable/disable the module momentarily (~1sec) connection with GND, but it is more convenient to simply connect it with GND and do not disconnect. The module will turn on when power is applied.

If there is no such thing, then you can turn the arduino into USB-UART bridge bay into it here is such a sketch ...

Void setup() ( pinMode(0, INPUT); pinMode(1, INPUT); ) void loop() ()

... and connecting like this:

Arduino <> NEOWAY

+5 <> +5
GND <> GND
RX <> RX
TX <> TX

Contact BOOT connect with GND.

About nutrition

The module can consume high current, up to 2 amperes at the peak, so for reliable operation it is necessary to organize an additional power supply unit. In principle, it will also work from the arduino, but at the time of registering on the network or receiving a call, the module may be overloaded.

It will also not be superfluous to put an electrolytic capacitor (~ 1000 microfarads, 16 volts) closer to the module.

After power is applied, the LED on the board should start blinking. (about once per second)- this indicates that he is ready to work.

Now we connect your design to the computer, in the Arduino IDE open the “Serial Port Monitor” (hereinafter "terminal"), choose (bottom-right) NL&CR, set the speed to 9600 and send a ping command - AT

If the answer is OK, then the module is working and the speed UART installed 9600 . If there is no answer, then check the correct connection of the UART and then proceed by “poke” by substituting different speeds until you see the coveted OK.

After starting, the modem will say - MODEM:STARTUP, and will inform about readiness for work - +PBREADY

If the modem does not have enough power (most of the problems that occur are due to this), then it will constantly restart.

I also encountered the fact that the modem does not work with all SIM cards.

If everything is in order, then we proceed to the study of AT commands for communicating with NEOWAY and its settings.

AT commands

AT- status request, response - OK.

ATE0- disable "echo".

ATE1- enable "echo".
Echo is a repetition of the entered command in the terminal.

ATI- name and version of the module.

AT+getvers- firmware version.

AT+IPR=9600- setting UART speed (9600) , possible options - 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200.

AT&W0

AT&W1- saving configuration settings in EEPROM.
0 for zero profile, 1 for first profile.

AT+CPAS- modem status check, response - +CPAS: 0.
Statuses: 0 - ready to work, 2 - unknown, 3 - incoming call, 4 - connected.

AT+CPWROFF- disable the module.

AT+CLIP=1- enable caller ID.

AT+CLIP=0- disable caller ID.

ATD+79634759175;- call.
The following messages will be displayed in the terminal: CONNECT - the connection is established, BUSY - busy, NO ANSWER - no answer, NO CARRIER - the call is dropped.

ATH- reset all connections.

ATH1- reset the current connection.

AT+CMGF=1- set to SMS text format.

AT+CMGF=0- configure SMS to PDU format.

AT+CSCS="GSM"- sms text encoding - ASCII. Change to normal quotes.
Other encodings are possible: HEX - hexadecimal values, IRA - international reference alphabet, PCCP437 - CP437 (IBM PC) encoding, 8859-1 - code pages of the ISO 8859 family, UCS2 - unicode encoding.

AT+CMGR=1- reading sms, where the number is the serial number of the message. That is, in this case, the first message is read, so - AT+CMGR=2 the second, and so on.

AT+CMGD=1- deleting sms, where the number is the serial number of the message.

AT+CMGD=1.1- delete all read sms.

AT+CMGD=1.2- delete all read and sent sms.

AT+CMGD=1.3- delete all read, sent and unsent sms.

AT+CMGD=1.4- delete all sms.

AT+CNMI=1,2,2,1,0- output received sms to the terminal.

You can find comprehensive information on at-commands.

Sending SMS will be carried out by arduino.

Next, we will control the module using arduino

If your module has a UART speed set other than 9600 then issue the command:

AT+IPR=9600
When interacting with the arduino, SoftwareSerial will be used, and it does not work well at speeds above 9600.

Unplug device from power and switch RX and TX (rest unchanged) module to arduino as follows:

Arduino <> NEOWAY

+5 <> +5
GND <> GND
D2 <> TX
D3 <> RX

Contact BOOT connect with GND.

First, upload a simple sketch to the arduino (after entering the number from which you will call the module).

At the start, for each command there must be a confirmation - OK.

#include SoftwareSerial mySerial(2, 3); byte led = 13; void setup() ( delay(2000); pinMode(led, OUTPUT); digitalWrite(led, LOW); Serial.begin(9600); mySerial.begin(9600); Serial..println(); Serial.println(" Turn on AOH:"); mySerial.println("AT+CLIP=1"); //turn on AOH delay(100); // AT START, EVERY COMMAND MUST BE CONFIRMED - OK ) void loop() ( if( mySerial.available()) //if the module sent something ( char ch = " "; String val = ""; while(mySerial.available()) ( ch = mySerial.read(); val += char(ch ); //collect the received characters into a string delay(3); ) Serial.print("Neo send> "); Serial.println(val); if(val.indexOf("RING") > -1) //if there is an incoming call, then check the number ( if(val.indexOf("79891196709") > -1) // ENTER THE NUMBER from which you will call the module ( Serial.println("Call my phone"); mySerial.println( "ATH"); //break the connection Serial.println("Disconnection"); Serial.println("On D13"); digitalWrite(led, HIGH); //turn on the LED for 5 sec Serial.println("5 sec pause "); delay(5000); digitalWrite(led, LOW); //turn off Serial.println("Off D13"); ) ) ) )
When calling from the entered number, D13 will light up for 5 seconds, and the connection will be cut off. If it is a different number, then nothing will happen. All actions are displayed in the terminal.

The following sketch will send an SMS in response to our call:

#include SoftwareSerial mySerial(2, 3); byte led = 13; void setup() ( delay(2000); pinMode(led, OUTPUT); digitalWrite(led, LOW); Serial.begin(9600); mySerial.begin(9600); Serial..println(); Serial.println(" Turn on AOH:"); mySerial.println("AT+CLIP=1"); // turn on AOH delay(100); Serial.println("Text format sms:"); mySerial.println("AT+CMGF= 1"); // text format SMS delay(100); Serial.println("Mode GSM:"); mySerial.println("AT+CSCS=\"GSM\""); // text encoding - GSM delay( 100); // AT START, EVERY COMMAND MUST BE CONFIRMED - OK ) void loop() ( if(mySerial.available()) //if the module sent something ( char ch = " "; String val = "" ; while(mySerial.available()) ( ch = mySerial.read(); val += char(ch); //gather the received characters into a string delay(5); ) Serial.print("Neo send> "); Serial.println(val); if(val.indexOf("RING") > -1) //if there is an incoming call, then check the number ( if(val.indexOf("79919790861") > -1) // ENTER THE NUMBER , from which you will call the module ( Serial.println("Call my pho ne"); mySerial.println("ATH"); //disconnect Serial.println("Disconnection"); delay(3000); sms(String("Hello from website"), String("+79919790861")); // ENTER THE NUMBER from which you will call the module ) ) ) ) void sms(String text, String phone) // send SMS ( Serial.println("Start SMS send"); mySerial.println("AT+CMGS= \"" + phone + "\""); delay(500); mySerial.print(text); delay(500); mySerial.print((char)26); delay(500); Serial.println("SMS send OK"); delay(2000); )
Instead of the “Hello from site” line, you can enter some variable, for example, the temperature from the sensor, and replace the call with some event, for example, by pressing a button (adding a button click handler).

Using this sketch, you can send some of your commands or AT commands to the module through the terminal. The answer will be displayed in the terminal.

#include SoftwareSerial mySerial(2, 3); byte led = 13; void setup() ( delay(2000); pinMode(led, OUTPUT); digitalWrite(led, LOW); Serial.begin(9600); mySerial.begin(9600); Serial..println(); ) void loop() ( if(Serial.available()) //if something was entered in the port monitor ( char ch = " "; String val = ""; while (Serial.available()) ( ch = Serial.read(); val += char(ch); //collect the received characters into a string delay(5); ) if(val.indexOf("callmy") > -1) // own command ( mySerial.println("ATD+79196989701;") ; // ENTER the number you want to call ) else mySerial.println(val); // transfer everything typed in the terminal to the GSM module ) while(mySerial.available()) ( Serial.print((char)mySerial. read()); delay(3); ) )
If you enter the at-command in the terminal - AT+CLIP=1, then caller ID will turn on, and if you enter your command - call my, then the module will call back to the phone entered in the sketch.

Sketch for sending SMS commands:

#include SoftwareSerial mySerial(2, 3); byte led = 13; void setup() ( delay(2000); pinMode(led, OUTPUT); digitalWrite(led, LOW); Serial.begin(9600); mySerial.begin(9600); Serial..println(); Serial.println(" Turn on AOH:"); mySerial.println("AT+CLIP=1"); //turn on AOH delay(300); Serial.println("Text format sms:"); mySerial.println("AT+CMGF= 1"); // text format SMS delay(300); Serial.println("Mode GSM:"); mySerial.println("AT+CSCS=\"GSM\""); // text encoding - GSM delay( 300); Serial.println("SMS to terminal:"); mySerial.println("AT+CNMI=2,2,0,0,0"); // print SMS to console delay(300); ) void loop () ( if(mySerial.available()) //if the module sent something ( char ch = " "; String val = ""; while(mySerial.available()) ( ch = mySerial.read(); val += char(ch); //collect received characters into a string delay(3); ) Serial.print("Neo send> "); Serial.println(val); if(val.indexOf("+CMT") > -1) //if there is an incoming sms ( if(val.indexOf("led13on") > -1) // see what the command is ( Serial.println("On D13"); digitalWr ite(led, HIGH); // turn on the LED ) if(val.indexOf("led13off") > -1) // look at the command ( digitalWrite(led, LOW); // turn off Serial. println("Off D13"); ) ) ) )
If you send a text message to the module - led13on, then the LED will light up, and if you send the text - led13off, then it will turn off.

And the last sketch, which allows you to send an SMS with a special word to the module and receive an SMS in response with the balance of money on the SIM card, which is in NEOWAY
Don't forget to enter the correct number.

#include SoftwareSerial mySerial(2, 3); byte led = 13; void setup() ( delay(2000); pinMode(led, OUTPUT); digitalWrite(led, LOW); Serial.begin(9600); mySerial.begin(9600); Serial..println(); Serial.println(" Turn on AOH:"); mySerial.println("AT+CLIP=1"); //turn on AOH delay(300); Serial.println("Text format sms:"); mySerial.println("AT+CMGF= 1"); // text format SMS delay(300); Serial.println("Mode GSM:"); mySerial.println("AT+CSCS=\"GSM\""); // text encoding - GSM delay( 300); Serial.println("SMS to terminal:"); mySerial.println("AT+CNMI=2,2,0,0,0"); // print SMS to console delay(300); ) void loop () ( if(mySerial.available()) //if the module sent something ( char ch = " "; String val = ""; while(mySerial.available()) ( ch = mySerial.read(); val += char(ch); //collect received characters into a string delay(3); ) Serial.print("Neo send> "); Serial.println(val); if(val.indexOf("+CMT") > -1) //if there is an incoming sms ( if(val.indexOf("money") > -1) // see what the command is ( delay(3000); mySerial.println("ATD#10 0#;"); ) ) if(val.indexOf("+CUSD") > -1) //if there is an incoming sms ( if(val.indexOf("Balance") > -1) // see what the command is ( delay(3000) ; val = val.substring(val.indexOf("Balance"),val.indexOf("r")); sms(String(val), String("+79967081199")); // ENTER YOUR NUMBER ) ) ) ) void sms(String text, String phone) //sending SMS with modem balance ( Serial.println("Start SMS send"); mySerial.println("AT+CMGS=\"" + phone + "\""); delay(500); mySerial.print(text); delay(500); mySerial.print((char)26); delay(500); Serial.println("SMS send OK"); delay(2000); )
Send the module an SMS with the text - money and in a few seconds you will receive a response SMS with the amount of money on the balance of the NEOWAY SIM card.

All experiments were carried out with the MTS operator.

Now you can collect what you need from these sketches.

When you receive an incoming call on a contact RING there are pulses with a low logic level with a duration of 30 ms, in time with the sound of the beep. Upon receipt of an SMS message, a single pulse with a duration of 25-35 ms appears.

This is probably all...

Join