Tip:
Highlight text to annotate it
X
In this video I will show you how I created a SMS Server
It allows me to control household appliances with SMS messages
That is...
if I send a command from my GSM mobile phone via SMS
Then the server receives it and executes these commands
I can turn on and off appliances... and list if they are turned on or off
To create this server... I used the following components
EFCom Shield bought from dx.com
Arduino Mega 2560 revision 3
8 channel 5V relay module
Bought from DX.com
And a SIM card
The price of the EFCom shield was 57.7 USD.
I also purchased Mega. It was priced 15.6 USD
And I purchased the relay module. It was priced 11.5 USD
The total is then 84.81 USD Not including the SIM card and jumper wires.
I will use light diodes instead of appliances and the relay module.
To show you how the server works
This is the relay
There will be light emitting diodes instead of this.
The GSM and GPRS shield...
can be used to send and receive SMS messages.
It can be used to connect to the internet via GPRS...
and to use as a normal GSM phone if you connect to it a microphone and headphones.
I am only using it to send and receive SMS In this example.
Arduino Mega 2560 revision 3
Is the microcontroller used to control the SMS Server
I bought it from AliExpress.com
When connecting, the 8 channel relay module to the Mega
You connect these pins directly to the Arduino Mega pins via jumper wires.
If you turn this relay on
then this lights up.
There for, you know you have turned it on.
It's very easy to use this.
In this video I will be turning on and off 4 light diodes instead of this relay.
I decided to use Arduino Mega with the EFCom shield...
because I was able to control so many pins with the Mega.
Using the 8-channel relay, makes it very easy to control appliances.
It took me a while, to find out how to connect and control the shield with the Mega
I searched the internet and found a few code examples and libraries, which did not work with my Shield and Mega.
Finally, I created my own sketch using code from other examples and libraries.
To be able to use the EFCom shield with Mega, you need to connect a jumper wire ...
from Shield pin RX to Mega pin 51.
Then you need to connect another wire..
from Shield pin TX to Mega pin 50.
This needs to be done because the Mega cannot use digital pin 2 and digital pin 3 as communication pins.
But Arduino UNO can do that.
For the Mega you need to disable these two jumpers, which have already been disabled here.
If I am going to use this shield with UNO then,
this jumper must be connected here
and this jumper connected here.
These three leds here show you the the shield status
This led lights if the shield is drawing power.
The shield will never be able to connect to the phone network if it's only connected to computer with USB
The STA led shows if this SIM900 chip is powered on or not
If the Net led is off, then SIM900 is not running.
It will blink differently depending on the network status
If the NET led blink rate is 0.8 seconds. Then SIM900 is not registered to the Network
If it blinks at 0.3 second interdvals. Then GPRS communication is established.
If it blinks at 3 second interdvals. Then SIM900 registered to the network.
That is what we want to see... blinking at 3 second interdvals.
Here is where I would connect the Relay if I was using it.
But in this video I connect these leds instead
The ground is connected to GND
And these are connected to the Mega digital pins 30, 31, 32 and 33.
You can see that, we have many pins to spare.
These are Analog pins
and these are digital pins
Here is the software running on the Arduino Mega.
The SMS server sketch.
I am not going to step through all of the sketch.
I'm just going to cover the primary sections of the code.
If I'm using Arduino Mega
Then I will need to use these pins.
DO NOT use the Serial1, Serial2 and Serial3 on the Mega.
Because they are buggy and will fail in the comunication buffer.
So use these pins
For UNO I need to connect the jumpers I showed you earlier, and use pins 2 and 3.
This is the Shield status LED description I showed you earlier.
If you are going to use this server then you need to define the pins you are going to control on Mega.
This is the first pin
and this is the last pin
you could for example, have this 30 to 42 or something...
and you don't need to change anything else in the sketch.
Here you set the starting state of all the pins.
You can choose whether, you want all of the pins to be turned ON or OFF when the SMS server starts.
And this is the phone number which will be allowed to control the server.
that is...
The server will only execute SMS commands coming from this number.
I borrowed a few functions from the GPRS Shield library they are here below
I will not be combing through them, they are a little complicated.
Let's scroll down to the main program
Here is the setup function
Here I turn the shield ON
Turn the PWR button on and wait for 3 seconds
I only turn on the power if there is no response from the shield
That means that it is turned OFF.
This is because the program can start when the shield is powered on and ready.
You could be restarting the Mega with the shield running and ready.
Here I am asking the server to have the SMS'es on a normal text format.
I have not had the time to make the code look pretty so sorry for that.
These are the possible SMS commands
It is possible to give the command "Offall"
Or "Off" followed by the pin "number".
It is possible to give the command "Onall" Or "On" followed by the pin "number"
Finally it is possible to give the command "List"
Then all pin states is collected.
"Stada" is put in..
space...
Pin "number"...
Equal "="...
and then whether the pin is turned ON or OFF
This would then return 1 or 0.
When I have run through all of the pins.
Then I put the result to a char buffer
Put in the earlier defined phone number
and the char buffer.
and send the SMS.
You can give these commands in any order.
You can send one SMS, with...
"Onall" followed by "List"
Then the server will execute all this
and end by doing the "List" command
Scrolling down to the end.
Let's start the test.
Plugging in the 9V power cord that came with the shield.
Beginning by blinking fast.
We want a three second blinking rate. Then we are connected to the network.
Connected to the network
I am going to send "On30"
"On30" sent
Then the server should turn pin 30 ON
Which is the first LED
If I send...
If I send... "On33"
and add "List" at the end.
Then the server will turn ON led 33 and send back a pin status report.
This led should be turned on
Now I want back the SMS
It came...
This is how the status report looks like.
The server support more pins but the length of the status report must fit in a text message.
Let's add "Onall"
It's hard to write on the phone sideways.
Send it
While the SMS is on it's way, I will write "OffallList"
"O"
All leds turned on
"f"
"f"
"a"
"l"
"l"
and "List"
"OffallList"
Then the server should turn all leds off, and send a status report.
That is, if I wrote this correctly.
If I send some nonsense then nothing will happen.
I forgot the list should be on it's way
Sending nonsense..
Nothing happens then, the SMS is just ignored.
Thank you for watching !