Hardware Reference
In-Depth Information
On line 12, the different objects are created: gsmAccess is used to talk to the
Arduino GSM board, sms is the object used to send SMS messages, client is
used to create a GPRS client connection, and gprs is used to attach the GPRS
connection.
The setup() function is declared on line 20. The serial connection is coni g-
ured on line 23, and on line 26 the variable notConnected is set to true . As long
as this variable is true , a while loop attempts to attach to the GPRS network,
with the attachGPRS() function on line 33. Finally, on line 43, pin 8 is set as an
input with an internal pull-up resistor.
On line 88 a function is declared: sendWarningSMS() . This function will send
an SMS message to the specii ed contact. The SMS message is created on line 90
using the beginSMS() function. On line 91, text is sent to the SMS engine—this
will be the content of the message. Finally, on line 92 the endSMS() function
will send the message.
The loop() function is declared on line 49. It starts with a for() loop and
iterates 600 times. Each loop will start by waiting for a second, and then looking
at the state of the digital input on pin 8. If the result is false, that means that the
reed switch has been activated, and the variable intrusion is set to true before
calling the sendWarningSMS() function.
Once this loop iterates 600 times, or close to 10 minutes, the sketch will attempt
to connect to a server. If the connection is successful, the sketch will send a mes-
sage to the server telling it that the security system is still up and running. If
the sketch cannot connect, then a warning message is sent to the serial console.
The sketch is simple and needs protection. A warning light could be added,
or at least an output to a relay for a siren of some sort. Also, the device can send
SMS messages to warn people, but it can also receive messages—you can write
a routine that can receive messages to turn the security on if the user leaves the
house without activating his alarm.
Summary
In this chapter, I have shown you just how l exible a GSM shield can be and the
different ways it can be used. You have seen an example using just some of the
many functions, and explored an idea about how to increase connectivity. In
the next chapter, I will show you the Audio library, a powerful library that adds
function to an Arduino Due to output audio i les. You will see how audio i les
are composed and how to create a device that will output audio to a loudspeaker.
 
Search WWH ::




Custom Search