Software Overview  |  Sitemap  |  Downloads  |  Developers  |  Forums
Small_clear_logo_llc

Recipe that Beeps a Beeper and Sends a Text/Email Message When It Senses Motion

This recipe uses an Arduino digital input pin to sense the voltage on a Grove PIR Motion Sensor (or equivalent). If the voltage from the sensor goes high, it sets an alarm and sends a text/email message. The alarm is controllable using text/email messages.

Ingredients

For this recipe, you will need:

  • an Arduino (running Firmata)
  • a Grove PIR Motion Sensor (or equivalent)
  • a Grove Buzzer (or equivalent)
  • a dedicated email account

If you are not using Grove devices, you can use any 5V buzzer that requires <= 40mA of current and any motion detector with a 5V compatible output. Many 3rd party motion detectors have an active low open collector or relay controlled output. These can be used if you pull up their outputs to 5V and invert them (using an Inverter Device).

You need an email account to which you can send messages to via SMTP and receive from using POP. Most email accounts support SMTP and POP interfaces. If you look on your provider's support page, you should find addresses for sending and receiving messages such as "smtp.provider.com" and "pop.provider.com". Once you know these addresses, you can use your account name and password to send and receive messages.

The address where your messages will be sent can be any email address. It can also be an email address for a text message (see the Email Addresses for Texting section). You can add additional addresses using the addEmailAddress Script.

Unlike configurations which only send messages, this Recipe can receive and respond to messages as well. Receiving requires that the Recipe poll your email account for email. Don't use an email account which has email you wish to keep, or which is receiving email you wish to read. When this Recipe picks up the mail, it cleans out the mailbox. It will act upon messages from users it recognizes, but all the messages it receives will be deleted.

Script

You can find the Script in the Scripts "examples" area. The Script is called "motion_detector_texting.script". The Script is as follows:

# Makes a motion detector that turns on an LED or buzzes a buzzer when
# there's motion, and it sends a text/email message as well.
# It also responds to text messages.
# Requires an Arduino with a Grove board, a Grove PIR Motion Detector, and
# an LED or buzzer (or equivalents).  You'll also need an email account you
# can SMTP messages to and poll using POP.
# This Script has defaults for the location of the motion sensor and
# the LED/buzzer.  The motion sensor is on pin 2, and the LED/buzzer is on pin 3.
# You can override the defaults when you run this Script.


# Set up defaults

# moisture detector pin
MOTION_SENSOR_PIN = 2
# LED/buzzer location
BUZZER_PIN = 3


# parameters for Arduino and its peripherals 

# arduino_port should be the file handle of the Arduino
script_parameters("arduino_port")

optional_script_parameters(buzzer_pin:BUZZER_PIN, motion_sensor_pin:MOTION_SENSOR_PIN)


# parameters for the text/email Device
# messaging_address is the text/email address to which and from where messages
# will be sent and received
# pop_host is the host name for POP polling - e.g. "pop.example.com"
# smtp_host is host name for SMTP - e.g. "smtp.example.com"
# user is the user's email address on the host - e.g "user@example.com"
# password is the user's password for the email account

script_parameters("messaging_address", "pop_host", "smtp_host", "password", "user")

optional_script_parameters(ssl_enable:true, smtp_port:587)




# arduino device
run_script("Scripts/Device/Arduino/Arduino", port_location:arduino_port, id:"arduino")

# Create terminals for accessing devices in Arduino system.
run_script("Scripts/Device/Arduino/PinTypes/DigitalInputs", names:"motion", pins:motion_sensor_pin, arduino_id:"arduino")

run_script("Scripts/Device/Arduino/PinTypes/DigitalOutputs", names:"buzzer", pins:buzzer_pin, arduino_id:"arduino")


# add an alarm generator (which self resets after an hour)
run_script("Scripts/Device/Virtual/Alarm/Alarm", duration:3600, id:"alarm")

# give it an input which looks for a motion alarm
run_script("Scripts/Device/Virtual/Alarm/InputTypes/Equal", alarm_id:"alarm", input_name:"motion", value:"on")


# Create a text messaging device.  Poll every 240 seconds (4 minutes)
run_script("Scripts/Device/EMail/TextMessagingPOP", email_address:messaging_address, gmail_polling:false, host:pop_host, id:"text_messenger", mail_subject:"Virtual Wiring Text Messenger", password:password, poll_interval:240, smtp_host:smtp_host, smtp_port:smtp_port, ssl_enable:ssl_enable, user_name:user)


# Wire things up
wire("text_messenger:out", "alarm:command")
wire("alarm:messages", "text_messenger:in")
wire("arduino:motion", "alarm:motion")
wire("alarm:alarm", "arduino:buzzer")

To run this Script, you need 10 parameters: arduino_port, motion_sensor_pin, buzzer_pin, pop_host, smtp_host, smtp_port, ssl_enable, user, password, and messaging_address.

The arduino_port parameter is the name of the USB port of the Arduino. On *nix hosts, the USB port name is in the "/dev" directory. To see the devices in order of their creation, type "ls -lrt /dev" at a shell prompt and look near the bottom of the list for your Arduino's USB port.

The motion_sensor_pin and buzzer_pin are the pin numbers on the Arduino where the motion sensor and buzzer are connected.

The pop_host is the name of the POP server hosting the email account, and the smtp_host and smtp_port are the name and port of the SMTP server hosting the email account. ssl_enable determines whether SSL will be used when talking to the server. The user parameter is the user name of the email account on the server and the password parameter is the password for the email account. The messaging_address is the email/texting address of the device that will be controlling the system.

As an example, for an Arduino at USB port "/dev/cu.usbserial-00002006" with a buzzer at pin 3 and a motion sensor at pin 2, an email server using SSL with name "email_server" with an email account of "user" and a password of "secret", and a controlling device which is a Verizon cell phone with phone number 111-555-1212, the Script parameters are:

arduino_port: "/dev/cu.usbserial-00002006"
motion_sensor_pin: 2
buzzer_pin: 3
pop_host: "pop.email_server"
smtp_host: "smtp.email_server"
smtp_port: 587
ssl_enable: true
user: "user"
password: "secret"
messaging_address: "1115551212@vtext.com"

Running the Script

Run the Script above with your own parameters (remember, if you make a mistake, you can edit what you've done on the Console page). Wave your hand over the motion sensor. The buzzer will sound, and you'll get a message that looks like this:

Alarm is on

motion: ALARM!

You may wish to turn off your buzzer (the alarm will persist for an hour). Respond to your message with a one word message of: "reset" (no quotes in your message). (See the Alarm "command" Input Terminal section for details on other possible messages.) After an Email Device poll period (4 minutes in this Script) or less, your alarm will turn off, and you'll receive a message that looks like this:

Resetting Alarm

Catalina Computing, LLC.

Copyright © Catalina Computing, LLC. (2013-2017)




Page last updated: Tue Oct 13 12:56:49 2015 (UTC)