Auto-minimize your PC screen the second someone walks in?

Hell yeah, bro! All you need is an Arduino, an IR sensor, and a tiny bit of Python magic.



This is a super simple project, perfect to build just for fun. The core idea is: whenever the IR sensor connected to your Arduino detects something, the Arduino will shoot a message over to your computer. As soon as the PC gets that signal, boom! Everything open on your screen gets minimized.  

Since I'm a Windows user, the quick shortcut to hide everything is the Win + Comma keys. Hold them down together, and all your open windows vanish, leaving just your bare desktop in plain sight.

But wait, does this project even make any sense? Well, picture this: you're 45 years old, happily watching Tom and Jerry, or maybe you're playing Call of Duty while hiding from your wife. Suddenly, she catches you red-handed and gives you the scolding of a lifetime. Now tell me, doesn't this make perfect sense?

Here's a list of the components we'll be using for this project, along with their links.

You can grab the stuff used in this project from right here: 

  1. IR Sensor
  2. Arduino UNO
  3. Arduino Mega



The Arduino code isn't rocket science at all. We just need to write a simple script so that when the sensor detects an obstacle, it sends a quick message to the PC. 



Once you're done coding the Arduino, check the Arduino IDE to see which COM or Serial Port your board is using to communicate. You can easily find this in the Ports menu of the Arduino IDE. We'll need this COM Port (along with the baud rate) for our Python script in just a bit.

Now, before we jump into the Python part, we need to close the Arduino IDE. Honestly, the IDE being open isn't a huge deal, BUT if the Serial Monitor is open, Python won't be able to talk to the Arduino. So, definitely close the Serial Monitor to avoid any communication hiccups. Two apps just can't use the same serial port at the exact same time!

To run the Python script, you absolutely need Python installed on your system, along with a few extra Python modules. 


How do you know if you already have Python?

Go to your Start menu, search for 'powershell', and open Windows PowerShell. You'll feel a bit like a hacker once you see that Terminal or CLI (Command Line Interface).

Now type 'python' and smash Enter. 

If Python is installed, it will look something like this:



And if it’s not installed, hitting Enter will straight up open the Microsoft Store so you can download it. Just install it right from there! 



After installing, if you want to be 100% sure it's there, open PowerShell again, type 'python', hit enter, and double-check!

Now that we're sure Python is ready to roll, let's grab the necessary Python modules. Without these, our auto-minimize script won't work. Jump back into PowerShell. 

Then, run these commands one by one to install the modules:  

    pip install pynput

    pip install pyserial

    pip install pyautogui


Next up, open your favorite code editor! Whether it's VS Code, Notepad++, Sublime Text, or literally just regular Notepad if you don't have the others.

Copy one of the scripts from below, paste it in, and save it with a .py extension. You can name it whatever you want! After saving, you can just double-click the file or run it from the command line. 

This first script works fine, but if you minimize it and try to do other stuff, it won't run in the background. If you want a script that works silently in the background, just scroll down a bit more!


And here’s the script that runs perfectly in the background too.

Post a Comment

Previous Post Next Post