After getting a couple basic projects under our belts, it was time for my boys and I to stretch our maker legs a bit. We decided to build a system to monitor and control the overhead doors in our 2-car garage. Since we're aspiring to be uber geeks, we've gone with a HAL 9000 theme.
And thus, the pod bay controller concept was born!
Design OverviewWe wanted to be able to monitor and control our pod bay doors via a variety of channels. The existing, standard wall buttons needed to continue functioning, as do the remotes in our vehicles. We'd also like to use web pages, smart phones, tablets, etc. to monitor status and control the doors. And Alexa! No HAL 9000 rip-off would be complete without today's version of voice interaction.
Architecture:
Main Control Unit - central processing, WiFi connection, relay switching for door control
Sensor Nodes (x2) - monitors door status (open, closed, occupied) and reports to main control unit.
Main Control Unit
Having fallen in love with Particle Photons, this little gem will be the heart of our controller. We mounted our Photon to a custom PCB, nestled it in a project enclosure and perched it on top of one of the garage door openers.
The main control unit will also house a dual relay board. This will be used to communicate with the 2 garage door openers. The relays will function the way the wall switches do: cause a momentary (~1 second) closed-loop which signals the opener to do something. The garage door openers will continue to control how they respond to such signals (open if closed, close if opened, stop if moving, etc.)
The custom PCB will connect to the relay board via a 4-wire jumper cable. This cable will be constructed using Dupont connectors and housings. The custom PCB will also have 2 RJ45 jacks mounted. This will facilitate easy connection to the 2 sensor nodes. The PCB will further have a 2-wire header mounted to it which will allow easy connection to the DC power jack. The PCB is designed to then route the 5v DC power to the Photon, the 4-wire header that connects to the relays, and the 2 RJ45 jacks that connect to the sensor nodes. The PCB will also route signals from the Photon to the relay header.
Sensor Nodes
A pair of HC-SR04 proximity sensors will be HAL's, er, the Photon's eyes. One will be mounted on the ceiling above each door, pointing down toward the floor. When a door is open, it will be in the sensor's line-of-sight. The sensor should report a distance of approximately 25". When a door is closed and there's a car occupying the pod bay, the sensor will report a distance of about 48". When the door is closed and the pod bay is empty, the sensor will report a proximity of 10'. Each sensor is also mounted to a custom PCB and enclosed in small plastic enclosure.
The sensor node custom PCB will also have an RJ45 jack mounted to it to facilitate easy connection to the main control unit. This PCB will route power and signals between the RJ45 jack and the proximity sensor.
Connections
The two sensor nodes are connected to the main control unit via standard CAT5 cables. These cables will carry 5v power from the main control unit to the sensor as well as transport signals to/from the sensors. RJ45 jacks mounted to the custom PCB's on both ends make the connections easy!
The relays will be connected to the garage door openers using garage door opener wire (radical!). Replacement wire is easily obtained at your local home improvement store, or online. Any 2-conductor wire in the 20-24 gauge range should work.
The wire will be connected to the openers by piggybacking onto the terminals used by the wall switch. When the relay closes, it'll create a closed loop. To the opener, it'll look exactly like someone pushed the wall switch. Clever, no?
Construction (the good stuff!)Assemble PCB's
The first step is to populate and solder all 3 PCB's. First, we do the 2 PCB's for the sensor nodes. Both are identical.
Next, we build up the PCB for the main controller unit.
Wiring Harnesses
Now we need to connect each sensor node PCB with it's HC-SR04 distance sensor. We'll use pre-crimped wires and Dupont housings to create custom, 4-wire harnesses.
Next, we follow a similar process to connect the main control unit's custom PCB to the 2-channel relay board.
Project Boxes
For protection and neatness purposes, each major component will be housed in a project box. We need 3 boxes: 2 identical boxes for the door positions sensors and 1 for the main control unit. We modeled both designs in Fusion 360 and 3D printed them ourselves on our Ender 3 printer. (STL files of both designs are below)
Assembly
Now it's time to put all the pieces together. We will assemble each sensor node first.
To complete each sensor assembly, we'll need the electronic components (duh), our custom box, 4 short stand-offs, 4 screws and 4 nuts for the stand-offs and a bit of cyanoacrylate glue.
First, install the RJ-45 jack:
Next, secure the distance sensor in the box using cyanoacrylate glue:
Next, connect the sensor PCB to the RJ-45 PCB using the wire harness. Make sure to align that harness plugs correctly so that power and ground are not criss-crossed!
Finally, place the lid on the box and secure with screws:
Next, we assemble the main control unit
<pics of main control unit assembly>
Software
Time to write some code! We need to flash custom firmware on to the Photon. The requirements for the firmware include:
- Poll each distance sensor every second. Convert sensor input into inches.
- Store distance in a Particle variable so it is exposed to the Particle cloud.
- Convert the distance to an "Open" vs. "Closed" state.
- Store the state in a Particle variable so it is exposed to the Particle cloud.
- Expose a Particle function to receive messages/commands to toggle open/close a garage door.
- Use MQTT to receive messages/commands to toggle open/close a garage door.
The full code is attached below. Here's a quick walk-through:
Preamble stuff. Including a couple of libraries, setting up global variables and objects.
// This #include statement was automatically added by the Particle IDE.
#include "HC_SR04_v3.h"
#include "MQTT.h" // added by me
///// Declare/initialize globals /////////////
void mqtt_callback(char* topic, byte* payload, unsigned int length); //declare callback funciotn for MQTT
double inches1 = 0.0; //distance reported by sensor 1
double inches2 = 0.0; //distance reported by sensor 2
String status1; //distance reported by sensor 1 converted to "Open" or "Closed"
String status2; //distance reported by sensor 2 converted to "Open" or "Closed"
String mqttStatus; //status of connection to MQTT broker
int trigPin1 = A0; //the photon pin used to trigger sensor 1
int echoPin1 = A1; //the photon pin used to receive echo/reply for sensor 1
int trigPin2 = A2; //the photon pin used to trigger sensor 2
int echoPin2 = A3; //the photon pin used to receive echo/reply for sensor 2
int relayPin1 = A4; //the photon pin used to trigger relay 1
int relayPin2 = A5; //the photon pin used to trigger relay 2
HC_SR04 rangefinder1 = HC_SR04(trigPin1, echoPin1, 5.0, 400.0); //instantiate an object for sensor 1
HC_SR04 rangefinder2 = HC_SR04(trigPin2, echoPin2, 5.0, 400.0); //instantiate an object for sensor 2
//Establish connection to MQTT broker
byte server[] = { 192,168,1,127 }; // Mosquitto broker address
MQTT mqtt_client(server, 1883, mqtt_callback);
bool inSetup; // a boolean used to indicate that the photon is in it's set-up process.
Integration with HAL
Installation
Time to put all the pieces into their new homes. We'll attach the main control unit to the top of one of the garage door openers. We'll mount each sensor node above each of the garage doors. We'll run garage door opener wire from each relay to the control terminals on each opener. Finally, we'll connect the main control unit to each sensor node with CAT5 cables.
First, the main control unit:
<pics of control unit install>
Next, the sensor nodes:
<pics of sensor node install>
Finally, connect all the dots:
<pics of wiring>
Comments
Please log in or sign up to comment.