A four-channel DMX relay controller based on a PIC18F1320.
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
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.
DMX relay board schematic.
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 rangefrom 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.