In the world of IoT and automation, motion detection is a fundamental concept used in security systems, smart homes, and more. In this project, we create a motion detection system using an RF transmitter and receiver. The transmitter detects motion using an IR sensor and sends the data wirelessly to the receiver. An Arduino connected to the receiver processes this data and communicates with a Python script via PySerial to control a computer screen or change tabs dynamically.
Project Overview
This system detects motion and triggers an action on a connected computer. The components work together as follows:
-
Transmitter Side:
- An IR sensor detects if someone crosses its path.
- The RF transmitter sends a signal (1 or 0) to the receiver.
-
Receiver Side:
- An RF receiver captures the signal and sends it to an Arduino.
- The Arduino communicates with a Python script via PySerial.
- Python interprets the signal to shift tabs or change the screen.
Components Required
- Arduino Board
- RF Transmitter and Receiver Module (433 MHz)
- IR Sensor (e.g., IR Proximity Sensor or IR LED and Photodiode Pair)
- Computer with Python Installed
- Jumper Wires
- Breadboard
Circuit Diagram
Transmitter Side:
- Connect the IR sensor’s VCC, GND, and output to the RF transmitter module.
- The RF transmitter is powered by 5V from the Arduino or an external source.
Receiver Side:
- The RF receiver’s data pin connects to a digital pin on the Arduino (e.g., Pin 2).
- The Arduino communicates with the computer via a USB cable.
Arduino Code
The Arduino listens for signals from the RF receiver and sends the data to the Python script.
const int receiverPin = 2; // RF receiver data pin
void setup() {
Serial.begin(9600);
pinMode(receiverPin, INPUT);
}
void loop() {
int motionDetected = digitalRead(receiverPin);
if (motionDetected == HIGH) {
Serial.println("1"); // Send 1 if motion is detected
} else {
Serial.println("0"); // Send 0 if no motion
}
delay(100); // Slight delay to prevent spamming
}
Python Script
The Python script uses PySerial to read data from the Arduino and control the screen or tabs accordingly.
import serial
import time
import pyautogui # For controlling the screen
# Configure serial communication
arduino = serial.Serial('COM3', 9600) # Replace 'COM3' with your Arduino's port
time.sleep(2) # Wait for Arduino to initialize
def change_tab():
pyautogui.hotkey('ctrl', 'tab') # Simulates a tab switch in browsers
while True:
if arduino.in_waiting > 0:
data = arduino.readline().decode('utf-8').strip()
print(f"Received: {data}")
if data == "1":
print("Motion detected! Changing tab...")
change_tab()
elif data == "0":
print("No motion detected.")
How It Works
-
Motion Detection:
The IR sensor detects motion when someone crosses its path and sends a HIGH signal to the RF transmitter. -
Wireless Communication:
The RF transmitter sends this signal wirelessly to the RF receiver. -
Arduino Processing:
The Arduino reads the signal from the receiver and transmits the corresponding data (1 or 0) to the connected computer via USB. -
Python Automation:
The Python script monitors the serial input. If it receives a1
, it triggers a screen action like switching tabs using thepyautogui
library. If it receives a0
, no action is taken.
Applications
- Home Automation: Automatically shift screens based on motion detection in different rooms.
- Security Systems: Alert systems when unauthorized motion is detected.
- Interactive Displays: Use motion detection for dynamic content switching on screens.
Videos
1. Working Video
2. Prototype Testing Video
Conclusion
This project showcases a simple yet effective way to integrate hardware and software for real-time motion detection and response. By combining RF communication, Arduino, and Python, we’ve created a system that can be scaled for various applications, from smart homes to interactive displays. Dive into this project and explore the endless possibilities of automation!
No comments:
Post a Comment