I turned an old Android phone into a security camera

I had a Pixel 3a in a drawer with a cracked screen corner. The camera still worked fine — better, honestly, than most of the €40–80 Wi-Fi cameras you see recommended online. Instead of letting it collect more dust, I decided to see how far I could get without buying anything new.

Starting point: IP Webcam

The easiest entry point is an Android app called IP Webcam. Install it, tap “Start server,” and your phone starts broadcasting a local HTTP server. The endpoints that matter:

  • /video — an MJPEG stream you can open directly in VLC or a browser
  • /shot.jpg — a single JPEG snapshot on demand
  • /settings — JSON config you can manipulate remotely

The stream is accessible from anything on the same network. VLC handles it with Network > Open URL > http://192.168.x.x:8080/video. Home Assistant supports it natively as a generic camera. At this point you have a functional camera for zero cost.

But I wanted motion detection without depending on any cloud service.

Adding motion detection

For motion detection I wrote a small Python script that polls the /shot.jpg endpoint and compares consecutive frames. OpenCV makes this straightforward:

import cv2
import urllib.request
import numpy as np
from datetime import datetime

CAMERA_URL = "http://192.168.1.50:8080/shot.jpg"
THRESHOLD = 5000  # minimum contour area to count as motion

prev_gray = None

while True:
    with urllib.request.urlopen(CAMERA_URL, timeout=5) as resp:
        img = np.frombuffer(resp.read(), dtype=np.uint8)
    frame = cv2.imdecode(img, cv2.IMREAD_COLOR)
    gray = cv2.GaussianBlur(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), (21, 21), 0)

    if prev_gray is not None:
        diff = cv2.absdiff(prev_gray, gray)
        _, thresh = cv2.threshold(diff, 25, 255, cv2.THRESH_BINARY)
        contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

        if any(cv2.contourArea(c) > THRESHOLD for c in contours):
            ts = datetime.now().strftime("%Y%m%d_%H%M%S")
            cv2.imwrite(f"/var/clips/motion_{ts}.jpg", frame)
            notify(f"Motion at {ts}")  # your preferred notification method

    prev_gray = gray
    time.sleep(1)

This runs as a systemd service on a Raspberry Pi 3B that’s already on for other things. When motion is detected it saves a JPEG and fires a Telegram bot message, which works well because you already have the app on your phone.

Keeping the phone viable

A few things I ran into:

Battery: leave it plugged in permanently. Some Android builds (Pixels included) let you cap charging at 80% to reduce battery stress — check Settings > Battery. If yours doesn’t, there are apps for it, or you can live with a fully charged battery given the phone is essentially retired hardware.

Screen: set the display to stay on, brightness to minimum. Or turn it off entirely — the IP Webcam server keeps running with the screen off. You can do this with adb shell input keyevent 26 if you don’t want to touch it.

Heat and placement: a phone lying face-down on a shelf can get warm. I use a small 3D-printed wall bracket to keep it upright; a folded piece of cardboard works as a proxy. Keep it away from direct sunlight through a window.

Lens cleaning: a camera phone pointed at the same scene for months picks up a lot of dust. Worth wiping the lens every few weeks.

What I didn’t bother with

IP Webcam also exposes an RTSP stream, which you’d use if you wanted to pipe the camera into an NVR like Frigate or use it with more sophisticated motion detection (person detection, etc.). I didn’t need that — one frame per second from /shot.jpg is enough to know whether something moved when I wasn’t watching.

I also didn’t set up any remote access. The stream is purely local, accessible through a WireGuard tunnel if I need it from outside.

Result

Total cost: zero. The camera has better low-light performance than the purpose-built cameras I was comparing it to, and the footage stays on hardware I own. It’s been running for several months without issue.

If you’re putting together monitoring for a small workspace or office and don’t want to commit to a proprietary system, this kind of setup scales surprisingly well — a handful of old phones and a Pi running the detection scripts covers a lot of ground before you need dedicated hardware.


Dealing with something similar at your business? Feel free to reach out.