Farm Security with Raspberry Pi, PIR Sensor and Odoo

Protecting farms against unauthorized access at night can be done efficiently with a simple hardware setup and direct Odoo integration. By combining a Raspberry Pi Zero, a PIR motion sensor, and a Pi Camera, movements are detected, photos are taken automatically, and alerts are logged in Odoo with a timestamp.

Required Hardware

  • Raspberry Pi Zero
  • Pi Camera (CSI port)
  • PIR motion sensor
  • Wi-Fi or Ethernet connection to Odoo

How It Works

The PIR sensor monitors for movement. As soon as activity is detected, the Pi Camera captures an image and saves it with a timestamp. The image file is then uploaded to Odoo via its API, where it is stored and documented as a security event.

Example Python Script

import RPi.GPIO as GPIO
import time
import requests
from picamera import PiCamera

PIR_PIN = 4
camera = PiCamera()

GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR_PIN, GPIO.IN)

ODOO_UPLOAD_URL = 'http://your-odoo.com/api/upload_alert'
HEADERS = {'Authorization': 'Bearer your_token'}

def upload_image(file_path):
    with open(file_path, 'rb') as f:
        files = {'image': f}
        requests.post(ODOO_UPLOAD_URL, files=files, headers=HEADERS)

try:
    while True:
        if GPIO.input(PIR_PIN):
            filename = f"/home/pi/motion_{int(time.time())}.jpg"
            camera.capture(filename)
            upload_image(filename)
            print("Motion detected – image captured and sent.")
            time.sleep(10)
        time.sleep(0.5)

except KeyboardInterrupt:
    GPIO.cleanup()

Wiring PIR Sensor and Camera to Raspberry Pi

  • PIR VCC → Pin 2 (5V)
  • PIR GND → Pin 6 (Ground)
  • PIR OUT → GPIO4 (Pin 7)
  • Pi Camera → CSI Port

Benefits and Recommendations

This setup provides a simple yet effective security solution for barns or farm entrances. By linking image captures directly to Odoo, farmers gain full documentation of nighttime activity and can react faster to unusual events. Adding multiple sensors at different entry points further increases coverage.

Conclusion

Automating farm surveillance with Raspberry Pi and Odoo creates an affordable monitoring solution. It reduces security risks, improves record-keeping, and strengthens farm management through real-time alerts.