Skip to content

Instantly share code, notes, and snippets.

@Krutonium
Last active June 16, 2022 22:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Krutonium/1bd094800702f00df339ce6a3d29ab85 to your computer and use it in GitHub Desktop.
Save Krutonium/1bd094800702f00df339ce6a3d29ab85 to your computer and use it in GitHub Desktop.
My Adventure with RGB

On 03/03/2021 I discovered that my local dollar store had $4 strips of RGB lights. They could be controlled with an IR remote, similar to an old TV.

I purchased it, and immediately stripped the shrink wrap off the controller. I discovered 2 things from this:

  1. If I want to control the the RGB strip, I'm going to need to remove it
  2. It's actually pretty simple!

1 is because it has no reverse power protection as far as I can tell, so applying power to any of the colors could cause the microcontroller to turn on, and then switch everything to white - Spreading the power based love, as it were. 2 is because the way it works, well, is simple! You supply 5V on one line, and ground the color you want. Presumably you could use somthing akin to PWM to control the intensity.

(The controller in question is an ATMHK225)

I cut the built in MicroController off (It has some fun components I may user later though, like the relatively unknown microcontroller, and the IR Reciever! Having done that, I wrote a bit of code for my Arduino UNO based on the ATMEGA328 chip. (At this point I realized that the chip on the RBG Controller is ATMEL. Possible super simple Arduino project?)

void setup() {
  pinMode(3, OUTPUT);
}

void loop() {
  for(int i=0; i < 255; i++){
    analogWrite(3, i);
    delay(5);
  }
  for(int i=255; i>0; i--){
    analogWrite(3,i);
    delay(5);
  }
}

I 5v as a PWM source, which is unfortunate, because it means I can't change the brightness of each color individually. What I need is more like PWM Ground - Which having asked, apparently is not a thing?

Either way, this means that via the selective flipping of Ground I can make and mix colors, at least in theory, but not have any one color brighter than the others.

So my colors are limited to whatever I can directly mix from R G and B without varying brightness between them.

Update 1:

I realized I can use the PWM Pins on my Arduino as ground, as long as I remember that the values are inverse of what they should be - 255 is off and 0 is full on. I now have full per color lighting control - Mostly. The LED's never actually turn off. This could probably be fixed using a resistor (haha, I'm driving this directly from the Arduino with no power control.)

My Code now looks like this:

int redPin = 3;
int greenPin = 5;
int bluePin = 6;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  analogWrite(redPin, 255);
  analogWrite(greenPin, 255);
  analogWrite(bluePin,255);
}

void loop() {
  for (int p = 0; p < 3; p++) {
    int currentPin;
    if(p==0){
      currentPin = redPin;
    } else if(p==1){
      currentPin = greenPin;
    } else if(p==2){
      currentPin = bluePin;
    }
    for (int i = 255; i > 0; i--) {
      analogWrite(currentPin, i);
      delay(5);
    }
    for (int i = 0; i < 255; i++) {
      analogWrite(currentPin, i);
      delay(5);
    }
  }
}

As expected, the RGB Strip is cycling through each color in sequence. And the light level transitions? Substancially better than the original controller was capable of. OpenRGB Support When?

Update 2: I realized that if I call

    DigitalWrite(currentPin, HIGH);

at the end of the loop, I can get the LED's to turn completely off. Nice!

YouTube of the results so far (TBC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment