written by: feitan - amazon web services · this project uses the seeed studio gprs/gsm shield to...

18
Cellular Sensor Sentinel You can change the sensors to detect just about anything, be it humidity, barometric pressure, magnetic fields, acceleration, vibration, flexing, tilt, etc. Initialize the sensor in setup(). If you want the sensor to trigger a message, check for the trigg Written By: Feitan Cellular Sensor Sentinel © 2017 www.botsbits.org Page 1 of 18

Upload: lyliem

Post on 11-Jul-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Cellular Sensor SentinelYou can change the sensors to detect just about anything, be it humidity, barometric pressure,

magnetic fields, acceleration, vibration, flexing, tilt, etc. Initialize the sensor in setup(). If you wantthe sensor to trigger a message, check for the trigg

Written By: Feitan

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 1 of 18

Page 2: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

INTRODUCTION

This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remotealarm system that can notify your cell phone within seconds, via text message, when nearby doorsor windows are opened or closed, pressure sensors depressed, or motion sensors activated, just toname a few of the many possibilities.

Watch video

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 2 of 18

Page 3: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 1 — Cellular Sensor Sentinel

Here we’ll teach you how to connectsimple motion, touch, pressure, andlight sensors, and how to programthe Arduino to use the shield to sendtext messages when these detectevents.

It’s easy to adapt this system to useother sensor devices liketemperature probes, magneticswitches, tilt sensors, etc. (If you’relooking for inspiration, check outForrest Mim’s classic bookElectronic Sensor Circuits andProjects.)

Step 2

GPR…what was that again?

Back when cellphone technologywas only “2G,” an industrystandard data protocol wasdeveloped so that all phones,towers, and other cellular devicescould talk to each other, even ifthey weren’t all made by the samecompany, regardless of whatcountry they happened to beoperating in.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 3 of 18

Page 4: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

That protocol survives today, andis known as GSM. The originalFrench acronym—Groupe SpecialMobile—has been superseded byan English one: Global System forMobile Communications. Though2G has been overtaken in manyparts of the world by 3G and 4Gtechnologies, even these moremodern devices are required to bebackwards-compatible with GSM.

As such, GSM remains theworld’s dominant mobile phonedata standard. GSM specifies anumber of services that devicesmust provide in order to claimcompliance. Among these isGPRS, or General Packet RadioService, which is commonly usedto provide text messaging,multimedia messaging, andinternet access.

Power

You can power the SensorSentinel over your USB cable,through a wall-wart, or using abattery pack. During testing, it’sconvenient to use the USB cable,but for true wireless use, you’llwant a battery.

The method we’re using forcapacitive touch sensing workspoorly when powered throughbatteries, but relatively well whenpowered by USB or AC adapter.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 4 of 18

Page 5: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

The Arduino code and arepackaged version of PaulBadger’s Capacitive SensingLibrary are available for downloadfrom the MAKE Github repository.

Step 3

Step #1: Build the contact sensor

Cut a small rectangle out of cardboard, and transfer its shape to a piece of aluminum foil bytracing around it with a pencil. Cut out the aluminum foil rectangle, cut it in half, and trim all theedges of both halves about 1/8". Glue the foil sections to the cardboard as shown.

You want a narrow gap between the two foil sections and around all the edges.

Crease the cardboard in the middle, folding the foil-covered surfaces toward each other. Cut twosections of drinking straw about 1" longer than the sensor is wide, on each side, and attach themacross the foil on one side of the sensor by folding them around the back and securing the twoends with Scotch tape.

You can change the amount of air trapped in each straw to adjust its springiness, which in turnwill allow you to tune the sensitivity of the sensor.

Attach alligator clips to two opposing corners of the foil/cardboard rectangle and cut out theadjacent corners, with scissors, so that the clips will not short across the gap when the sensoris folded over.

Close the sensor and check its operation with the continuity tester on your multimeter. Thestraws hold the surfaces apart, but when something presses down on the middle, the two foilsurfaces will connect, closing the circuit.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 5 of 18

Page 6: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 4

Step #2: Build the capacitive touch sensor

While the contact sensor is basically an improvised momentary switch, the capacitive touchsensor is a little more sophisticated. it works by detecting the change in capacitance—the abilityto hold electrical charge—of a metal sensor element when it comes in contact with anotherobject.

This sensor probably won’t work well on battery power, so if you know you’re going to be runningon batteries, skip this sensor and try another.

To build the sensor itself, cut a rectangle out of cardboard about 5" × 10". Cover one side withaluminum foil, and glue the aluminum foil to the cardboard. Attach an alligator clip and wire to thefoil.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 6 of 18

Page 7: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 5

Step #3: Build the battery pack

Unscrew the connector sleeve from the power plug and slip it over the battery pack wires.

Double check that you have put the connector sleeve over the battery pack wires so you canslide it back up and screw it on over the connector when you are finished.

