Categories
TUTORIALS

Rain Sensor Trigger for Servo Motor

This tutorial is the third one in the series corresponding to the Sunbrella project for the Sensing the City course taught by Allison Lassiter for students in the University of Pennsylvania’s Department of City and Regional Planning.

This tutorial will focus on how to create a rain (water) trigger override for a motor using an Adafruit Analog Water Sensor. The mechanism aims to override the default setting of the servo motor (as coded in Using photoresistors and a servo motor to make a single-axis solar tracker by Delfina Vildosola) such that it adjusts the roof to a predefined position for optimum rain protection. This tutorial is also in series with the tutorial by Laura Frances: Using a solar cell and rechargeable battery to power a servo motor.

Parts List

Adafruit Analog Water Sensor

Included in kit:

Arduino Uno

Servo Motor

Breadboard

Jumper wires

9V Battery

Sensor Specifications

  • A water sensor that is compatible with Arduino UNO board.
  • Adafruit Analog Water Sensor is a simple analog water sensor that can be used to detect the presence or absence of water. It works by measuring the resistance between two exposed electrodes on the sensor, which changes when water is present. It can be connected directly to an analog input on the Arduino board and costs around $1.95.
  • Description from the website: The sensor has a very lightly biased transistor that is connected to two long sets of interlocking traces. When a little bit of water/condensation lands on the PCB and touches two of the traces, the transistor will turn on, setting the output pin high. The output voltage does vary a bit with how much water is detected, but honestly, we recommend just using it as an “on or off” type sensor. (source: https://www.adafruit.com/product/4965) 
Circuit Diagram

Here’s the circuit diagram for the rain trigger override circuit:

Circuit Diagram for Water Sensor Trigger made using Cirkit Designer.

In this circuit, the motor is connected to the motor driver, which is controlled by the Arduino. The Adafruit Analog Water Sensor is connected to the Arduino analog input pin A0.

Connections: connect the minus (-) pin to the ground, connect the plus (+) pin to 5V DC, and then the output signal pin (S) goes to your breadboard. For servo motor connections and roof connections, refer to Using photoresistors and a servo motor to make a single-axis solar tracker by Delfina Vildosola.

Step 1: Connect the circuit

Connect the circuit according to the circuit diagram above. Make sure all connections are secure and correctly placed.

Step 2: Upload the code

Upload the code to the Arduino using the Arduino IDE. Make sure the correct board and serial port are selected in the IDE.

Step 3: Test the circuit

Power on the circuit and test it by pouring some water on the Adafruit Analog Water Sensor. The motor should move in one direction when the water level is high, and move in the opposite direction when the water level is low.

Step 4: Customize the code

You can customize the code by changing the water level threshold that triggers the motor movement. We set a threshold at 500, but you can adjust this to suit your needs.

Code

Here’s the code for the rain trigger override circuit:


In this code, the Adafruit Analog Water Sensor is read using the analogRead() function. If the water level is high (i.e., rain is detected), the motor is moved in one direction using the digitalWrite() function. If the water level is low (i.e., no rain is detected), the motor is moved in the opposite direction to assume the default position.

Leave a Reply

Your email address will not be published. Required fields are marked *