Tom Moxon
Published © LGPL

DMX-512 : Light & Relay Control

DMX-512 is the protocol used world-wide for theater lighting control, and here is an easy, low cost way to embed it in your projects!

BeginnerFull instructions provided1 hour7,177
DMX-512 : Light & Relay Control

Things used in this project

Hardware components

thingSoC RS485 Expansion
thingSoC RS485 Expansion
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

DMX-512 XLR Jack Wiring Example

Wiring up the connector for standard theater lights

Code

DMXmaster

C/C++
The DMX Master Sketch
/* Welcome to DmxSimple. This library allows you to control DMX stage and
** architectural lighting and visual effects easily from Arduino. DmxSimple
** is compatible with the Tinker.it! DMX shield and all known DIY Arduino
** DMX control circuits.
**
** DmxSimple is available from: http://code.google.com/p/tinkerit/
** Help and support: http://groups.google.com/group/dmxsimple       */

/* To use DmxSimple, you will need the following line. Arduino will
** auto-insert it if you select Sketch > Import Library > DmxSimple. */

#include <DmxSimple.h>

#define MAXCHAN 254

const int RedPin =     A3;  // PWM output pin for Red Light.
const int GreenPin =   A2;  // PWM output pin for Green Light.
const int BluePin =     7;  // PWM output pin for Blue Light.
const int YellowPin =   8;  // PWM output pin for Yellow Light.
const int Relay1Pin =   3;
const int Relay2Pin =  10;

void setup() {
  /* enable LED outputs */
  pinMode(RedPin,    OUTPUT); // sets the digital pin as output
  pinMode(GreenPin,  OUTPUT);
  pinMode(BluePin,   OUTPUT);
  pinMode(YellowPin, OUTPUT);
  pinMode(Relay1Pin, OUTPUT);
  pinMode(Relay2Pin, OUTPUT);  
  digitalWrite(RedPin,    LOW);
  digitalWrite(GreenPin,  LOW);
  digitalWrite(BluePin,   LOW);
  digitalWrite(YellowPin, LOW);
  digitalWrite(Relay1Pin, LOW);
  digitalWrite(Relay2Pin, LOW);
  delay(200);
  digitalWrite(RedPin, HIGH);
  digitalWrite(GreenPin, HIGH);
  digitalWrite(BluePin, HIGH);
  /*
   * Configure RS-485 Driver Enable as Output for DMX512 Master
   * Rev4.0  = D5
   * Rev5.0  = D2
   */
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);
  /* 
   *  If RDM512, Configure RS-485 Driver for RDM512 Input
   * Rev4.0  = D6
   * Rev5.0  = D0   */
  pinMode(0, INPUT);
 
  /* The most common pin for DMX output is pin 3, which DmxSimple
   * uses by default. If you need to change that, do it here. 
   * Rev4.0  = D4
   * Rev5.0  = D1
   */
  DmxSimple.usePin(1);

  /* DMX devices typically need to receive a complete set of channels
  ** even if you only need to adjust the first channel. You can
  ** easily change the number of channels sent here. If you don't
  ** do this, DmxSimple will set the maximum channel number to the
  ** highest channel you DmxSimple.write() to. */
  DmxSimple.maxChannel(MAXCHAN);

  /* turn on brightness channel(s) */
  DmxSimple.write(11, 255);
  digitalWrite(YellowPin, HIGH);
}

void loop() {
  int channum;
  byte level;

  digitalWrite(RedPin,    LOW);
  DmxSimple.write(12, 255);
  delay(1000);
  digitalWrite(RedPin,    HIGH);
  digitalWrite(GreenPin,  LOW);
  DmxSimple.write(12, 0);
  DmxSimple.write(13, 255);
  delay(1000);
  digitalWrite(GreenPin,  HIGH);
  digitalWrite(BluePin,   LOW);
  DmxSimple.write(13, 0);
  DmxSimple.write(14, 255);
  delay(1000);
  digitalWrite(BluePin,   HIGH);
  digitalWrite(YellowPin, LOW);
  DmxSimple.write(14, 0);
  DmxSimple.write(15, 255);
  delay(1000);
  digitalWrite(YellowPin, HIGH);
  digitalWrite(Relay1Pin, HIGH);
  DmxSimple.write(15, 0);
  DmxSimple.write(16, 255);
  delay(1000);
  digitalWrite(Relay1Pin, LOW);
  digitalWrite(Relay2Pin, HIGH);
  DmxSimple.write(16, 0);
  DmxSimple.write(17, 255);
  delay(1000);
  digitalWrite(Relay2Pin, LOW);
  DmxSimple.write(17, 0);
}