Triple check that you've put the connector sleeve over the wires before soldering.

The connector's center pin is positive. Solder it to the red wire. The outside shell is negative.Solder it to the black wire.

If you forgot to put the connector sleeve over the wires, desolder the wires from the connectorand do so now.

Gently crimp the connector terminal ears down to grab the wire insulation. This will providestrain relief on the solder joints. Don't crimp too hard, or you may cut through the wire insulationand short out the connector.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 7 of 18

Page 8: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 6

Use your multimeter's continuitytester between the sleeve and centerpin of the plug connector. The circuitshould test open (i.e. there shouldbe no beep); if your meter beeps,there is a short. Fix it beforeproceeding.

Once you've fixed any shortedconnections, pull the sleeve up alongthe wires and thread it onto theconnector body. Put 6 AA batteriesin the battery box.

Step 7

Step #4: Program the Arduino

If you haven’t already, visitarduino.cc to download and installthe free Arduino software for yourcomputer.

Download the Sensor Sentinelsketch and Capacitive SensingLibrary from the MAKE Githubrepository. Put the sketch in yoursketchbook directory, in asubdirectory calledSensorSentinel. Follow theinstructions at arduino.cc toinstall the library directly from theZIP file.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 8 of 18

Page 9: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

The Sensor Sentinel software hasa variety of options you can setby making changes at the top ofthe program code. Texting isdisabled by default, so you canget the sensor working as you likebefore enabling a service thatmay cost you money to use.

With texting disabled, the SensorSentinel will only report eventsthrough the Arduino software's"Serial Monitor" window. Beforeyou enable texting, you'll alsoneed to replace the default phonenumber with the number of thephone you want to receive textswhen the Sensor Sentinel isactivated.

Connect the Arduino to your PCusing the USB A-B cable. UnderTools, set the board to ArduinoUno (or whatever is appropriatefor your Arduino board). Selectthe proper port. Press the uploadbutton to send the code to theArduino.

Open the Serial Monitor and setthe baudrate to 115200. Youshould see “Hello World” appearin the Serial Monitor window.

Disconnect the Arduino from thecomputer.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 9 of 18

Page 10: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 8

Step #5: Configure the GPRS 2.0 shield

Your shield may come with the headers loose from the board; if so you'll need to solder them inplace so it can plug into an Arduino. A handy trick for getting everything aligned quickly is to firstsolder only one pin from each header to the shield.

Once all the headers are "tacked" to the board, confirm everything is aligned by connecting it toan Arduino. If you need to adjust something, there's only one pin you have to reheat and gentlymove. Once everything fits, solder all the pins.

Activate your SIM card using the package instructions, then load it in the GPRS shield'sconnector, making sure the contacts connect. If you have a microSIM, use an adapter.

The small connector on the shield that connects to the external PCB antenna is called a HiroseU.FL connector. Connect the small wire from the PCB antenna to it now.

The two jumpers that select the serial port can either be set to HWserial or SWserial. We wantto use software serial, so set them both to SWserial.

Make sure the Arduino isn’t powered, and then connect the GPRS shield to it.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 10 of 18

Page 11: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 9

Connect the Arduino to your PCusing the USB A-B connector, andwatch the serial output using theSerial Monitor at 115200 baud. Youshould see the green PWR LED lightup on the board.

The program will try to turn on themodule, so wait a few seconds andwatch for the Serial Monitor to print“Ready”, and you should see the red"Sta" LED light up on the shield. The"Net" LED might also blink green.

Just to demonstrate the powerbutton, let’s press and hold thePWRKEY for two seconds. Thelights should change as the cellularmodule turns off. Whether themodule is on or off, when theprogram starts, the program will turnon the module.

Disconnect the Arduino from thecomputer.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 11 of 18

Page 12: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 10

Step #6: Connect the sensors

Plug the PIR motion sensor into the board so that OUT connects to pin 2, VCC connects to pin3, and GND connects to pin 4. Remember, Arduino pin numbering starts at 0. The GPRS shielddoesn’t have pin labels, so reference the corresponding labels on the Arduino to double-check.

The light sensor has a long and short leg. Connect the short leg to GND and the long leg to A0.

Connect one of the contact switch alligator clips to the ground leg of the light sensor, andanother to pin 10. If you have a jumper wire, you can use that to connect the alligator clip to pin10. If you don’t, you can use the leg of an extra resistor. If it’s confusing, cut the leg off the extraresistor and use it as a little wire.

Connect the 10M resistor between pins 11 and 12. Connect the alligator clip lead from thecapacitive sensor to the resistor on the part that plugs into pin 12.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 12 of 18

Page 13: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 11

Step #7: Test and configure

Connect the Arduino to the PC using the USB A-B cable.

