This guide will help you create an IoT-based night patrolling robot using Raspberry Pi. The robot will patrol designated areas and provide real-time alerts to enhance women's safety. It will include features such as obstacle detection, live video streaming, and emergency alerts.
Components Required
- Raspberry Pi (Model 3 or later)
- Motor driver board (e.g., L298N for controlling motors)
- DC motors with wheels (for movement)
- Ultrasonic distance sensors (for obstacle detection)
- Camera module (e.g., Raspberry Pi Camera or USB webcam for video streaming)
- GPS module (for location tracking)
- Relay module (optional, for triggering alarms or lights)
- Connecting wires and breadboard
- Power supply (for Raspberry Pi and motors)
- Cloud service account (e.g., ThingSpeak, Blynk, or AWS IoT)
Setting Up the Hardware
Follow these steps to set up the hardware:
-
Assemble the Robot Frame
Attach the DC motors with wheels to the robot frame and connect them to the motor driver board. Ensure that the frame is sturdy and able to support all components.
-
Connect the Sensors and Camera
Attach the ultrasonic sensors to the front of the robot for obstacle detection. Connect the camera module to the Raspberry Pi for live video streaming. Attach the GPS module for location tracking.
-
Power the System
Ensure the Raspberry Pi, motors, and sensors are properly powered using appropriate power supplies. Verify that all connections are secure.
Programming the Raspberry Pi
Write the code to control the robot’s movement, handle obstacle detection, stream video, and send alerts. Below is a basic outline of the code using Python:
import RPi.GPIO as GPIO
import time
import picamera
import requests
# Configuration
MOTOR_LEFT_PIN1 = 17
MOTOR_LEFT_PIN2 = 18
MOTOR_RIGHT_PIN1 = 22
MOTOR_RIGHT_PIN2 = 23
TRIG_PIN = 24
ECHO_PIN = 25
CAMERA_RESOLUTION = (640, 480)
CLOUD_URL = "https://api.thingspeak.com/update?api_key=YOUR_API_KEY"
# Setup
GPIO.setmode(GPIO.BCM)
GPIO.setup([MOTOR_LEFT_PIN1, MOTOR_LEFT_PIN2, MOTOR_RIGHT_PIN1, MOTOR_RIGHT_PIN2], GPIO.OUT)
GPIO.setup(TRIG_PIN, GPIO.OUT)
GPIO.setup(ECHO_PIN, GPIO.IN)
camera = picamera.PiCamera()
camera.resolution = CAMERA_RESOLUTION
def measure_distance():
GPIO.output(TRIG_PIN, False)
time.sleep(2)
GPIO.output(TRIG_PIN, True)
time.sleep(0.00001)
GPIO.output(TRIG_PIN, False)
start_time = time.time()
stop_time = time.time()
while GPIO.input(ECHO_PIN) == 0:
start_time = time.time()
while GPIO.input(ECHO_PIN) == 1:
stop_time = time.time()
time_elapsed = stop_time - start_time
distance = (time_elapsed * 34300) / 2
return distance
def move_forward():
GPIO.output(MOTOR_LEFT_PIN1, GPIO.HIGH)
GPIO.output(MOTOR_LEFT_PIN2, GPIO.LOW)
GPIO.output(MOTOR_RIGHT_PIN1, GPIO.HIGH)
GPIO.output(MOTOR_RIGHT_PIN2, GPIO.LOW)
def stop_moving():
GPIO.output(MOTOR_LEFT_PIN1, GPIO.LOW)
GPIO.output(MOTOR_LEFT_PIN2, GPIO.LOW)
GPIO.output(MOTOR_RIGHT_PIN1, GPIO.LOW)
GPIO.output(MOTOR_RIGHT_PIN2, GPIO.LOW)
def send_alert():
response = requests.get(CLOUD_URL + "&field1=1")
print(f"Alert sent to cloud: {response.status_code}")
try:
while True:
distance = measure_distance()
print(f"Distance to obstacle: {distance} cm")
if distance < 20: # Example threshold for obstacle detection
stop_moving()
send_alert()
else:
move_forward()
time.sleep(1) # Adjust as necessary for your application
except KeyboardInterrupt:
GPIO.cleanup()
This code controls the robot’s movement and obstacle detection. It also includes basic functionality for sending alerts and streaming video.
Setting Up Cloud Integration
To monitor and control the robot remotely, integrate the system with a cloud service. Configure the cloud service to receive data from the Raspberry Pi and set up dashboards or alerts based on the data received from the robot.
Testing and Calibration
Test the robot’s movement, obstacle detection, and video streaming capabilities. Ensure that the alerts are correctly sent to the cloud and adjust the sensor sensitivity and code parameters as needed for reliable performance.
Conclusion
The IoT-based night patrolling robot provides a proactive solution for enhancing women’s safety. By integrating sensors and Raspberry Pi with cloud services, you can create a smart patrolling system that offers real-time monitoring and alerts, improving safety and security.