Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled Servo with Rain Sensor Activation

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Servo with Rain Sensor Activation

Circuit Documentation

Summary

This circuit is designed to interface a rain sensor with an Arduino UNO microcontroller and control a servo motor based on the sensor's input. The rain sensor detects the presence of rain and sends a signal to the Arduino, which processes the input and drives the servo motor to a specific position depending on whether rain is detected or not.

Component List

RAIN SENSOR

Arduino UNO

Servo

Wiring Details

RAIN SENSOR

Arduino UNO

Servo

Documented Code

Arduino UNO Code

#include <Servo.h>

Servo tap_servo;

int sensor_pin = 4;
int tap_servo_pin = 5;
int val;

void setup(){
  pinMode(sensor_pin, INPUT);
  tap_servo.attach(tap_servo_pin);
}

void loop(){
  val = digitalRead(sensor_pin);

  if (val == 0) {
    tap_servo.write(0);
  }
  if (val == 1) {
    tap_servo.write(180);
  }
}

Description: This code snippet is for the Arduino UNO. It initializes the rain sensor input pin and the servo motor control pin. In the loop function, it reads the digital value from the rain sensor. If the sensor detects rain (val == 1), the servo is set to 180 degrees. If no rain is detected (val == 0), the servo is set to 0 degrees.

RAIN SENSOR Code

The rain sensor does not have associated embedded code as it is a passive sensor that provides an analog output to the Arduino UNO.

Servo Code

The servo is controlled directly by the Arduino UNO using the Servo library, and as such, it does not have separate embedded code.