Email Sending Motion Detector

Overview:

In this lesson you will learn how to use a PIR movement detector with an Arduino and to have the Arduino communicate with a Python program running on your computer to send an email whenever movement is detected by the sensor.

The Arduino is the heart of this project. It 'listens' to the PIR sensor and when motion is detect, instructs the computer via the USB port to send an email.

Materials Needed:

You will also need a computer with an Internet connection (so you can send email thru it)!

  • (1) PIR Sensor
  • (1) Arduino Uno R3
  • (1) Half-size breadboard
  • Jumper wires

Code:

int pirPin = 7;

 

int minSecsBetweenEmails = 60; // 1 min

 

long lastSend = -minSecsBetweenEmails * 1000l;

 

void setup()

{

  pinMode(pirPin, INPUT);

  Serial.begin(9600);

}

 

void loop()

{

  long now = millis();

  if (digitalRead(pirPin) == HIGH)

  {

    if (now > (lastSend + minSecsBetweenEmails * 1000l))

    {

      Serial.println("MOVEMENT");

      lastSend = now;

    }

    else

    {

      Serial.println("Too soon");

    }

  }

  delay(500);

}

Layout:

Schematic: