Recipe that Beeps a Beeper and Sends a Text/Email Message When It Senses MotionThis 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. IngredientsFor this recipe, you will need:
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. ScriptYou can find the Script in the Scripts "examples" area. The Script is called "motion_detector_texting.script". The Script is as follows:
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:
Running the ScriptRun 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:
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:
|