DMXSlave

C/C++
The DMX Slave node sketch
// - - - - -
// DmxSerial - A hardware supported interface to DMX.
// DmxSerialRecv.ino: Sample DMX application for retrieving 3 DMX values:
// address 1 (red) -> PWM Port A3
// address 2 (green) -> PWM Port A2
// address 3 (blue) -> PWM Port D7
// 
// Copyright (c) 2011-2015 by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// 
// Documentation and samples are available at http://www.mathertel.de/Arduino
// 25.07.2011 creation of the DmxSerial library.
// 10.09.2011 fully control the serial hardware register
//            without using the Arduino Serial (HardwareSerial) class to avoid ISR implementation conflicts.
// 01.12.2011 include file and extension changed to work with the Arduino 1.0 environment
// 28.12.2011 changed to channels 1..3 (RGB) for compatibility with the DmxSerialSend sample.
// 10.05.2012 added some lines to loop to show how to fall back to a default color when no data was received since some time.
// - - - - -

#include <DMXSerial.h>

// Constants for demo program

const int RedPin =     A3;  // PWM output pin for Red Light.
const int GreenPin =   A2;  // PWM output pin for Green Light.
const int BluePin =     7;  // PWM output pin for Blue Light.
const int YellowPin =   8;  // PWM output pin for Yellow Light.
const int Relay1Pin =   3;
const int Relay2Pin =  10;


#define RedChannel          12
#define RedDefaultLevel    255
#define GreenChannel        13
#define GreenDefaultLevel  255
#define BlueChannel         14
#define BlueDefaultLevel   255
#define YellowChannel       15
#define YellowDefaultLevel 255
#define Relay1Channel       16
#define Relay1DefaultLevel   0
#define Relay2Channel       17
#define Relay2DefaultLevel   0
void setup () {
  /* enable LED outputs */
  pinMode(RedPin,   OUTPUT); // sets the digital pin as output
  pinMode(GreenPin, OUTPUT);
  pinMode(BluePin,  OUTPUT);
  pinMode(YellowPin,  OUTPUT);
  pinMode(Relay1Pin,  OUTPUT);
  pinMode(Relay2Pin,  OUTPUT);
    
  DMXSerial.init(DMXReceiver);
  
  // set some default values
  DMXSerial.write(RedChannel, RedDefaultLevel);
  DMXSerial.write(GreenChannel, GreenDefaultLevel);
  DMXSerial.write(BlueChannel, BlueDefaultLevel);
  DMXSerial.write(YellowChannel, YellowDefaultLevel);
  DMXSerial.write(Relay1Channel, Relay1DefaultLevel);
  DMXSerial.write(Relay2Channel, Relay2DefaultLevel);    
}


void loop() {
  // Calculate how long no data backet was received
  unsigned long lastPacket = DMXSerial.noDataSince();
  
  if (lastPacket < 5000) {
    analogWrite(RedPin,  255-DMXSerial.read(RedChannel));
    analogWrite(GreenPin,  255-DMXSerial.read(GreenChannel));
    analogWrite(BluePin,   255-DMXSerial.read(BlueChannel));
    analogWrite(YellowPin, 255- DMXSerial.read(YellowChannel));
    digitalWrite(Relay1Pin, DMXSerial.read(Relay1Channel));
    digitalWrite(Relay2Pin, DMXSerial.read(Relay2Channel));
            
  } else {
    // Show pure red color, when no data was received since 5 seconds or more.
    analogWrite(RedPin,    RedDefaultLevel);
    analogWrite(GreenPin,  GreenDefaultLevel);
    analogWrite(BluePin,   BlueDefaultLevel);
    analogWrite(YellowPin, YellowDefaultLevel);
    digitalWrite(Relay1Pin, Relay1DefaultLevel);
    digitalWrite(Relay2Pin, Relay2DefaultLevel);
  }
}

Embedis

Embedis Library for the Arduino IDE

Credits

Tom Moxon

Tom Moxon

16 projects • 38 followers
Chip Designer, Embedded Hardware and Software Design
Thanks to PaulStoffregen.

Comments