Marco Zonca
Published © GPL3+

DMX RGB Mixer for Lights

Five channels circuit to control Red, Green, Blue, Brightness and Strobo of your LED lamps in an handy box!

IntermediateFull instructions provided5,845
DMX RGB Mixer for Lights

Things used in this project

Story

Read more

Schematics

Schematic diagram (Fritzing)

PCB overview

PCB top components

PCB top copper

PCB bottom components

PCB bottom copper (main solder face)

Code

Base DMX Arduino code

Arduino
/*
  This sketch acts as basic DMX lights controller, 5 channels, RGB and STROBO, by Marco Zonca, 2/2021
  Arduino Nano as 5V MPU, C25B TTL/RS485 rtx board, 4 x 10k slider potentiometers,
  one button, 10k potentiometer, RGB led, 3 x LED and a few resistors;

  Channels: 1=brightness
            2=Red
            3=Green
            4=Blue
            5=STROBO (0-7 none, 8-255 rate)
 */

#include <DmxSimple.h>

#define IS_DEBUG false

byte MaxChannel = 5;
bool isSTROBO = false;
bool ledStroboOn = false;

const byte TTL485Pin = 3;
const byte TrimStroboPin = 15; 
const byte TrimRedPin = 16; 
const byte TrimGreenPin = 17; 
const byte TrimBluePin = 18; 
const byte TrimBrightnessPin = 19; 
const byte LedRPin = 11; 
const byte LedGPin = 10; 
const byte LedBPin = 9; 
const byte ButtonRSPin = 7;

const unsigned long refreshRate = 200;  // millis, lower this for a quicker response at changes
const unsigned long ledStroboRate = 250;  // millis, change this for a different led blinking rate
const byte antiBouncing = 1;  // units, change this to 0 for a better granularity of changes
                              // but more rtx traffic, or increase to 2 if you experience jumping values
const byte chStrobo=5;
const byte chBrightness=1;
const byte chRed=2;
const byte chGreen=3;
const byte chBlue=4;


int ValStrobo=0;
int ValRed=0;
int ValGreen=0;
int ValBlue=0;
int ValBrightness=0;
int prevValStrobo=0;
int prevValRed=0;
int prevValGreen=0;
int prevValBlue=0;
int prevValBrightness=0;

unsigned long lastRefresh = 0;  // millis
unsigned long lastStrobo = 0;  // millis

void setup() {
  if (IS_DEBUG) Serial.begin(38400);
  DmxSimple.usePin(TTL485Pin);
  DmxSimple.maxChannel(MaxChannel);
  pinMode(LedRPin, OUTPUT);
  pinMode(LedGPin, OUTPUT);
  pinMode(LedBPin, OUTPUT);
  pinMode(ButtonRSPin, INPUT);
  pinMode(TrimStroboPin, INPUT);
  pinMode(TrimRedPin, INPUT);
  pinMode(TrimGreenPin, INPUT);
  pinMode(TrimBluePin, INPUT);
  pinMode(TrimBrightnessPin, INPUT);
}//setup()


