Smart Rain Protection System With Automatic Clothes Retracting Mechanism and Environmental Monitoring
by am4759 in Circuits > Raspberry Pi
17 Views, 0 Favorites, 0 Comments
Smart Rain Protection System With Automatic Clothes Retracting Mechanism and Environmental Monitoring
Introduction
Rain can create problems when clothes are drying outside. If nobody is available to bring the clothes inside, they can become wet. To solve this problem, I developed a Smart Rain Protection System that automatically protects clothes when rainfall is detected.
The system uses an Arduino Nano 33 IoT and a rain sensor to detect rainfall. It has two servo motors. The first servo moves the clothes-hanging pipe inwards, while the second servo rotates a bottom protective wall upwards. This helps protect the clothes from rain.
The system also uses green and red LEDs to indicate the weather condition. The green LED indicates that rain has not been detected, while the red LED indicates that rain has been detected.
In addition to rain protection, the project monitors air humidity and soil moisture using sensors. The sensor readings are sent wirelessly to a Raspberry Pi 4 using MQTT communication. A Python dashboard displays the collected information.
The main objective of this project is to combine automatic rain protection, environmental monitoring and IoT technology in one system.
Supplies
Hardware Requirements
- Arduino Nano 33 IoT – Main controller.
- Raspberry Pi 4 – MQTT broker and monitoring dashboard.
- Rain sensor – Detects rainfall.
- Soil moisture sensor – Measures soil moisture.
- Humidity sensor – Measures air humidity.
- Servo motor 1 – Moves the clothes-hanging pipe inwards.
- Servo motor 2 – Rotates the bottom protective wall upwards.
- Green LED – Indicates that rain is not detected.
- Red LED – Indicates that rain is detected.
- Jumper wires – Connect the electronic components.
- External regulated power supply – Supplies power to the servo motors.
- Mechanical clothes-hanging pipe and protective wall – Provides the physical rain protection mechanism.
Software Requirements
- Arduino IDE – Arduino programming.
- Raspberry Pi OS – Raspberry Pi operating system.
- Python 3 – Dashboard programming.
- Mosquitto – MQTT broker.
- Paho MQTT – Python MQTT communication.
- Tkinter – Dashboard interface.
- Wi-Fi network – Wireless communication.
— Understanding the Smart Rain Protection System
Understanding the Smart Rain Protection System
The Smart Rain Protection System is designed to protect clothes from rain automatically. When the rain sensor detects rainfall, the system activates two servo motors to move the clothes-protection mechanism.
The first servo motor moves the clothes-hanging pipe inwards to protect the clothes. The second servo motor rotates the bottom protective wall upwards. These movements help prevent rainwater from reaching the clothes.
The system also uses two LEDs to show the weather condition:
- Green LED: Indicates that rain has not been detected.
- Red LED: Indicates that rain has been detected.
A buzzer provides an additional alert when rain is detected.
Along with rain detection, the system monitors air temperature, air humidity and soil moisture. An Arduino Nano 33 IoT collects the sensor readings and sends the information wirelessly to a Raspberry Pi 4 using MQTT communication. A Python dashboard on the Raspberry Pi displays the monitoring information.
The main components work together to provide automatic rain protection and environmental monitoring.
— Collecting the Required Components
Collecting the Required Components
Before building the project, I collected the hardware and software components required for the system.
Hardware Components
- Arduino Nano 33 IoT – Main controller.
- Raspberry Pi 4 – Receives and displays monitoring data.
- Rain sensor module – Detects rainfall.
- Soil moisture sensor – Measures soil moisture.
- DHT11 sensor – Measures air temperature and humidity.
- First servo motor – Moves the clothes-hanging pipe.
- Second servo motor – Rotates the bottom protective wall.
- Green LED – Indicates dry weather.
- Red LED – Indicates rain.
- Buzzer – Provides an alert during rainfall.
- Jumper wires – Connect the electronic components.
- Breadboard – Helps with circuit connections.
- Suitable regulated external power supply for the servo motors.
- Mechanical clothes-hanging pipe and protective wall.
Software and Tools
- Arduino IDE – Used to write and upload the Arduino program.
- Raspberry Pi OS – Operating system for the Raspberry Pi.
- Python 3 – Used to develop the monitoring dashboard.
- Mosquitto MQTT Broker – Handles MQTT messages.
- Paho MQTT – Python library for MQTT communication.
- Tkinter – Used to create the dashboard interface.
- Wi-Fi – Provides wireless communication.
— Understanding the Circuit Connections
Understanding the Circuit Connections
The Arduino Nano 33 IoT is the main controller of the project. All the sensors and output devices are connected to it.
The connections used in my Arduino program are:
ComponentArduino Pin
Rain sensor
A0
Soil moisture sensor
A1
DHT11 sensor data
D2
Green LED
D4
Red LED
D5
Buzzer
D6
First servo motor
D9
Second servo motor
D10
The rain sensor and soil moisture sensor provide analogue readings to the Arduino. The DHT11 sensor provides temperature and humidity readings.
The two servo motors receive control signals from the Arduino. The LEDs and buzzer provide visual and sound alerts.
— Building the Clothes Protection Mechanism
Building the Clothes Protection Mechanism
The mechanical section contains a clothes-hanging pipe and a bottom protective wall. Both parts are controlled using separate servo motors.
The first servo motor is connected to the clothes-hanging pipe. During normal weather, the pipe remains in its normal extended position. When rain is detected, the servo rotates to move the pipe inwards.
The second servo motor controls the bottom protective wall. During normal weather, the wall stays in its normal position. When rain is detected, the servo rotates in the opposite direction to move the wall upwards.
The two servo motors are controlled by the Arduino program. This allows both mechanical movements to happen automatically when the rain sensor detects rainfall.
The actual mechanical arrangement should be checked to make sure that the pipe and wall can move freely without hitting other parts of the structure.
— Connecting the Sensors
Connecting the Sensors
Three sensors are used to collect environmental information.
1. Rain Sensor
The rain sensor is connected to analogue pin A0. It provides a reading that changes depending on the amount of water detected.
The Arduino compares this reading with predefined threshold values:
- Below 750: Rain is detected.
- Above 800: The system changes back to dry condition.
- Between 750 and 800: The previous rain condition is maintained.
This difference between the two thresholds helps prevent the system from repeatedly switching between rain and dry conditions when the reading changes slightly.
2. Soil Moisture Sensor
The soil moisture sensor is connected to analogue pin A1. It provides a reading that represents the soil moisture level.
The program uses 650 as its threshold:
- Above 650: The soil is classified as dry.
- 650 or below: The soil is classified as moist.
This sensor is used for environmental monitoring and does not control the servo motors.
3. DHT11 Sensor
The DHT11 sensor is connected to digital pin D2. It measures air temperature and humidity.
The Arduino reads the DHT11 sensor approximately every 2.5 seconds. These readings are later included in the MQTT data sent to the Raspberry Pi.
Together, these sensors provide information about rainfall, soil moisture, temperature and humidity.
— Connecting the LEDs and Buzzer
Connecting the LEDs and Buzzer
The project uses two LEDs and a buzzer to provide alerts.
The green LED is connected to digital pin D4, while the red LED is connected to digital pin D5. The buzzer is connected to digital pin D6.
The Arduino controls these components according to the rain sensor reading.
Normal Weather
When rain is not detected:
- Green LED turns ON.
- Red LED turns OFF.
- Buzzer turns OFF.
Rain Detected
When rain is detected:
- Green LED turns OFF.
- Red LED turns ON.
- Buzzer turns ON.
— Programming the Arduino Nano 33 IoT
Programming the Arduino Nano 33 IoT
The Arduino program controls the sensors, servo motors, LEDs, buzzer and wireless communication.
I used the following libraries:
- WiFiNINA – Connects the Arduino to Wi-Fi.
- PubSubClient – Provides MQTT communication.
- Servo – Controls the two servo motors.
- DHT – Reads temperature and humidity from the DHT11 sensor.
Main Program Functions
The program is divided into several functions to make it easier to understand and maintain.
1. connectWiFi()
This function connects the Arduino Nano 33 IoT to the selected Wi-Fi network. It checks the connection status and attempts to reconnect if the connection is lost.
2. connectMQTT()
This function connects the Arduino to the MQTT broker running on the Raspberry Pi. It uses the MQTT server address, port and authentication settings.
3. readSensors()
This function reads the rain sensor and soil moisture sensor. It also reads temperature and humidity from the DHT11 sensor at regular intervals.
4. controlSystem()
This function controls both servo motors, the LEDs and the buzzer.
When rain is detected, the first servo moves to 90 degrees and the second servo moves to 0 degrees. The red LED and buzzer are switched on.
When the weather is dry, the first servo returns to 0 degrees and the second servo returns to 180 degrees. The green LED is switched on.
5. publishMQTTData()
This function prepares the sensor readings and device conditions in JSON format. It then publishes the information to the MQTT topic smartplant/data.
6. setup()
The setup function starts the Serial Monitor, configures the pins, attaches both servo motors, starts the DHT11 sensor and configures the MQTT server.
7. loop()
The loop function continuously checks the Wi-Fi and MQTT connections, reads the sensors, controls the output devices and publishes monitoring information approximately every two seconds.
The use of separate functions makes the program easier to organise, understand and troubleshoot.
— Setting Up MQTT Communication on Raspberry Pi 4
Setting Up MQTT Communication on Raspberry Pi 4
The Raspberry Pi 4 is used to receive environmental monitoring data from the Arduino Nano 33 IoT.
I used MQTT (Message Queuing Telemetry Transport), which is a lightweight messaging protocol commonly used in IoT projects.
The Raspberry Pi runs the Mosquitto MQTT broker. The Arduino connects to this broker over Wi-Fi and publishes information to the MQTT topic:
smartplant/data
The Arduino sends data in JSON format, including:
- Rain sensor reading
- Soil moisture reading
- Temperature
- Humidity
- Rain status
- Soil status
- First servo position status
- Second servo position status
- Buzzer status
- Red LED status
- Green LED status
— Creating the Python Monitoring Dashboard
Creating the Python Monitoring Dashboard
I created a Python dashboard on the Raspberry Pi 4 to display the environmental information received from the Arduino.
The dashboard uses Tkinter to create the graphical interface and Paho MQTT to receive messages from the MQTT broker.
The dashboard is designed to display information such as:
- Rain sensor value
- Soil moisture value
- Temperature
- Humidity
- Rain or dry condition
- Soil moisture status
- Servo motor status
- LED status
- Buzzer status
- MQTT connection status
— Testing the Complete System
Testing the Complete System
After connecting the components and preparing the software, the system can be tested in different conditions.
Test 1: Normal Weather
When the rain sensor does not detect rain:
- The green LED should turn ON.
- The red LED should turn OFF.
- The buzzer should remain OFF.
- The first servo should move to 0 degrees.
- The second servo should move to 180 degrees.
Test 2: Rain Detection
When the rain sensor reading falls below the rain threshold:
- The red LED should turn ON.
- The green LED should turn OFF.
- The buzzer should turn ON.
- The first servo should move to 90 degrees.
- The second servo should move to 0 degrees.
The mechanical arrangement should then move the clothes-hanging pipe inwards and rotate the bottom protective wall upwards.
Test 3: Environmental Monitoring
The soil moisture sensor and DHT11 sensor should provide readings to the Arduino. The readings should also be included in the MQTT messages.
Test 4: Wireless Communication
The Arduino should connect to Wi-Fi and the MQTT broker. The Raspberry Pi dashboard should receive and display the published sensor information.
The results should be checked using the Arduino Serial Monitor and the Python dashboard. Any connection or sensor problems should be corrected before considering the system fully operational.
— Results and Conclusion
Results and Conclusion
The project demonstrates how an IoT-based system can be used to protect clothes from rainfall automatically.
The rain sensor provides the input for detecting rainfall. Based on its reading, the Arduino Nano 33 IoT controls two servo motors to move the clothes-hanging pipe inwards and rotate the bottom protective wall upwards.
The LEDs and buzzer provide alerts about the weather condition. The soil moisture sensor and DHT11 sensor collect additional environmental information.
MQTT communication allows the Arduino to send the collected information to the Raspberry Pi 4. A Python dashboard provides a convenient way to monitor the readings and device conditions.
This project helped me understand how sensors, actuators, microcontrollers, wireless communication and software dashboards can work together in an IoT application.
It also provided practical experience in Arduino programming, MQTT communication, Python development and integrating hardware with software.