How to make a device on Arduino to automatically close windows on the computer when someone enters the room

7 August 2024 3 minutes Author: Cyber Witcher

Sometimes it is necessary to automatically close windows on a computer when someone enters a room to protect privacy or to avoid accidental disclosure of important information. In this article, we will create an Arduino-based device that will detect motion using a PIR sensor and automatically close open windows on the computer.

What will we need?

  1. Arduino (Uno, Nano or other compatible controller)

  2. PIR motion sensor (e.g. HC-SR501)

  3. Resistors and conductors for connections

  4. USB cable for connecting Arduino to a computer

  5. Computer with Arduino IDE and AutoHotkey installed

  6. AutoHotkey (to create a script to close windows)

  7. Software for communicating Arduino with a computer (for example, Serial Monitor or a special script in Python)

Step 1: Connect the PIR sensor to the Arduino

A PIR sensor is a small sensor that “sees” movement. Here’s how to connect it:

  • Connect VCC on the sensor to 5V on the Arduino (this is power).

  • Connect the GND on the sensor to the GND on the Arduino (this is ground).

  • Connect the OUT on the sensor to D2 on the Arduino (this is the pin we get the signal through).

Step 2: Write a program for Arduino

Now we will write a small program that will help the Arduino to “understand” when someone entered the room. https://pastebin.com/1Qe2EVvh

Step 3: Create an AutoHotkey script to close windows

AutoHotkey is a program that performs certain actions on a computer. We’ll write a script that closes the windows when the Arduino detects motion.

  1. Installing AutoHotkey:- Download and install AutoHotkey from the official site

  2. Creating a script: – Open a text editor (for example, Notepad) and create a new file with the extension .ahk.

  3. Paste the following code into the file: – https://pastebin.com/p5x1tYf9 (When a signal is detected, the program will press the WIN + D combination (you can replace it with the one you want, I recommend win + L to lock the device)

  4. Run the script: – Save the file and double click on it to run the script.

Step 4: Connect and test the device

  1. Connect the Arduino to the computer using a USB cable.

  2. Download the program to the Arduino via the Arduino IDE.

  3. Run the created AutoHotkey script.

  4. Now, when someone enters the room, the computer will automatically close the active windows.

Conclusion

In this article, we have created an Arduino-based device that detects movement in a room using a PIR sensor and sends a signal to a computer to automatically close windows. This approach can be used to protect sensitive information when you don’t want anyone to see what’s open on your screen. This project can be extended with additional functions, such as turning on an alarm or recording the time of motion detection.

Disclaimer. This article is created for informational purposes only. All advice and instructions are provided for educational purposes and we are not responsible for any possible consequences related to the implementation of this project. Always use safety precautions when working with electronic components.

Other related articles
Found an error?
If you find an error, take a screenshot and send it to the bot.