Saturday, February 15, 2014

Get notified when your cookies are stolen!

I bought a new NL-SWDK-1xRTT-V development kit and wanted to do something fun and quick to test it out, so I hooked up a simple magnetic reed switch to an Arduino Leo and modified the development kit sample code to send me an SMS whenever someone opens the cookie cupboard.  The video and picture show you the pieces.  The operation is pretty straightforward.  You mount the magnetic switch near the edge of the door, and you mount a magnet on the door.  You arm the system by plugging in power.  The code takes a few seconds to initialize the modem, and then anytime the door opens in the future, I get a text message.  My sample code is provided below so others can replicate or improve!

There are a few cool things about the Skywire module:
1) its small 33mm x 29mm
2) its certified as an end-product on the Verizon network, so you can embed it into end products and skip the FCC and Carrier certification hassles found in typical product designs
3) it conforms to the XBee formfactor, so you can plug it into many existing development tools and upgrade legacy low-power RF products to communicate over the cellular network without any hardware re-design
4) the development kit is also an Arduino shield, so you can plug it right into your favorite Arduino and use the sample code to create something useful like this!
5) NimbeLink provides low cost Verizon plans ($5/mo for SMS only, $10/mo for <1MB data plans) so you can get your device activated and running on the network the same day without having to go through Verizon!
6) complete kit is only $262 on Digikey.com

Development kit on Arduino Leonardo plus Antenna and open/close sensor.






For more information, checkout the Skywire product page here.




/*
SMS Cookie alarm
This sketch is an example that sends SMS messages using the Telit CE910-DUAL modem.
Circuit:
* Arduino Leonardo
* Skywire development kit: NL-SWDK-1xRTT and NL-SW-1xRTT
created 2/15/2014
by Kurt Larson // NimbeLink.com
This example is in the public domain.
*/
#define DESTINATION_PHONE_NUMBER "15554443333"    // destination phone number of 1-555-444-3333 should be formated like: 15554443333
String SMS_MESSAGE = "Cookies are under attack! Sent via Arduino & Skywire cellular modem!";    // SMS message you want to send, limited to 160 characters
void setup()               // Initializes the pins, serial ports, modem
{
  pinMode(10, INPUT);       // Set I/O pin 10 to input for door open/close sensor
  pinMode(13, OUTPUT);      // Set LED pin to output
  digitalWrite(12, LOW);    // Set I/O pin 12 to low
  pinMode(12, OUTPUT);      // Configure I/O pin 12 as output
  digitalWrite(12, LOW);    // Drive I/O pin 12 low
  delay(1100);               // modem requires >1s pulse
  pinMode(12, INPUT);       // Return I/O pin 12 to input/hi-Z state and wait >10 seconds for modem software to boot up  
  delay(10000);             // modem documentation says wait 10 seconds
  Serial1.begin(115200);    // Initialize serial port to communicate with modem
  while (!Serial1) ;
  Serial1.println("AT+CMGF=1");  // put modem into text mode
  delay(250);                // wait for modem response
}
void loop() 
{
  if (digitalRead(10) == 1) {        // if the signal goes high, that means the open/close sensor is open, so send an alert
    digitalWrite(13, LOW);
    Serial1.print("AT+CMGS=\"+");
    Serial1.print(DESTINATION_PHONE_NUMBER);
    Serial1.print("\"\r");
    delay(250);
    Serial1.print(SMS_MESSAGE);
    Serial1.write(26);
    Serial1.write("\r");
    delay(300000);              // do not retrigger for 5 minutes
  }
 }
For more information, checkout the Skywire product page here.