This circuit is designed to monitor environmental conditions using various sensors and control a servo motor based on the detected conditions. The circuit includes an Arduino UNO microcontroller, a DHT11 temperature and humidity sensor, a SparkFun Soil Moisture Sensor, a rain sensor, and a servo motor. The Arduino UNO reads data from the sensors and controls the servo motor based on the sensor readings.
Arduino UNO
SparkFun Soil Moisture Sensor
DHT11
RAIN SENSOR
Servo
// Including all Libraries
#include <Adafruit_Sensor.h>
#include <Servo.h>
#include <dht.h>
// Defining pins as variables
#define rsp A0
#define sp 5
#define smp A1
#define DHT11PIN 4
Servo servo;
dht DHT;
// Defining variables for later
int rainState;
int moi;
float hum;
float temp;
void setup() {
// Beginning the serial monitor
Serial.begin(9600);
// making pins inputs
pinMode(rsp, INPUT);
// servo init settings
servo.attach(sp);
servo.write(0);
// defining rain state as the rain sensor value
rainState = digitalRead(rsp);
}
void loop() {
int chk = DHT.read11(DHT11PIN);
// Defining the previous variables
moi = analogRead(smp);
hum = DHT.humidity;
temp = DHT.temperature;
// If-else statement for Rain Sensor - Servo Arrangement
if (rainState <= 600) {
servo.write(90);
Serial.println("RAIN!!!");
} else {
servo.write(0);
Serial.println("NO RAIN!!");
}
Serial.print(temp);
Serial.print("x");
Serial.println(hum);
delay(2000);
}
This code initializes the sensors and servo motor, reads data from the sensors, and controls the servo motor based on the rain sensor's readings. The temperature and humidity data are also printed to the serial monitor.