In today’s world, home automation is not just about convenience—it’s about safety and environmental control. Imagine a system that automatically closes your windows when it starts raining, detects dangerous smoke, or senses harmful gases entering your home. It also tells you the temperature if your room too. This blog post will guide you through building a smart window automation system using Arduino, DIY sensors, and actuators. This project is perfect for those looking to enhance their home’s safety and efficiency while learning about electronics and coding.

Understanding the Project
This Arduino-based project is designed to respond to various environmental triggers. The window closes automatically when it starts raining, if dangerous smoke is detected, or if harmful gases, such as carbon monoxide, are present. Once the environment is safe again, the system reopens the window, ensuring that your living space remains protected and well-ventilated. This project is an excellent way to dive into the world of DIY home automation and IoT (Internet of Things).
Components Needed for the Smart Window Automation Project

To build this smart window automation system, you will need the following components:
- Arduino Standalone board: The brain of the project, handling sensor inputs and controlling the actuators. This is made up of the ATmega328P IC and the rest of the integrated circuitry.
- Rain Sensor: Detects when rain is falling, triggering the window to close.
- Smoke Detector Sensor: Senses the presence of smoke inside the room, signaling the Arduino to close the window.
- Gas Sensor (MQ-2): Detects harmful gases like carbon monoxide, ensuring the window closes to prevent toxic air from entering.
- Actuators (DC Motor Slider from Old DVD Mechanism): Used to physically open and close the window. We used the tray mechanism from an OLD DVD or VCD to model this.
- Motor Driver Module: Controls the power to the actuators based on signals from the Arduino Standalone board.
- Power Supply: Provides power to the entire system.

The crystal oscillator, sometimes referred to as just a crystal, produces an electrical signal with a very precise frequency. The frequency in this instance is 16 MHz. It is not polarized in crystals. In Figure 3.12, the schematic symbol is displayed. The microcontroller’s operating speed is set by the crystal. For instance, the microcontroller circuit that we are going to assemble has a frequency of 16 MHz, which enables it to process 16 million instructions per second. That doesn’t mean, however, that it can perform a function or a line of drawing that quickly, as one line of code requires numerous processing instructions to decode.
The Schematic Diagram

Attached to this control unit is a crystal oscillator which is used for the clocking of the microcontroller. Two capacitors are connected side by side to the crystal. They are in series to create a network that creates a 180° phase inversion at resonance. The purpose of the capacitors are basically to damp unwanted oscillation modes. The crystal will transfer any harmonic of its resonant frequency to a greater or lesser degree. The crystal oscillator together with the two capacitors connected side by side of the crystal are connected to pin 9 and pin 10 of the Atmega328p-pu microcontroller.
Read How To Design An Arduino Based Automatic Gate Controller