void loop() {
  readButtons();
  readTrimmers();
  if ((lastRefresh+refreshRate) < millis()) {
    if (isSTROBO==true) {
        if ((ValStrobo < (prevValStrobo-antiBouncing)) || (ValStrobo > (prevValStrobo+antiBouncing))) {
          writeDMX(chStrobo, ValStrobo);
          if (IS_DEBUG) Serial.print("STROBO=");
          if (IS_DEBUG) Serial.println(ValStrobo);
          prevValStrobo=ValStrobo;
        }
    }
    if ((ValRed < (prevValRed-antiBouncing)) || (ValRed > (prevValRed+antiBouncing))) {
      writeDMX(chRed, ValRed);
      analogWrite(LedRPin,ValRed/4);
      if (IS_DEBUG) Serial.print("Red=");
      if (IS_DEBUG) Serial.println(ValRed);
      prevValRed=ValRed;
    }
    if ((ValGreen < (prevValGreen-antiBouncing)) || (ValGreen > (prevValGreen+antiBouncing))) {
      writeDMX(chGreen, ValGreen);
      analogWrite(LedGPin,ValGreen/4);
      if (IS_DEBUG) Serial.print("Green=");
      if (IS_DEBUG) Serial.println(ValGreen);
      prevValGreen=ValGreen;
    }
    if ((ValBlue < (prevValBlue-antiBouncing)) || (ValBlue > (prevValBlue+antiBouncing))) {
      writeDMX(chBlue, ValBlue);
      analogWrite(LedBPin,ValBlue/4);
      if (IS_DEBUG) Serial.print("Blue=");
      if (IS_DEBUG) Serial.println(ValBlue);
      prevValBlue=ValBlue;
    }
    if ((ValBrightness < (prevValBrightness-antiBouncing)) || (ValBrightness > (prevValBrightness+antiBouncing))) {
      writeDMX(chBrightness, ValBrightness);
      if (IS_DEBUG) Serial.print("Brightness=");
      if (IS_DEBUG) Serial.println(ValBrightness);
      prevValBrightness=ValBrightness;
    }
    lastRefresh=millis();
  }
  if (isSTROBO==true && (lastStrobo+ledStroboRate) < millis()) blinkLed();
}//loop()

void blinkLed() {  // led blinking
  if (ledStroboOn==false) {
      analogWrite(LedRPin,ValRed/4);
      analogWrite(LedGPin,ValGreen/4);
      analogWrite(LedBPin,ValBlue/4);
      ledStroboOn=true;
    } else {
      analogWrite(LedRPin,0);
      analogWrite(LedGPin,0);
      analogWrite(LedBPin,0);
      ledStroboOn=false;
  }
  lastStrobo=millis();
}//blinkLed()

void readButtons(){
  if (digitalRead(ButtonRSPin) == LOW) {
    if (isSTROBO==false){
        prevValStrobo=0;
        isSTROBO=true;
      } else {
        writeDMX(chStrobo, 0);  // stop Strobo
        if (IS_DEBUG) Serial.print("STROBO=");
        if (IS_DEBUG) Serial.println(ValStrobo);
        analogWrite(LedRPin,ValRed/4);
        analogWrite(LedGPin,ValGreen/4);
        analogWrite(LedBPin,ValBlue/4);
        ledStroboOn=false;
        isSTROBO=false;
    }
    if (IS_DEBUG) Serial.print("isSTROBO=");
    if (IS_DEBUG) Serial.println(isSTROBO);
    delay(250);
  }
}//readButtons()

void readTrimmers(){
  // instead of mapping 0-1023 I use 10-1013 to reach limits 0-255 easily
  ValStrobo=map(analogRead(TrimStroboPin),10,1013,8,255);
  if (ValStrobo < 8) ValStrobo=8;
  if (ValStrobo > 255) ValStrobo=255;
  ValRed=map(analogRead(TrimRedPin),10,1013,0,255);
  if (ValRed < 0) ValRed=0;
  if (ValRed > 255) ValRed=255;
  ValGreen=map(analogRead(TrimGreenPin),10,1013,0,255);
  if (ValGreen < 0) ValGreen=0;
  if (ValGreen > 255) ValGreen=255;
  ValBlue=map(analogRead(TrimBluePin),10,1013,0,255);
  if (ValBlue < 0) ValBlue=0;
  if (ValBlue > 255) ValBlue=255;
  ValBrightness=map(analogRead(TrimBrightnessPin),10,1013,0,255);
  if (ValBrightness < 0) ValBrightness=0;
  if (ValBrightness > 255) ValBrightness=255;
}//readTrimmers()

void writeDMX(const byte ch, const byte val) {
  if (ch > 0 && ch <= MaxChannel ) DmxSimple.write(ch, val);
  if (IS_DEBUG) Serial.print("sent ");
  if (IS_DEBUG) Serial.print(ch);
  if (IS_DEBUG) Serial.print(" ");
  if (IS_DEBUG) Serial.println(val);  
}//writeDMX()

Credits

Marco Zonca

Marco Zonca

12 projects • 43 followers
"From an early age I learned to not use pointers"

Comments