8

I'm just starting out. How could I use my Raspberry Pi to do the following: when any movement is detected at my front door, send me a text message (SMS)?

  • 2
    It seems like might be better off as two questions. How to detect movement and how to send SMS. – Jivings Jan 30 '14 at 23:34
  • 1
    you might consider purchasing Prowl, it can send Push Notifications to your Phone: prowlapp.com – Gotschi Jan 31 '14 at 12:51
11

My answer is in two parts, one for motion detection and another for SMS. A project like this has two components: hardware and software. Detecting motion is the hardware part and everything else is software.

Motion

Hardware

To detect movement, get a motion sensor. I use the Parallax PIR Motion Sensor: Amazon affiliate link here. The sensor has 3 pins: GND, VCC and OUT. Connect the pins to your RPi or connect them to a breadboard and connect the pins from the RPi to the same breadboard. Connect GND to a GND pin (6), VCC to a 3.3v pin (1) and OUT to GPIO0 (11).

Software

I recommend you use the WiringPi library. Follow these instructions to download and install the library on your Pi: Wiring Pi Library Download and Install. The pin on the motion sensor reads High if motion is detected and Low if it's not.

The motion detector resets itself after about 10 seconds when continuous motion ends. So the pin could fire many times in response to a single motion. To avoid getting SMS messages every few seconds, you probably want to include logic in your program to wait a certain amount of time before sending another SMS.

SMS

There are a few different ways you can do this. One way is to subscribe to a paid service that provides a library you can call with the pertinent information to send the SMS. Twilio API Libraries is a good example of this.

If you don't want to spend any money and you have a Google Voice number connected to your cellphone, you can use the Google Voice C++ API that Steven Hickson developed for the RPi (Google Voice C++ API). The end result might look something like this (I wrote it but did not load and test it on the RPi):

#include <wiringPi.h>
#include <time.h>
#include <string.h>
#include "gvoice.h"

int sendSMS(void);

#define MOTION_PIN 0
#define MINUTES_TO_WAIT 5

// some made-up error codes for SMS result
#define SUCCESS 0
#define LOGIN_ERROR 1
#define SMS_ERROR 2

static char *number = "2125551212", *message = "Motion detected!";

int main(int argc, char** argv) {
    time_t lastSent, now;
    int result;

    // track the time we sent the last SMS
    lastSent = time(NULL) - 60*(MINUTES_TO_WAIT + 1)

    // set up motion pin
    wiringPiSetup();
    pinMode(MOTION_PIN, INPUT);

    while (true) {
        if (digitalRead(MOTION_PIN)==HIGH) { // motion detected
            // get the current time
            time(&now);

            // if we've waited long enough, send a message
            if (difftime(now, lastSent)/60) > MINUTES_TO_WAIT) {
                if (result = sendSMS()) {
                    print("Message sent!\n");
                    lastSent = now;
                } else {
                    printf("Error %d. Message not sent!\n", result);
                }
            }
        }
    }

}

int sendSMS(void) {
    // Uses the Google Voice C++ API by Steven Hickson
    GoogleVoice gv;
    char *username = "username", *password = "password";

    if (gv.Login(username, password)) {
        if (gv.SendSMS(number, message)) {
            return SUCCESS;
        } else {
            return SMS_ERROR;
        }
    } else {
        return LOGIN_ERROR;
    }
}
4

simple web-camera + "motion" software (you may install it with 'sudo apt-get install motion') should take care about the first part of the question. motion has plenty of parameters in the configuration file, you may run external scripts when the motion is detected.

the second part of your question (re: SMS) will require internet connection and subscription to some kind of SMS sending service. there might be free ones available in your area, but I cannot promise you that. basically, the SMS delivery service company will provide you with the SMS sending scripts written in a few languages, you may choose the one you like and use it to send messages when "motion" detects anything interesting.

  • Thanks I'll give the motion software a try! – G. Lombard Jan 31 '14 at 17:14
2

For the SMS part, simply use email to your cell phone's email address. e.g. your10digitnumber@vtext.com / @txt.att.com / @tmomail.com

http://www.makeuseof.com/tag/email-to-sms/

2

There is a project that builds a security camera from a Raspberry Pi and Motion software (see link below). Note that the Pi camera (CMOS)is not a low light camera like many more expensive security cameras (CCD) and needs sufficient light to obtain a workable video stream.

http://www.raspberrypi.org/archives/5071

There is an IR camera available as well, though it also does not collect collect much light, so more IR irradiance is needed to achieve the same result that the more expensive security cameras achieve.

http://www.raspberrypi.org/forum/viewtopic.php?t=63115

More on the low light difference between CMOS and CCD;

http://www.axis.com/products/video/camera/ccd_cmos.htm

However, some backside-illuminated CMOS image sensosrs are starting to catch up in the low light category;

http://www.techhive.com/article/246931/cmos_is_winning_the_camera_sensor_battle_and_heres_why.html?page=2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.