This circuit is designed to detect light using an LDR sensor. If no light is detected, it turns on an LED and rotates a motor clockwise. If light is detected, it turns off the LED and rotates the motor counter-clockwise. The system also detects temperature and humidity using a DHT11 sensor and displays this data on an LCD screen and an IoT system using ESP32. The motor can also be controlled via the IoT system, and temperature and humidity data can be viewed remotely.
Arduino UNO
L298N DC Motor Driver
DHT11 Humidity and Temperature Sensor
Hobby Gearmotor with 48:1 Gearbox
9V Battery
16x2 I2C LCD
LED: Two Pin (red)
Resistor
ESP32 (30 pin)
Module LDR
GND connected to:
5V connected to:
Vin connected to 9V Battery +
D2 connected to DHT11 Humidity and Temperature Sensor DATA
A0 connected to Module LDR AO
A4 connected to 16x2 I2C LCD SDA
A5 connected to 16x2 I2C LCD SCL
D7 connected to Resistor pin2
D6 connected to L298N DC Motor Driver IN4
D5 connected to L298N DC Motor Driver IN3
D4 connected to L298N DC Motor Driver IN2
D3 connected to L298N DC Motor Driver IN1
D1 connected to ESP32 (30 pin) RX0
D0 connected to ESP32 (30 pin) TX0
OUT1 connected to Hobby Gearmotor with 48:1 Gearbox pin 1
OUT2 connected to Hobby Gearmotor with 48:1 Gearbox pin 2
/*
* This Arduino sketch is for a system that detects light using an LDR sensor.
* If no light is detected, it turns on an LED and rotates a motor clockwise.
* If light is detected, it turns off the LED and rotates the motor counter-
* clockwise. The system also detects temperature and humidity using a DHT11
* sensor and displays this data on an LCD screen and an IoT system using ESP32.
* The motor can also be controlled via the IoT system, and temperature and
* humidity data can be viewed remotely.
*/
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2
#define DHTTYPE DHT11
#define LDRPIN A0
#define LEDPIN 7
#define IN1 3
#define IN2 4
#define IN3 5
#define IN4 6
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(LEDPIN, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
lcd.begin();
lcd.backlight();
dht.begin();
Serial.begin(115200);
}
void loop() {
int ldrValue = analogRead(LDRPIN);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (ldrValue < 500) {
digitalWrite(LEDPIN, HIGH);
rotateMotorClockwise();
} else {
digitalWrite(LEDPIN, LOW);
rotateMotorCounterClockwise();
}
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print(" %");
sendToESP32(t, h);
delay(2000);
}
void rotateMotorClockwise() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void rotateMotorCounterClockwise() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void sendToESP32(float temperature, float humidity) {
Serial.print("Temp:");
Serial.print(temperature);
Serial.print(", Humidity:");
Serial.println(humidity);
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
This documentation provides a comprehensive overview of the circuit, including a summary, detailed component list, wiring details, and the code used in the microcontrollers.