Because this project sends text messages, and text messages can cost you money, there aresome features in the code that help stop you from sending a thousand texts in a minute if there’san issue with the sensors. By default, this project has the text messages turned off, but it willprint to the Serial Monitor when it would have sent a text.

Open the Arduino Serial Monitor with the baudrate set to 115200. You should be able to see a“Hello world” message shortly followed by the shield radio turning on.

Before enabling outgoing texts, test each subsystem—put your hand in front of the PIR sensor,and verify that the serial monitor reports the correct event. The PIR sensor also glows red whenactivated. Press and release the contact sensor. You should see a press event and a releaseevent on the Serial Monitor

The capacitive touch sensor needs a little configuration. First, it won’t work well when onbatteries, so if you know you’re going to be on batteries, ignore the capacitive touch sensortuning, and set CAP_SENSOR_ENABLED to false. There are two numbers, a lower and upperthreshold.

When the reading is above the upper threshold, it will trigger activation. When the reading dropsbelow the lower threshold, it will trigger deactivation. The raw sensor value will print to thescreen a few times a second. Watch the numbers as you put your hand closer and further awayfrom the sensor, and choose appropriate settings.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 13 of 18

Page 14: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

After changing these, you’ll have to re-upload the program to the Arduino.

Step 12

Test the cellular functionality.Confirm that SMS_NUMBER hasbeen set to a valid outgoing number.Confirm thatMIN_MS_BETWEEN_SMS, whichsets the minimum delay betweentext messages in milliseconds, isset relatively high—we recommend30000 milliseconds (30 seconds) tostart.

Confirm SMS_ENABLED andSEND_SMS_AT_STARTUP is true.If you’re not using the capacitivetouch sensor, setCAP_SENSOR_ENABLED to false.

After changing any values, be sureto reupload the modified code to theArduino by pressing the uploadbutton. Open the Serial Monitor—theshield should send a text message.Watch the Serial Monitor for errors.There shouldn’t be any.

After 30 seconds or so, turn off theArduino by unplugging it, and wait forthe SMS to come through on theoutgoing number. It shouldn't taketoo long, though delivery time willvary with network congestion. Thetext messages will contain thetrigger reason, the state of all thesensors, as well as the time the textwas sent.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 14 of 18

Page 15: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 13

Step #8: Deploy the Sensor Sentinel

Once the test message arrives successfully, you’re ready to deploy! You can use the batterypack, a wall-wart, or the USB cable to power the Sensor Sentinel. A rubber band is handy forconnecting the battery pack to the shield and Arduino.

I tested the Sensor Sentinel on top of the fridge (with the PIR watching for people walking in frontof it), in a book case (with the contact sensor positioned to notify me if anyone touched aparticular book), and underneath my favorite chair (with the capacitive sensor tuned to detectsomeone sitting down in it).

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 15 of 18

Page 16: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 14

Conclusion

You can change the sensors todetect just about anything, be ithumidity, barometric pressure,magnetic fields, acceleration,vibration, flexing, tilt, etc. Initializethe sensor in setup().

If you want the sensor to trigger amessage, check for the triggeringcondition in loop(), otherwise justread the sensor inannotateMessage(), put some textin the message variable andyou're good to go!

There are Arduino libraries forinterfacing with the module on theSeeed Studio GPRS Shield. Theymake it easier to do morecomplex stuff, but we chose notto use them in order to keep thissketch simple.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 16 of 18

Page 17: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

Step 15

Going Further

The code for interfacing with thecellular module is based uponexamples from Seeed Studio. Ithas a lot of delays. It would bepossible to write a function towatch for "OK: in the cellularmodule's output. This would likelyreduce those delays a bit, andmake the code a little morerobust.

Hook up a microphone to the MICjack on the shield, and have theshield call you for 1 minute andthen hang up. You could listen inremotely!

Have the cellular module checkfor incoming texts, and if you textit from your trusted number, haveit reply back with sensor readings(or call you back so you canlisten in!) Once you have this, youcould attach servos, buzzers,anything, and trigger them fromanywhere you have a cell signal!

Depending upon where you live,you may be able to text theTwitter shortcode and post toTwitter using this system.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 17 of 18

Page 18: Written By: Feitan - Amazon Web Services · This project uses the Seeed Studio GPRS/GSM Shield to build a versatile Arduino-based remote alarm system that can notify your cell phone

This document was last generated on 2017-06-17 10:57:31 AM.

Set up your Sensor Sentinel forlow power draw! Normal Arduinosaren't really meant for lowpower/long battery life, so wedidn't make power optimizationsin this sketch. However, youcould rig this up to "sleep" most ofthe time, and last a good amountof time on a battery, especially ifyou're only sending outgoingtexts.

You could even turn off thecellular module and program theArduino to only turn it on whenyou need to send a text.

Cellular Sensor Sentinel

© 2017 www.botsbits.org Page 18 of 18