This circuit integrates an Arduino UNO microcontroller with a YL-83 Rain Sensor system and a Tower Pro SG90 servo motor. The Arduino UNO reads the analog output from the rain sensor's control board and controls the servo motor based on the sensor's readings. The servo motor is used to actuate a mechanism, such as opening or closing a tap, in response to the detection of rain.
#include <Servo.h>
Servo tap_servo;
int sensor_pin = 4; // Analog input pin connected to the rain sensor
int tap_servo_pin = 5; // Digital output pin connected to the servo signal line
int val; // Variable to store the sensor reading
void setup() {
pinMode(sensor_pin, INPUT); // Initialize the sensor pin as an input
tap_servo.attach(tap_servo_pin); // Attach the servo motor to its control pin
}
void loop() {
val = digitalRead(sensor_pin); // Read the digital value from the rain sensor
if (val == 0) {
tap_servo.write(0); // If no rain is detected, set servo to position 0
}
if (val == 1) {
tap_servo.write(180); // If rain is detected, set servo to position 180
}
}
Filename: sketch.ino
Description: This code snippet is responsible for reading the digital output from the rain sensor and controlling the servo motor accordingly. When the sensor detects rain (represented by a high signal), the servo is set to its 180-degree position. Conversely, when no rain is detected (represented by a low signal), the servo is set to its 0-degree position.