Halloween was right around the corner and I needed a timer with a bunch of relays to trigger some store-bought props and a fog machine periodically. (Mental note: read fog machine specs carefully—not all come with timer remotes.) My first thought was an Arduino and cheap relay board. Second thought was to build something with a micro and some relays. Third thought was that if I’m going to build something, might as well add DMX and package it up into a neat enclosure. Hence, the four channel DMX-controlled relay project was born.
My go to 8-bit micro is a PIC18F1320. I’ve used them on tons of projects, all the development tools are already installed on my computer, and I’m pretty familiar with their idiosyncrasies and peripherals. I’ve also already written both DMX transmitter and DMX receiver code for this micro. The other micros I use a lot are all PIC24s but a 16-bit micro is overkill for this project. PIC18F1320 it is!
Another constraint on this design was to have something that easily fits in an enclosure. I’ve been using Hammond extruded aluminum enclosures for a while now too. They’re well made and look sharp. One of their smaller enclosures holds a 50mm by 80mm PCB which should be plenty of room for this design. Using the smallest enclosure possible reduces the cost of the board, the enclosure, and the end panels.
One last constraint that bears mentioning is the relay selection. I’m only switching small low-voltage, low-current loads. The Omron G5V-1 series of relays are physically small and capable of switching up to 1A at 24VDC. This matched the sorts of loads I was expecting to switch and four of them would fit on my PCB.
Design decisions made: use a PIC18F1320, use a Hammond 1455C801 enclosure, and use Omron G5v-1DC5 relays.
Here’s the schematic for the DMX relay controller. The controller consists of a PIC 18 microcontroller, a crystal oscillator, a power supply, a programming connector, a DMX interface, some relays and their drivers, and an illuminated pushbutton.
I had previously built a few PIC18 projects that used pulse width modulation (PWM) to dim four channels of LEDs with 10-bit resolution. Those projects were powered from 24V and ran the PIC18 as fast as it would run (FCY=40MHz) so there would be plenty of time to service the very frequent interrupts while still listening to the serial port for DMX data. I started with that hardware and software as the basis for this new design but swapped out the LED drivers for some relay drivers and relays.
The PIC18F1320 is capable of running at 40MHz at 5V with a 10MHz crystal oscillator. There’s also a PIC18LF1320 variant that will run at 24MHz at 3.3V with a 6MHz crystal oscillator. Either would work for this design. I went with the 5V version and made this a 5V-only design simply because I’ve had an easier time finding stock, off-the-shelf crystal oscillators in my preferred package for hand soldering that run at 5V than 3.3V.
For an oscillator, I picked a 10MHz, 5V ECS part that I’ve used on past designs. It’s a little big but it’s also very easy to solder by hand. I’m running the PIC18 oscillator in its HSPLL oscillator mode. With the 10MHz crystal, the PIC18 runs with an FCY of 40MHz—way faster than needed for this project because the relays are only either on or off and creation of PWM outputs in an interrupt service routine is not required.
For a power supply, I typically use Cui V7805-500 or Cui VXO7805-500 switching DC-DC converters. Both have a very wide input voltage range–from about 6 to 30+ volts. The wide input voltage is important if controlling, for example, a strand of five or six blue or green LEDs wired in series. In this example, the LEDs would be powered from +24V and then the +24V would be connected to the input of the regulator to generate +5V for the microcontroller. Using a cheap linear regulator such as the LM7805 with a 24V input would result in at least burned fingers and quite possibly a failure of the regulator without a proper heatsink.
The Cui regulators can supply 500mA of current while still running cool to the touch. The relays and the rest of the design only consume about 160mA so plenty of margin. As with most regulators, the CUI parts require some capacitors on both the inputs and outputs for stability. I designed the board to hold one of these switching regulators but ultimately decided not to stuff the component and fed the board directly from a 5V power supply connected to the power connector.
The Microchip standard programming interface is a 6-pin single-row 0.1” header. A number of years ago (possibly over a decade ago), I decided I wanted to use a connector that occupied less board space than the single-row header. I started using a 10-pin double row 2mm header. I should probably switch to 5-pin single row 2mm header at some point. Other than the connector, it’s the same as the standard programming interface.
I copied and pasted both the 2mm header and the /MCLR pin circuitry for this design from an earlier PIC24 design. On PIC24 designs, the /MCLR reset pin requires a 10k pull-up resistor and is particularly sensitive to electrostatic discharge. The 330Ω resistor and 0.1µF capacitor form a low-pass filter and serve to reduce the likelihood of an ESD event resetting the microcontroller. They’re not needed on the PIC18 design so I stuffed the 330Ω resistor pads with a 0Ω jumper and left the 0.1µF capacitor off the board altogether. These changes are noted in the schematic’s info layer.
For the DMX interface, I’m using two RJ-45 connectors and a Texas Instruments SN65HVD06 RS-485 transceiver. The RJ-45 connectors are wired using the less popular Color Kinetics standard where pin 1, the white with orange stripe wire, is the inverting or (-) data signal and pin 2, the orange wire, is the non-inverting or (+) data signal.
As mentioned above, I’m using four Omron G5V-1-DC5 relays. The coil voltage is 5V and the coil draws 30mA when energized. The relay’s contacts can switch up to 1 V at 24VDC. Because the board layout does not have adequate separation between traces for AC line voltage and the board is in an ungrounded aluminum enclosure, this design is NOT suitable for switching AC line voltage. Use with small DC loads under 24V only.
I did not physically have room to connect all the relays’ contacts pins to the outside world. Instead I connected the commons of the top two relays together and the commons of the bottom two relays together and routed these two signals to the outside world. I routed out the normally-open contacts for all four relays. This only required a six position screw terminal strip which fit comfortably on the circuit board and the end panels of the enclosure.
Finally, it’s always good to have a pushbutton and an LED on a microcontroller project. I’m using a very slim NKK illuminated pushbutton that will fit between the RJ-45 jacks and the side of the enclosure. The pushbutton will be used to set the DMX address and the LED indicates the state of the microcontroller: DMX address programming, DMX address confirmation, DMX data valid, or running an idle loop. More on this later in the software section.
Designing the Board for the Enclosure
The board was designed to fit in a Hammond 1455C801 extruded aluminum enclosure. The enclosure has 2mm deep card guides on either side of it to hold an 80mm x 50mm circuit board. In addition, the channel for the end panel screws extends an additional 1.55mm into the interior volume of the enclosure. Any components on the board need to avoid the volume occupied by the card guides and screw channel. This requires a 3.55mm high keep out region at both the bottom and top edges of the board. I used 4mm to be safe. This is particularly important for conductive components and vias that could possibly make contact with the conductive enclosure.
When placing components on the ends of the enclosure, they need to avoid the screws that hold the end panels to the extruded chassis and protrude through both the plastic bezel and end panels. The centers of the screws are 2mm from the edge of the board. The screws have a radius of 2.5mm. The minimum aluminum around any component on the end panels should be about 1mm. If you add these up, the outside edges of any components protruding through an end panel should be at least 5.5mm from the edge of board.
The plastic bezel is 1.5mm thick. The end panels are 1.5mm thick. The outside faces of the end panels will then be 3mm from the left and right edges of the board. Any components that are flush mounted will need to hang off the edge of the board by 3mm. Adjust this dimension up or down depending on the desired amount for a component to extend past or be recessed into the face of the enclosure.
For a layout, I started with a previous design that used this same enclosure, same pushbutton, and same connectors. The only change was moving from a five position Phoenix header to a six position Phoenix header. I’m happy with the layout but I really need to find a smaller surface mount crystal oscillator package that is easy to solder by hand.
I ordered the boards from OSHPark. Here are the renders. The cost for three boards was $31.00.
Enclosure End Panel Design
Once the boards were back and stuffed, I verified they fit in the enclosure as intended. The clearance between the bottom of the board and the enclosure is a bit tight so I used some wire cutters to trim the leads of the longer components to prevent them from making contact with the enclosure and creating a short. Ideally, I’d move to 100% surface mount components when using this enclosure, but I have not done so yet.
Now that I knew the boards fit the enclosure, it was time to design the end panels. I first did this for this arrangement of connectors and pushbuttons on this enclosure over a decade ago. I did it using hand-drawn sketches before the days of easily accessible and affordable CAD packages. Unfortunately, I lost my notes.
The basic process is to draw a dimensioned 2D sketch of the circuit board with the components on one end of the enclosure. Now draw a dimensioned sketch of the end panel over this sketch. The end panel needs to be placed over the circuit board just like it will be when the enclosure is assembled. With a bit of math, you can extrapolate the y positions and heights of the components on the board to the x and y positions of the components on the end panel.
Once the centers of all the components on the panel are known, it’s time to calculate the hole and cut out sizes. When calculating cut out sizes, the smallest milling bit available at Front Panel Express has a diameter of 1mm. The corners of any cutouts will necessarily have a rounded corner with a radius of 0.5mm. If you make the cutout about 0.5mm larger than component, the component will fit easily into the cutout when assembling the enclosure but there could be a bit of interference in the corners.
Repeat for the other end of the enclosure. I’m sure this process could be sped up and made less error prone using Fusion 360 or any other reasonably decent CAD software.
I used Front Panel Express to design and mill the end panels. Once I had the x-y coordinates and cutout sizes, I launched their software. I copied the dimensions from the enclosure data sheet for the basic dimensions of the panel and and the location and dimensions of the screw holes. I chose a thickness of 1.5mm for the end panels.
I then transcribed the positions and dimensions of my cut outs from my notes into Front Panel Express. The final end panels are shown in the figure below.
Before spending the money to have the end panels fabricated, I checked their dimensions using Front Panel Express, ecad.io, and Autodesk Fusion 360. The first step is to gather the required files for Fusion 360.
In the Front Panel Express design software, I exported my front panels as DXF files without reference points. I used ecad.io and the .brd file from Eagle PCB to create a 3D mechanical model of my circuit board without any components on it and exported it as a STEP v2.14 assembly file. I then dug around the component manufacturers’ websites to find 3D models of the enclosure and all the components that would extend through the end panels.
Once I had all the required files, I launched Fusion 360 and uploaded all the files. The DXF files for the end panels needed some depth. I opened each DXF file, used the Push/Pull tool to change the depth of the panels to 1.5mm then hid the sketch and saved the files.
At this point, I created a new design and new component in Fusion 360. I imported each component I previously uploaded into the new design and used the joint command in the assemble menu to place the components on the circuit board, the circuit board in the enclosure, and then the panels on the end of the enclosure.
I used the interference command under the inspect menu to check for interferences between the screw heads and my panels and the connectors and pushbutton and my panels. The interference command detected some interference in the corners of a few of the connectors but it was not enough to concern me.
At this point, I was confident in ordering the panels from Front Panel Express.
The software has four main functions: initialization, DMX address programming, normal DMX run mode, and DMX failure mode.
After reset, the initialization function initializes all the hardware then checks to see if the pushbutton is held down. If the pushbutton is held down and continues to be held down for an entire second, the software jumps into the DMX address programming mode. If the pushbutton is not held down or is released early, the software reads the board’s existing DMX address from the PIC18’s EEPROM and jumps into the DMX run mode.
In the DMX address programming mode, the software listens to the incoming data stream for a DMX channel with the level set to 0xFF. Once a channel with that level is detected, the address of that channel becomes the address of the first relay. The last three relays are assigned the next three consecutive addresses after the first relay. For example, if 0xFF is received on channel 8, the relays will be assigned to channels 8, 9, 10, and 11. Once programming is complete, the address information is saved in EEPROM, the pushbutton light blinks three times, and the software enters the DMX run mode.
In the DMX run mode, the software listens to the incoming data stream for the DMX channels matching the addresses of the relays. Levels for the matching channels are saved to memory. Once the level for the last relay is received, all the relays are updated to their new states. If a level is less than 128, the corresponding relay will be turned off. If a level is greater than or equal to 128, the corresponding relay will be turned on. If less than four relays of channels are received, the relays will not be updated.
While in DMX run mode, if the software does not receive a valid DMX stream for ten seconds, the software will leave DMX run mode and enter DMX failure mode. As soon as a valid DMX stream is received, the software will leave DMX failure mode and return to DMX run mode.
While in DMX failure mode, an idle loop is executed. In this loop, the user can write software to control the relays in absence of a valid DMX signal. This could be as simple as turning all the relays off. For my zombie fogger project, this loop turns on the zombie’s LED lighting and triggers the zombie’s sound effects and fog machine every 30 seconds.
The Final Product
Here’s a photograph of the final product with the end panels installed.
But wait…there’s more!
As an added bonus, with the Luminair 3 app and an Art-Net to DMX interface, I can control my zombies from an iPad!
Design files are located in my Github account.