Step-by-Step Guide Explanation Of the Schematic Diagram
- Setting Up the Sensors:
- We connected the rain sensor to the Arduino to monitor weather conditions. This sensor will detect moisture and send a signal to the Arduino when it starts raining.
- Attach the smoke detector sensor to the Arduino. This sensor will continuously monitor for smoke inside the room, triggering the window to close if smoke is detected.
- We connected the gas sensor (MQ-2) to the Arduino. This sensor will detect harmful gases like carbon monoxide and methane, sending a signal to close the window if dangerous levels are detected.
- Also, we connected the temperature sensor, DS18B20 and ensure that the 4.7k Ohms resistor is connected as shown in the circuit diagram.
- Setting Up the Actuators:
- We connected the L293D motor driver as shown in the circuit diagram above. The power diodes are very necessary to to ensure the forward and background movement of the DC is assured.
- The LCD screen is connected using the 4-bit communication method. This means the 4-data wires are connected as shown in the schematic diagram.
- Power Supply:
- The power supply for this project is a liner power supply system, you are free to use a more intelligent power supply that works on Switch Mode PWM principle or just build yours from scratch.
Programming the Arduino Standalone
/*
/* PROGRAM TO USE RAIN SENSOR, SMOKE SENSOR AND TEMP SENSOR
* TO SENSE THE ENVIROMENT OF A SMART SYSTEM AND CLOSE AND OPEN
* A WINDOW
*/
#include <LiquidCrystal.h>
//include the oneWire lib
#include <OneWire.h>
//include the Dallas temp lib
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS A1
int windowForward = 10;
int windowBackward = 13;
int switch1 = 6;
int switch2 = 7;
//State the toxidity level
int toxicLevel = 350;
// analog pin 0 = sensor i/p
int rainSensePin= A0;
// current counter - goes up by 1 every second while sensing
int curCounter= 0;
//declear the i/p for smoke detection
int smokeSense = A2;
// Setup a oneWire instance to communicate with any OneWire devices connected
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// initialize the library by associating any needed LCD interface pin
//state which pin of the LCD is connected
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
Serial.begin(9600);
sensors.begin();
pinMode(windowForward, OUTPUT);
pinMode(windowBackward, OUTPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
lcd.begin(16, 2);
// Display a welcome message
lcd.setCursor(0, 0);
lcd.print("AUTOMATIC WINDOW");
delay(500);
lcd.setCursor(0, 1);
lcd.print(" CONTROL SYSTEM: ");
delay(2000);
lcd.setCursor(0, 0);
lcd.print("1> RAIN-SENSING,");
delay(1500);
lcd.setCursor(0, 1);
lcd.print("2> TEMP-SENSING,");
delay(1000);
lcd.setCursor(0, 0);
lcd.print("2> TEMP-SENSING,");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("3> SMOKE-SENSING");
delay(2000);
lcd.setCursor(0, 0);
lcd.print(" DESIGNED BY: ");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("OMOLOLA ADEMOLA");
delay(2000);
}
void loop(){
sensors.requestTemperatures();
Serial.print(" Temperature is: ");
Serial.print(sensors.getTempCByIndex(0));
Serial.println("'C");
float roomTemp = sensors.getTempCByIndex(0);
lcd.setCursor(0, 0);
lcd.print("ROOM TEMP:");
lcd.setCursor(9, 0);
lcd.print(roomTemp);
lcd.setCursor(14, 0);
lcd.print("'C");
int rainSenseReading = analogRead(rainSensePin);
Serial.print("NOw rain ");
Serial.println(rainSenseReading);
//begin reading from smoke sensor
int readSmoke = analogRead(smokeSense);
Serial.print(" Now Smokereading: ");
Serial.println(readSmoke);
delay(500);
int sense1 = digitalRead(switch1);
int sense2 = digitalRead(switch2);
if( sense2 == LOW) {
if ((rainSenseReading < 350) || (readSmoke >= 280)){
digitalWrite(windowForward, HIGH);
digitalWrite(windowBackward, LOW);
delay(300);
lcd.setCursor(0, 1);
lcd.print("WINDOW ");
lcd.setCursor(7, 1);
lcd.print("OPENED ");
}
}
else if( sense2 == HIGH){
if ((rainSenseReading < 350) || (readSmoke >= 280)){
digitalWrite(windowForward, LOW);
digitalWrite(windowBackward, LOW);
delay(300);
}
}
if( sense1 == LOW) {
if((roomTemp > 40.00) && (rainSenseReading > 350) && (readSmoke <= 280) )
{
digitalWrite(windowForward, LOW);
digitalWrite(windowBackward, HIGH);
delay(300);
lcd.setCursor(0, 1);
lcd.print("WINDOW ");
lcd.setCursor(8, 1);
lcd.print("CLOSED ");
}
}
else if( sense1 == HIGH)
{
if((roomTemp > 40.00) && (rainSenseReading > 350) && (readSmoke <= 280))
digitalWrite(windowForward, LOW);
digitalWrite(windowBackward, LOW);
delay(300);
}
}
Read Also Android Platform Based Temperature Monitoring Design for Poultry Farms
Explanation of Arduino Source Code
The Temperature Sensor Code
The oneWire library (from the Maxim Company) was removed from the source code at lines 1 and 2 so that the IDE could understand the remaining syntax. The DS18B20 can determine the temperature in Celsius and Fahrenheit scales, respectively, thanks to the special library called Dallas Temperature, which is located at line 3. This is accomplished with a unique built-in algorithm.

