Nighttime Stall Monitoring with Raspberry Pi, PIR Sensor and Odoo
Monitoring barns at night helps improve security and animal safety. With a Raspberry Pi, a motion sensor, and a simple camera, movements can be detected automatically. Each event triggers a snapshot and sends a notification into Odoo for logging and review.
Required Hardware
- Raspberry Pi (Model 3B+ or 4)
- Camera (Raspberry Pi Camera or USB webcam such as Logitech C270)
- PIR motion sensor (HC-SR501 or similar)
- Wi-Fi connection to Odoo
How It Works
The PIR sensor detects motion from animals or people. The Raspberry Pi immediately captures an image with a timestamp. A Python script then forwards an alert to Odoo, attaching the image path or file. This creates a permanent record of the event and enables timely responses.
Example Python Script
import RPi.GPIO as GPIO
import time
from datetime import datetime
from picamera import PiCamera
import requests
PIR_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR_PIN, GPIO.IN)
camera = PiCamera()
camera.resolution = (1024, 768)
ODOO_URL = 'http://your-odoo-server.com/api/stall_alert'
AUTH_TOKEN = 'your_api_token_here'
def send_alert(image_path):
with open(image_path, 'rb') as img:
files = {'image': img}
headers = {'Authorization': f'Bearer {AUTH_TOKEN}'}
data = {'message': 'Motion detected in barn'}
response = requests.post(ODOO_URL, headers=headers, data=data, files=files)
print(f"Odoo: {response.status_code}")
try:
print("Motion sensor active...")
while True:
if GPIO.input(PIR_PIN):
print("Motion detected!")
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
image_path = f'/home/pi/stall_{timestamp}.jpg'
camera.capture(image_path)
print(f"Saved image: {image_path}")
send_alert(image_path)
time.sleep(10)
time.sleep(0.5)
except KeyboardInterrupt:
GPIO.cleanup()
Wiring PIR Sensor to Raspberry Pi
- VCC → Pin 2 (5V)
- GND → Pin 6 (Ground)
- OUT → GPIO17 (Pin 11)
Benefits and Recommendations
This setup provides quick detection of unusual activity during nighttime hours. By storing alerts and images in Odoo, farmers gain transparency and an audit trail for security or animal welfare checks. For larger barns, multiple sensors can be installed to improve coverage.
Conclusion
A simple PIR sensor and camera combined with Odoo create an effective solution for barn surveillance. It improves security, helps monitor livestock, and integrates seamlessly with farm management data.

