Circuit Documentation
Summary
This circuit is designed to automatically control a rooftop based on rain detection. The system uses an Arduino Uno R3 microcontroller to read inputs from a rain sensor and a limit switch, and to control two DC motors via an L298N motor driver. Additionally, a buzzer provides audible feedback, and a 16x2 I2C LCD displays the status of the rooftop.
Component List
L298N DC Motor Driver
- Description: Motor driver used to control the direction and speed of two DC motors.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
12V Adapter
- Description: Power supply providing 12V DC.
- Pins: VCC, GND
Arduino Uno R3
- Description: Microcontroller used to control the entire system.
- Pins: D8, D9, D10, D11, D12, D13, GND, AREF, SDA, SCL, D0/RX, D1/Tx, D2, D3, D4, D5, 6, D7, A5/SCL, A4/SDA, A3, A2, A1, A0, Vin, 5V, 3.3V, RESET, IOREF, NONE, USB Jack, Power Jack
Rain Sensor
- Description: Sensor used to detect rain.
- Pins: AO, DO, GRD, VCC
16x2 I2C LCD
- Description: LCD display used to show the status of the rooftop.
- Pins: GND, VCC, SDA, SCL
DC Motor (2 units)
- Description: Motors used to open and close the rooftop.
- Pins: pin 1, pin 2
Buzzer
- Description: Provides audible feedback.
- Pins: GND, IN
Limit Switch
- Description: Switch used to detect the position of the rooftop.
- Pins: NC, No, COM
Wiring Details
L298N DC Motor Driver
- GND connected to Arduino Uno R3 GND and 12V Adapter GND
- 12V connected to 12V Adapter VCC
- 5V connected to Arduino Uno R3 Vin
- OUT1 connected to DC Motor pin 1
- OUT2 connected to DC Motor pin 2
- OUT3 connected to DC Motor pin 1
- OUT4 connected to DC Motor pin 2
- IN1 connected to Arduino Uno R3 D9
- IN2 connected to Arduino Uno R3 D10
12V Adapter
- GND connected to Arduino Uno R3 GND and L298N DC Motor Driver GND
- VCC connected to L298N DC Motor Driver 12V
Arduino Uno R3
- GND connected to L298N DC Motor Driver GND, 12V Adapter GND, Rain Sensor GRD, 16x2 I2C LCD GND, Limit Switch COM, and Buzzer GND
- 5V connected to Rain Sensor VCC and 16x2 I2C LCD VCC
- Vin connected to L298N DC Motor Driver 5V
- D9 connected to L298N DC Motor Driver IN1
- D10 connected to L298N DC Motor Driver IN2
- D8 connected to Buzzer IN
- D2 connected to Rain Sensor DO
- D3 connected to Limit Switch No
- A5/SCL connected to 16x2 I2C LCD SCL
- A4/SDA connected to 16x2 I2C LCD SDA
Rain Sensor
- VCC connected to Arduino Uno R3 5V
- GRD connected to Arduino Uno R3 GND
- DO connected to Arduino Uno R3 D2
16x2 I2C LCD
- VCC connected to Arduino Uno R3 5V
- GND connected to Arduino Uno R3 GND
- SCL connected to Arduino Uno R3 A5/SCL
- SDA connected to Arduino Uno R3 A4/SDA
DC Motor (1)
- pin 1 connected to L298N DC Motor Driver OUT1
- pin 2 connected to L298N DC Motor Driver OUT2
DC Motor (2)
- pin 1 connected to L298N DC Motor Driver OUT3
- pin 2 connected to L298N DC Motor Driver OUT4
Buzzer
- GND connected to Arduino Uno R3 GND
- IN connected to Arduino Uno R3 D8
Limit Switch
- COM connected to Arduino Uno R3 GND
- No connected to Arduino Uno R3 D3
Documented Code
Arduino Uno R3 Code
// Define pins
const int rainSensorPin = 2; // Digital pin connected to rain sensor
const int motorPin1 = 9; // Motor driver input pin 1
const int motorPin2 = 10; // Motor driver input pin 2
const int buzzerPin = 8; // Buzzer pin
const int limitSwitchPin = 3; // Digital pin connected to limit switch
// Define states
bool isRoofClosed = false;
void setup() {
// Initialize pins
pinMode(rainSensorPin, INPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(limitSwitchPin, INPUT_PULLUP); // Assuming limit switch is normally open
// Start with the roof open
openRoof();
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int rainDetected = digitalRead(rainSensorPin);
int limitSwitchState = digitalRead(limitSwitchPin);
if (rainDetected == LOW && !isRoofClosed) {
// Rain detected, close the roof
closeRoof();
} else if (rainDetected == HIGH && isRoofClosed) {
// No rain, open the roof
openRoof();
}
// Check if the limit switch is triggered
if (limitSwitchState == LOW) {
// Stop the motor if the limit switch is triggered
stopMotor();
digitalWrite(buzzerPin, LOW);
}
delay(1000); // Check every second
}
void closeRoof() {
Serial.println("Closing Roof...");
// Rotate motor to close the roof
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
// Beep the buzzer while closing the roof
digitalWrite(buzzerPin, HIGH);
// Assuming it takes 5 seconds to close the roof
delay(5000);
// Stop the motor and buzzer
stopMotor();
digitalWrite(buzzerPin, LOW);
isRoofClosed = true;
}
void openRoof() {
Serial.println("Opening Roof...");
// Rotate motor to open the roof
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
// Beep the buzzer while opening the roof
digitalWrite(buzzerPin, HIGH);
// Assuming it takes 5 seconds to open the roof
delay(5000);
// Stop the motor and buzzer
stopMotor();
digitalWrite(buzzerPin, LOW);
isRoofClosed = false;
}
void stopMotor() {
// Stop the motor by setting both inputs to LOW
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
}
16x2 I2C LCD Code
/*
* Automatic Rooftop Sensor
* This code interfaces with a 16x2 I2C LCD to display the status of the
* rooftop (open or closed) based on the rain sensor input.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD, set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the LCD
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Rooftop Status:");
}
void loop() {
// Read the rain sensor status from the Arduino Uno
int rainDetected = digitalRead(2); // Assuming rain sensor is connected to pin D2
lcd.setCursor(0, 1);
if (rainDetected == LOW) {
lcd.print("Closing Roof