Any other IC linked to the Bus or wire could potentially be accessed by the application thanks to line 10. not limited to Onewire ICs only. Line 13 instructs the DallasTemp lib to use its built-in algorithm to return the temperature findings by reading off signals from which ICs. The temperature sensor in this instance was identified as oneWire.
The function setup initiated the sensor at line 18 at line 15. In order to get a real-time temperature measurement, the temperature must be continually sensed. This is done by repeating the codes based on the delay, or pause time, every 30 code lines, where the temperature in degrees Celsius is printed in the function loop.
Testing and Results
When the code was uploaded to the Arduino standalone boards, the project design worked as intended. The rain sensor was able to tell us when there was rain falling on the roof model of the house and from this, we could automatically close the window of the model home to ensure the rain doesn’t get inside. Also, when there was smoke detected, the window also closes.
Lastly, on very cold temperature days, the windows could respond automatically to closing itself. We can see the temperature of the room displayed on the LCD screen too. This helped us to further calibrate the temperature at which we could consider as the minimum allowable temperature at which we can place the shutting off of the smart automatic window.
Applications and Benefits
This smart window automation system has several practical applications:
- Home Safety: Protects your home from the dangers of smoke and harmful gases by automatically closing the windows when such threats are detected.
- Energy Efficiency: Helps maintain indoor temperature by closing windows during rain, reducing the need for heating or cooling.
- Convenience: Automates window control, reducing the need for manual intervention during weather changes or emergencies.
Conclusion
Building a smart window automation system with Arduino is a rewarding project that combines electronics, coding, and practical application. By using rain, smoke, and gas sensors, you can create a system that not only enhances home safety but also contributes to a more comfortable and energy-efficient living space. Whether you are a beginner or an experienced DIY enthusiast, this project is a fantastic way to explore the possibilities of home automation and IoT.
FAQ on Smart Window Automation System
1. How does the Arduino-based smart window automation system work?
The Arduino-based smart window automation system operates by using sensors to detect environmental conditions such as rain, smoke, and harmful gases. When any of these conditions are detected, the Arduino sends a signal to actuators (such as servos or motors) to automatically close the window. Once the conditions are clear and safe, the system reopens the window. The Arduino continuously monitors the inputs from the sensors to ensure real-time response to environmental changes.
2. What types of sensors are needed for this smart window automation project?
This project requires a rain sensor to detect precipitation, a smoke detector sensor to sense dangerous smoke, and a gas sensor (like the MQ-2) to identify harmful gases such as carbon monoxide or methane. These sensors are connected to the Arduino, which processes their readings and controls the window’s movement through actuators.
3. Can this smart window system be integrated into an existing home automation system?
Yes, the Arduino-based smart window system can be integrated into an existing home automation setup. By adding wireless communication modules (such as Wi-Fi or Bluetooth), the system can be connected to a smart home hub or controlled remotely through a smartphone app. This integration allows for more advanced control and monitoring, making the system part of a broader home automation network.
4. Is this project suitable for beginners in electronics and coding?
This project is suitable for beginners who have basic knowledge of Arduino programming and electronic components. The components used are relatively straightforward, and there are plenty of resources available to help with wiring and coding. However, those new to Arduino may need some additional guidance or tutorials to complete the project successfully.
5. What are the main benefits of installing a smart window automation system in my home?
The main benefits of a smart window automation system include enhanced home safety, improved energy efficiency, and increased convenience. By automatically closing windows during rain or when harmful gases are detected, the system helps protect your home from potential damage and health hazards. Additionally, it helps maintain indoor temperature by preventing rain or cold air from entering, thus saving on heating or cooling costs. The automation also eliminates the need for manual window control, making your home smarter and more responsive to environmental changes.