This is a simple project that combines Arduino and Python to control your computer using an ultrasonic motion sensor. When the sensor detects motion within a certain range, it triggers a Python script to switch between tabs using keyboard shortcuts like Alt + Tab
or Ctrl + Tab
.
motion-controlled-tab-switcher/
├── arduino_code/
│ └── arduino_code.ino
├── python_ultrasonicsensor/
│ ├── arduino_alt_tab.py
│ └── arduino_ctrl_tab.py
└── README.md
- The Arduino uses an HC-SR04 ultrasonic sensor to detect motion within a 1–100 cm range.
- When motion is detected, it sends the message
"Motion detected!"
to the serial port. - A Python script running on your computer listens to this serial message.
- Once the message is received, the Python script simulates a keyboard shortcut to switch between tabs.
arduino_alt_tab.py
→ triggersAlt + Tab
(switch apps)arduino_ctrl_tab.py
→ triggersCtrl + Tab
(switch browser tabs)
- Arduino board (Uno/Nano/etc.)
- HC-SR04 ultrasonic sensor
- Jumper wires
- Python 3.x
pyautogui
library (pip install pyautogui
)pyserial
library (pip install pyserial
)
- Connect your HC-SR04 sensor to the Arduino:
- Trig → Pin 12
- Echo → Pin 11
- Upload the
arduino_code.ino
file to your Arduino board.
- Make sure the COM port (
COM4
in the scripts) matches the port of your connected Arduino. - Open your terminal and run one of the Python scripts:
python python_ultrasonicsensor/arduino_alt_tab.py
# or
python python_ultrasonicsensor/arduino_ctrl_tab.py
Mohamed Soliman
Created as a fun mini project to explore Arduino and Python interaction.