Skip to main content

In this tutorial, we’ll guide you through the process of setting up a Raspberry Pi with a High-Quality Camera Module and an M12 Mount to capture a 10-second video when triggered by a laser sensor connected to a GPIO pin. This project is perfect for applications like surveillance, motion detection, or capturing specific events.

Materials Needed:

  1. Raspberry Pi (any model with GPIO pins)
  2. High-Quality Camera Module with M12 Mount
  3. Laser sensor module
  4. Jumper wires
  5. MicroSD card with Raspbian OS
  6. Power supply for Raspberry Pi
  7. HDMI cable (for display setup)

Step 1: Set Up Your Raspberry Pi

  1. Install Raspbian OS: Download the latest version of Raspbian and install it on your microSD card. Insert the card into the Raspberry Pi.
  2. Connect Peripherals: Connect the Raspberry Pi to a monitor, keyboard, and mouse using HDMI and USB cables. Power up the Pi.
  3. Update and Upgrade: Open the terminal and run the following commands to ensure your system is up-to-date:
sudo apt update 
sudo apt upgrade

Step 2: Connect the High-Quality Camera Module

  1. Attach the Camera Module: Carefully connect the High-Quality Camera Module to the Raspberry Pi’s camera port. Ensure the ribbon cable is properly seated.
  2. Secure the M12 Mount: If your Camera Module has an M12 mount, securely attach it to the module, adjusting the focus if needed.

Step 3: Set Up the Laser Sensor

  1. Connect the Laser Sensor: Connect the laser sensor to one of the GPIO pins on the Raspberry Pi. Make sure to connect the power (VCC), ground (GND), and signal (OUT) wires appropriately.
  2. Install Required Libraries: Install the RPi.GPIO library by running: sudo pip3 install RPi.GPIO

Step 4: Write the Python Script

Create a Python script to capture a 10-second video when the laser sensor is triggered:

# Import necessary libraries
import RPi.GPIO as GPIO
import time
import picamera

# Set GPIO mode
GPIO.setmode(GPIO.BOARD)

# Define GPIO pin for the laser sensor
laser_pin = 11

# Set up laser sensor as input
GPIO.setup(laser_pin, GPIO.IN)

# Set up the camera
camera = picamera.PiCamera()

try:
    while True:
        # Wait for the laser sensor to be triggered
        GPIO.wait_for_edge(laser_pin, GPIO.RISING)

        # Capture a 10-second video
        timestamp = time.strftime("%Y%m%d_%H%M%S")
        video_path = f"/home/pi/videos/video_{timestamp}.h264"
        camera.start_recording(video_path)
        camera.wait_recording(10)
        camera.stop_recording()

except KeyboardInterrupt:
    pass

finally:
    # Clean up GPIO
    GPIO.cleanup()
    camera.close()

Step 5: Run the Script

Save the script with a .py extension (e.g., laser_video_capture.py). Run the script using:

python3 laser_video_capture.py

Step 6: Test the System

Point the laser at the sensor and observe the Raspberry Pi capturing a 10-second video when the laser triggers the sensor.

Conclusion:

Congratulations! You’ve successfully set up a Raspberry Pi with a High-Quality Camera Module to capture videos triggered by a laser sensor. This project opens the door to various applications, including security systems, automated recording, and more. Feel free to customize the script to suit your specific needs or integrate additional features as desired.

Leave a Reply