Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

SmartThings Motion Sensor Using Computer Vision on Raspberry Pi 3

Deploy a computer‑vision‑enabled motion sensor on a Raspberry Pi 3 equipped with a PiCamera. The device detects human faces and transmits presence information via UPnP over the local network to SmartThings.

I will start by assuming that you have a Raspberry Pi 3 with a working camera and Open CV installed on it. If you don’t, I recommend this tutorial 🙂

Creating a Custom SmartThings Device Handler

In the SmartThings IDE, create a new device handler for our computer‑vision motion sensor.

Go to the “My Device Handler” section and click “+ Create New Device Handler” in the top right corner.

In this case we will create it from code. Click the second tab “From Code”, paste the attached Device Handler code and click “Create”.

On the next page click “Publish” to make the device available to you.

Writing the SmartThings App

Similarly, create a SmartApp. In the “My SmartApps” section click “+ Create New SmartApps” in the top right corner.

Create it from code, paste the attached SmartApp code, and click “Create”. Then publish it.

Getting the Raspberry Pi Ready

We now need a Python script that captures images, detects faces, and reports the status to SmartThings.

Install the required libraries:

pip install imutils
sudo apt-get install python3-twisted-web

Create a directory to hold the script:

mkdir -p /home/pi/camera
cd /home/pi/camera

Create the script file:

sudo nano ssdpcamera.py

Paste the attached Camera Python Script and save it.

Test the script with python3 ssdpcamera.py – you should see log output indicating camera initialization and face detection events.

Discovering and Pairing the Raspberry Pi

In the SmartThings mobile app, navigate to Marketplace → SmartApps, then locate “Computer Vision (Connect)” under “+ My Apps”.

Ensure the Raspberry Pi is powered on and the Python script is running. The SmartApp will initiate discovery; once the device appears, select it and tap “Done”.

After pairing, the device will start reporting presence updates to your SmartThings account.

Auto‑Start Configuration

To run the script automatically on boot, edit /etc/rc.local and add the following before the exit 0 line:

(sleep 10; python3 /home/pi/camera/ssdpcamera.py)&

The parentheses run the command in the background after a short delay.

Code Overview

Below is a concise excerpt of the key components in the Python script. Full source files are provided in the attachments.

#!/usr/bin/python3
import cv2
from picamera import PiCamera
from twisted.web import server, resource
# Camera initialization
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
# Face detector
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# SSDP and HTTP servers are set up to allow SmartThings discovery and status polling.

The script continuously captures frames, runs Haar‑cascade face detection, and notifies the SmartThings hub whenever a person is detected or the scene becomes empty.

Manufacturing process

  1. Build a DIY Infrared Motion Sensor for Raspberry Pi – Step‑by‑Step Guide
  2. Control an LED with a PIR Motion Sensor on Raspberry Pi
  3. Smart Motion-Activated Water Gun Built with Arduino Nano
  4. Visualizing 3D Motion with an IMU Sensor: A Practical Guide
  5. Complete Arduino & Intel Edison Starter Kit with Sensors, Webcam, and Essential Accessories
  6. Omron Introduces FH‑SMD Series 3D Vision Sensor for Robot Arms, Enhancing Part Recognition & Productivity
  7. Seven Proven Ways Computer Vision Drives Efficiency & Saves Costs
  8. Revolutionizing Industry 4.0: How Computer Vision Drives Smart Manufacturing
  9. Advanced TOMOPLEX Sensor Film for Real-Time Aerospace Monitoring
  10. Helical Gear Rack for Precise Linear Motion Systems