#include <Adafruit_Sensor.h>
#include <DHT.h>
#define BUZZER_PIN 14 // Replace with the pin your buzzer is connected to
#define LDR_PIN 26 // Replace with the pin your LDR sensor is connected to
const int DHT_PIN = 15;
#define RAIN_ANALOG 34
#define RAIN_DIGITAL 16
DHT dhtSensor(DHT_PIN, DHT22);
void setup() {
Serial.begin(115200);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LDR_PIN, INPUT);
pinMode(RAIN_ANALOG, INPUT);
pinMode(RAIN_DIGITAL, INPUT);
analogReadResolution(10);
}
void loop() {
// Read temperature and humidity from DHT22
float temperature = dhtSensor.readTemperature();
float humidity = dhtSensor.readHumidity();
Serial.println("Temp: " + String(temperature, 2) + "°C");
Serial.println("Humidity: " + String(humidity, 1) + "%");
Serial.println("---");
// Read LDR sensor value
int ldrValue = analogRead(LDR_PIN);
Serial.println("LDR Value: " + String(ldrValue));
// Read rain sensor values
int rainAnalogValue = analogRead(RAIN_ANALOG);
bool isRaining = digitalRead(RAIN_DIGITAL);
Serial.print("Rain Analog Value: ");
Serial.println(rainAnalogValue);
if (isRaining) {
Serial.println("It's raining!");
tone(BUZZER_PIN, 1000); // Play a tone for rain condition
} else {
noTone(BUZZER_PIN); // Turn off the buzzer if no rain condition
}
// Check conditions and control buzzer
if (temperature >= 40.0 && humidity >= 60.0) {
tone(BUZZER_PIN, 1500); // Play a tone for DHT22 conditions
} else if (ldrValue > 300) {
tone(BUZZER_PIN, 2000); // Play a tone for LDR conditions
} else {
noTone(BUZZER_PIN); // Turn off the buzzer if no conditions are met
}
delay(2000); // Adjust this delay as needed
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
chip1:VCC
chip1:GND
chip1:DO
chip1:AO
bz1:1
bz1:2
r1:1
r1:2
ldr1:VCC
ldr1:GND
ldr1:DO
ldr1:AO
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND