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, 2014 at 23:34
  • 1
    you might consider purchasing Prowl, it can send Push Notifications to your Phone: prowlapp.com
    – Gotschi
    Jan 31, 2014 at 12:51

4 Answers 4


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.



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).


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.


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

// 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
    pinMode(MOTION_PIN, INPUT);

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

            // 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;

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, 2014 at 17:14

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



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.


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.


More on the low light difference between CMOS and CCD;


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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