Software Overview  |  Sitemap  |  Downloads  |  Developers  |  Forums
Small_clear_logo_llc

Recipe that Beeps a Beeper 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.

Ingredients

For this recipe, you will need:

  • an Arduino (running Firmata)
  • a Grove Water Sensor (or equivalent)
  • a Grove Buzzer (or equivalent)

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.

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.

Script

You can find the Script in the Scripts "examples" area. The Script is called "moisture_detector_warning.script".

Run this Script and squeeze the sensor between your fingers. If your fingers are a little moist, the buzzer will sound. 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.

The Script is as follows:

# Makes a moisture detector that turns on an LED or buzzes a buzzer when
# there's moisture.
# Requires an Arduino with a Grove board, a Grove moisture detector, and
# an LED or buzzer (or equivalents).
# This Script has defaults for the location of the moisture detector and
# the LED/buzzer.  The moisture detector is on A0, and the LED is on pin 3.
# You can override the defaults when you run this Script.


# Set up defaults

# LED/buzzer location
BUZZER_PIN = 3
# moisture detector pin
MOISTURE_SENSOR_PIN = "A0"


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

optional_script_parameters(buzzer_pin:BUZZER_PIN, moisture_sensor_pin:MOISTURE_SENSOR_PIN)


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

# Create terminals for accessing devices in Arduino system.
# Sense input goes low when it senses moisture, so we'll call its "on"
# state "no_moisture".
run_script("Scripts/Device/Arduino/PinTypes/SchmittInputs", names:"no_moisture", pins:moisture_sensor_pin, arduino_id:"arduino")

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


# Since the sense of the moisture detector is inverted,
# add a Not gate to flip it back.
run_script("Scripts/Device/Virtual/Logic/Combinational/Not", id:"inverter")

# wire things together
wire "arduino:no_moisture","inverter:in"
wire "inverter:out","arduino:buzzer"

Catalina Computing, LLC.

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




Page last updated: Mon May 14 03:01:47 2018 (UTC)