Software Overview  |  Sitemap  |  Downloads  |  Developers  |  Forums
Small_clear_logo_llc

Recipe that Sends a Text/Email Message When It Senses Different Things

This recipe uses an Arduino to sense water, motion, and temperature. When it senses water or motion, it sets an alarm and sends a text message. When it senses temperature outside of a range, it sets an alarm and sends a text message. The alarm is controllable using text/email messages.

This Recipe demonstrates the flexibility of the Arduio I/O system and the Alarm Device. Using Arduino sensors and the Alarm Device, one can monitor many different kinds of sensors.

Ingredients

For this recipe, you will need:

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

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 "multi_sensor_texting.script". The Script is as follows:

# Makes a detector senses water, motion and temperature.
# When triggered, sends a text/email message.
# It also responds to text messages.
# Requires an Arduino with a Grove board, a Grove Water Sensor,
# PIR Motion Sensor, and a Temperature Sensor (or equivalents).
# You will also need an email account you can SMTP messages to and
# poll using POP.
# This Script has defaults for the locations of the water, motion and
# temperature sensors.
# The water sensor is on A0, motion sensor is on pin 2, and the temperature
# sensor is on A1.
# You can override the defaults when you run this Script.


# Set up defaults

WATER_SENSOR_PIN = "A0"
TEMPERATURE_SENSOR_PIN = "A1"
MOTION_SENSOR_PIN = 2


# parameters for Arduino and its peripherals 

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

optional_script_parameters(water_sensor_pin:WATER_SENSOR_PIN)
optional_script_parameters(temperature_sensor_pin:TEMPERATURE_SENSOR_PIN)
optional_script_parameters(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/SchmittInputs", names:"no_water", pins:water_sensor_pin, arduino_id:"arduino")

# measure temp in F or C - choose Script below
run_script("Scripts/Device/Arduino/Devices/Seeed/TemperatureSensor_F", arduino_id:"arduino", name:"temp_F", pin:temperature_sensor_pin)
#run_script("Scripts/Device/Arduino/Devices/Seeed/TemperatureSensor_C", arduino_id:"arduino", name:"temp_C", pin:temperature_sensor_pin)



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

# give it inputs which look for a motion and water
run_script("Scripts/Device/Virtual/Alarm/InputTypes/Equal", alarm_id:"alarm", input_name:"motion", value:"on")
# note water detector is active low
run_script("Scripts/Device/Virtual/Alarm/InputTypes/Equal", alarm_id:"alarm", input_name:"water", value:"off")

# give it an input which looks for a range of (Fahrenheit temperatures)
# range is <60 and >80
run_script("Scripts/Device/Virtual/Alarm/InputTypes/GreaterThan", alarm_id:"alarm", input_name:"temp", value:80)
run_script("Scripts/Device/Virtual/Alarm/InputTypes/LessThan", alarm_id:"alarm", input_name:"temp", value:60)


# 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("arduino:motion", "alarm:motion")
wire("arduino:no_water", "alarm:water")
wire("arduino:temp_F", "alarm:temp")
wire("text_messenger:out", "alarm:command")
wire("alarm:messages", "text_messenger:in")

To run this Script, you need 11 parameters: arduino_port, motion_sensor_pin, temperature_sensor_pin, water_sensor_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, temperature_sensor_pin, and water_sensor_pin are the pins on the Arduino where the motion sensor, temperature sensor, and water sensor 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/ttyUSB0" with a motion sensor at pin 2, a temperature sensor at pin "A1", and a water sensor at pin "A0", 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/ttyUSB0"
motion_sensor_pin: 2
temperature_sensor_pin: "A1"
water_sensor_pin: "A0"
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 and wave your hand over the motion sensor, stick the Water Sensor in water, or heat the Temperature Sensor in you hand. You'll get messages that look like this:

Alarm is on

motion: ALARM!
temp: clear (75.7)
water: clear

You may wish to reset your alarm. 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-2018)




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