#include <Wire.
h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int rainSensorPin = A0;
const int ldrPin = A1;
const int relayPin = 10;
const int motorIn1 = 5;
const int motorIn2 = 6;
const int ledPin = 11;
int rainThreshold = 500;
int lightThreshold = 600;
void setup() {
[Link](9600);
[Link](16, 2); // hoặc [Link](20, 4) tùy theo loại LCD bạn đang dùng
[Link]();
pinMode(relayPin, OUTPUT);
pinMode(motorIn1, OUTPUT);
pinMode(motorIn2, OUTPUT);
pinMode(ledPin, OUTPUT);
[Link](0, 0);
[Link]("He thong dang chay");
delay(2000);
[Link]();
}
void loop() {
int rainValue = analogRead(rainSensorPin);
int lightValue = analogRead(ldrPin);
[Link](0, 0);
[Link]("Rain: ");
[Link](rainValue);
[Link](0, 1);
[Link]("Light: ");
[Link](lightValue);
if (rainValue < rainThreshold) {
digitalWrite(relayPin, HIGH);
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(relayPin, LOW);
digitalWrite(ledPin, LOW);
}
if (lightValue < lightThreshold) {
digitalWrite(motorIn1, HIGH);
digitalWrite(motorIn2, LOW);
} else {
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, LOW);
}
delay(1000);
}