Recipe that Beeps a Beeper and Sends a Text/Email Message When It Senses Water
This recipe uses an Arduino analog input pin to sense the voltage on a Grove Water Sensor. If the voltage from the sensor goes low, it beeps a beeper and sends a text/email message.
For this recipe you will need:
If you are not using Grove devices, any 5V buzzer that requires 40mA of current or less can be connected to the Arduino output and ground. Instead of a Grove Water Sensor, you can use two wires. One should be connected to ground, and the other pulled up with a ~1Meg resistor to 5V and connected to the Arduino analog input.
You will need an email account to which you can send messages via SMTP. Most email accounts support an SMTP interface. If you look on your provider's support page, you should find an address for sending messages to such as "smtp.provider.com". Once you have that, you can use your account name and password to send 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.
Note that the Arduino analog input is a Schmitt trigger input. Schmitt triggers have good noise immunity, and this weak ~1Meg pullup resistor input is susceptible to noise.
You can find the Script in the Scripts "examples" area. The Script is called "moisture_detector_texting.script". The Script is as follows:
To run this Script, you need 9 parameters: arduino_port, buzzer_pin, moisture_sensor_pin, smtp_host, smtp_port, smtp_user, ssl_enable, password, and to_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 moisture_sensor_pin and buzzer_pin are the pin numbers on the Arduino where the moisture sensor and buzzer are connected.
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 smtp_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 to_address is the email/texting address of the device that will be receiving text/email messages.
As an example, for an Arduino at USB port "/dev/ttyUSB0" with a buzzer at pin 3 and a moisture 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 text receiving device which is a Verizon cell phone with phone number 111-555-1212, the Script parameters are:
Running the Script
Run the Script and squeeze the sensor between your fingers. If your fingers are a little moist, the buzzer will sound and you'll get a message. You can also make the buzzer sound by sticking the sensor in water. Make sure the water is not distilled water, however, as it is a poor conductor.
When you trip your moisture detector, here is what your message will look like: