Control PIR Sensor with Arduino: Discover how to control a Passive Infrared (PIR) sensor with an Arduino and monitor motion detection using Bluetooth. The Bluebot Controller app makes it easy to view real-time motion data on your smartphone. In this tutorial, you will learn how to build a motion-sensing system that combines Arduino, a Bluetooth module, and the PIR sensor.
Components You Need
Here’s a quick list of components required for this project:
- Arduino Board (e.g., Arduino Uno)
- HC-05 Bluetooth Module
- PIR Motion Sensor
- LED (optional for motion status indication)
- Jumper Wires
- Bluebot Controller App (available for Android/iOS)
How the System Works
The PIR sensor detects motion by sensing changes in infrared radiation. When motion occurs, the Arduino reads the sensor output and transmits data to your smartphone via the Bluetooth module. The Bluebot Controller app displays the status, letting you monitor motion in real-time.
Setting Up the Circuit
- Connect the HC-05 Bluetooth Module:
- Attach the TX pin of HC-05 to pin 2 on the Arduino.
- Connect the RX pin of HC-05 to pin 3 on the Arduino.
- Wire the PIR Sensor:
- Connect the VCC pin of the PIR sensor to the 5V pin on the Arduino.
- Attach the GND pin to the Arduino’s ground.
- Connect the output pin of the PIR sensor to pin 4 on the Arduino.
- Optional LED Setup:
- Connect an LED to pin 13 on the Arduino to indicate motion detection.
Code for Motion Detection and Bluetooth Communication
This code reads data from the PIR sensor, sends motion status to the Bluebot Controller app, and lights up an LED when it detects motion.
#include <SoftwareSerial.h>
// Bluetooth module connections
const int bluetoothTx = 2; // HC-05 TXD to Arduino RX
const int bluetoothRx = 3; // HC-05 RXD to Arduino TX
// PIR sensor pin
const int pirSensorPin = 4; // PIR sensor output pin
// Bluetooth setup
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
Serial.begin(9600); // Start Serial Monitor
bluetooth.begin(9600); // Initialize Bluetooth communication
pinMode(pirSensorPin, INPUT);// Set PIR sensor pin as input
pinMode(LED_BUILTIN, OUTPUT);// Set built-in LED as output
}
void loop() {
int pirStatus = digitalRead(pirSensorPin); // Read PIR sensor value
String motionStatus = "No Motion Detected";
int fillPercentage = 0;
if (pirStatus == LOW) {
motionStatus = "Motion Detected";
fillPercentage = 100; // Full percentage if motion is detected
digitalWrite(LED_BUILTIN, HIGH); // Turn on LED
} else {
digitalWrite(LED_BUILTIN, LOW); // Turn off LED
}
String data = motionStatus + ";" + String(fillPercentage);
bluetooth.println(data); // Send data via Bluetooth
Serial.println(data); // Print data on Serial Monitor
delay(500); // Delay for stability
}
How Data is Sent to the App and Why
The Arduino sends motion data as a string formatted like this:"Motion Detected;100"
or "No Motion Detected;0"
.
- Format Explanation:
The string includes two parts separated by a semicolon (;
):- Motion Status: Indicates if motion is detected (“Motion Detected”) or not (“No Motion Detected”).
- Fill Percentage: Represents a numerical value for easy app integration. In this project, it’s 100% when motion is detected and 0% otherwise.
- Why This Format?
- App Parsing: The semicolon separator makes it simple for the Bluebot Controller app to split the data into meaningful parts. The app can display the motion status as text and use the fill percentage for graphs, sliders, or further analysis.
- Flexibility: The same format can be extended to include more parameters (e.g., sensor temperature, distance) in future upgrades.
- Ease of Debugging: The combined string is human-readable and easy to debug via the Serial Monitor.
The Bluetooth module transmits this formatted data string to the Bluebot Controller app, which decodes and displays it on the smartphone screen. This approach ensures smooth communication and an intuitive app experience.
How to Use the Bluebot Controller App
- Install the App: Download the Bluebot Controller app from the Play Store or App Store.
- Pair with Bluetooth: Connect your phone to the HC-05 module through the app.
- View Motion Data: Monitor the status updates, including “Motion Detected” and “No Motion Detected,” on your phone.
Applications of This Project
- Home Security: Monitor movement inside your home and trigger alarms or alerts.
- Automation Projects: Control smart devices like lights or fans when motion is detected.
- Interactive Devices: Create motion-triggered systems for robotics or other automated gadgets.
Conclusion
This project demonstrates how to integrate an Arduino with a PIR motion sensor and Bluetooth to create a responsive motion detection system. The Bluebot Controller app simplifies real-time monitoring on your smartphone. The data format ensures seamless app integration and debugging.
Start building today and explore the endless possibilities of motion detection with Arduino!