← All machines

Raccoon Soaker

Building

A camera and a PIR guard the steps onto my deck, and an ESP32-CAM opens a 12 V water valve to soak whatever comes up them.

Raccoon Soaker

What it is

A camera that guards the steps onto my deck. An ESP32-CAM watches the steps, and when an animal comes up them, it opens a 12 V water valve for two seconds and soaks it. It's built for raccoons, which come at night, so a small PIR sensor watches for body heat as well.

How it decides to spray

The camera takes 320 × 240 black-and-white frames and cuts each one into 768 blocks of 10 × 10 pixels. It compares each block with a background it learns slowly. If 2% of the blocks change for three frames in a row, that's an animal.

  • If 40% of the picture changes at once, it's the light, not an animal (a cloud, the porch light), so it re-learns the background instead.
  • It ignores its own splash: 3 seconds after a spray, then a 20-second cooldown.
  • Hard limits: the valve never stays open more than 10 seconds, and it stops after 12 automatic sprays in an hour, so a branch in the wind can't empty the hose overnight.

The camera can't see in the dark, so the Spray when setting decides who gets a say:

Setting Sprays when
camera the camera sees enough movement
both the camera sees movement and the PIR felt something in the last 3 s
either the camera or the PIR alone
auto both in daylight, the PIR alone after dark (the camera measures the light itself)

The app

The app is a single web page the ESP32-CAM serves itself. On my iPhone it's added to the home screen and opens full screen. It shows the live camera with the motion blocks over it, the state (ARMED, COOLDOWN, SPRAYING), the PIR, the catches and a snapshot every 30 seconds, with Spray now, Arm / Disarm and the settings. The same page runs inside Bench, against the real board or against Bench's Preview, where a made-up 8-bit raccoon walks past the camera.

Firmware updates go over Wi-Fi: the board only needed USB once.

The circuit

A 5 V relay is the wall between the two sides. The ESP32-CAM drives only the relay's input (GPIO 13, about 2 mA), and the relay's contacts switch the 12 V to the valve, which never touches the camera's side. A 1N4007 diode across the valve's coil catches the spike when it switches off. A buck converter makes the camera's 5 V from the same 12 V.

The enclosure

The box is version 4, printed without supports. Everything inside sits on a sled: the relay, the buck converter and the camera in its carrier. It's built at the bench and slides in from the back like a drawer, held by two screws at the opening. The cables come up through glands into a basement under the sled. The valve hangs under the box on its own bosses, with a printed 60° fan nozzle on its outlet, and a rain hood keeps the top dry.

Where it's at

Built, wired and on its yoke: the camera, the PIR, the relay and the valve all work in the real box, and the box tilts in the yoke on two ears, which pans on a round base. Next are water through the valve, the dusk light reading, and a night on the deck.

Raccoon Soaker photo 1
Raccoon Soaker photo 2
Raccoon Soaker photo 3
Raccoon Soaker photo 4
Raccoon Soaker photo 5
Raccoon Soaker photo 6
Raccoon Soaker photo 7
Raccoon Soaker photo 8
Raccoon Soaker photo 9
Raccoon Soaker photo 10

Build log