Shhh! Don’t move! It can’t see us if we don’t move.

Tyler/ September 9, 2024/ Uncategorized/ 0 comments

In my last post, I described a new circuit board to add IR motion detection to our kitchen to control some recessed lights. The IR motion sensors are compact little components, but they need to be mounted permanently. Over the past few days, I designed and fabricated a mount for the IR detector, and today I installed everything.

I do modeling work using OpenSCAD. I hated CAD work until I finally discovered this wonderful piece of software. While other applications feel very manual and tedious, OpenSCAD is script based. You describe your model using functions and operations.

The first step was to measure the PSIR board and create a model of it.

PSIR Motion sensor component

This is easy. Two cylinders and two rectangular prisms is all it takes to get close enough.

PSIR_BELL_DIAMETER = 9.5; //mm
PSIR_BELL_HEIGHT = 10.5; //mm

PSIR_BOARD_DIAMETER = 16.0; //mm
PSIR_BOARD_HEIGHT = 1.5; //mm

PSIR_PIN_HEIGHT = 8.0; //mm
PSIR_PIN_WIDTH = 0.5; //mm
PSIR_PIN_TOPHEIGHT = 1.0; //mm
PSIR_PIN_X_TRANSLATION = PSIR_BOARD_DIAMETER/2-2; //mm - pin is 2 mm from board edge
PSIR_PIN_Y_SPACING = 2.5; //mm
//Center of model is the center of the top of the PSIR.

module PSIR_Board()
{
    color( "white", 1.0 )
    {
        translate([0,0,-PSIR_BOARD_HEIGHT/2]){
            cylinder(h=PSIR_BELL_HEIGHT+PSIR_BOARD_HEIGHT/2, d=PSIR_BELL_DIAMETER, center=false);
        }
    }

    color( "black" , 1.0)
    {
        translate([0,0,-PSIR_BOARD_HEIGHT])
        {
            cylinder(h=PSIR_BOARD_HEIGHT, d=PSIR_BOARD_DIAMETER, center=false);
        }
    }

    color( "silver", 1.0)
    {
        //Step size is the pin width so that the entire region is filled for subtraction operation later
        for(y_offset=[-PSIR_PIN_Y_SPACING : PSIR_PIN_WIDTH : PSIR_PIN_Y_SPACING])
        {
            translate([PSIR_PIN_X_TRANSLATION,y_offset,0])
            {
                //top part of pin, accounting for solder
                scale([1.5, 1.5, 1.0])
                {
                    cube([PSIR_PIN_WIDTH,PSIR_PIN_WIDTH,PSIR_PIN_TOPHEIGHT],center=false);
                }
                
                //bottom part of pin
                translate([0,0,-(PSIR_PIN_HEIGHT+PSIR_BOARD_HEIGHT)])
                {
                    cube([PSIR_PIN_WIDTH,PSIR_PIN_WIDTH,PSIR_PIN_HEIGHT],center=false);
                }
            }
        }
    }
}
Approximation for the PSIR Motion sensor component

Using the model of the PSIR motion sensor made it easy to design a mount to fit it. The design steps are:

  • Create a tapered cylinder.
  • Rotate the cylinder to the desired mount angle.
  • Create a 2D projection (a “shadow”) of the resultant cylinder in the xy-plane, scale it up a bit, and perform a linear extrude operation to create a mounting ring.
  • Cut away the far end of the mounting ring where it intersects with the tapered cylinder.
  • Add M5 screw holes to the mounting ring.
  • Cut out a cylinder through the center of the mount. This is where the motion sensor is inserted and its wires pass through.
The mount model containing the PSIR motion sensor
A view down the bore of the mount.
The motion sensor component needs to be able to slide straight down to its seat.

OpenSCAD is a great piece of software because the model is explicitly parameterized. This means that if you’ve designed it functionally, parameters can quickly be changed to modify the design. For example, I measured the correct angle to be 68° for this project, but I plan to print more of these, and I will want to change the mount angle for each one. With OpenSCAD, all I need to do is change the one variable.

Next, I put this model into Cura to create gcode for my 3D printer. At first, something seemed very wrong. The model was far too small, and Cura said it would only take 7 minutes to print!. It didn’t take long to realize that I’d used centimeters in OpenSCAD, but Cura expects millimeters! A quick modification to the units yielded results much closer to expectations. I’m glad I realized my mistake before attempting a print, but the kids probably would have loved a ⅒ scale model.

Sliced model

It’s basic and old, but my Monoprice Select Mini v1 is still chugging along (here’s a link to v2).

3D Printing the mount

Finally, I just had to modify the existing project box to include the new circuit board and the motion sensor mount. It is getting a bit tight in there, and some of the terminals are a bit undersized for the wire gauges in the box. My fingers are sore, but I managed to cram it all in.

It sees you!
A close up view of the angled mount

I powered it up, and the board (which I’d already flashed with a basic ESPHome configuration) immediately connected to Home Assistant. I updated the automations regarding whether the kitchen is occupied to trigger on the motion sensor, and it was done.

Just like that, the quality of this automation is markedly improved, but this is not a one-off! I intend to add motion-controlled recessed lighting in several other areas in our house. The one I’m most excited about installing next is dim recessed lighting that turns on at night when someone steps out of their bed to walk to the bathroom.

Share this Post

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*