Go Down

Topic: Arduino and analog led strip (adalight, ambilight, boblight) (Read 4441 times) previous topic - next topic


I have an analog led strip which dont compensate its value with the headache is giving me....my goal is using this with XBMC and in the end i dont know if is easier just to buy a digital strip I have found one that says it have a W2811 IC integrated in the SMD led

i have follow this diagram

Code: [Select]
// color swirl! connect an RGB LED to the PWM pins as indicated
// in the #defines
// public domain, enjoy!

#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3

#define FADESPEED 5     // make this higher to slow down

void setup() {
  pinMode(REDPIN, OUTPUT);

void loop() {
  int r, g, b;

  // fade from blue to violet
  for (r = 0; r < 256; r++) {
    analogWrite(REDPIN, r);
  // fade from violet to red
  for (b = 255; b > 0; b--) {
    analogWrite(BLUEPIN, b);
  // fade from red to yellow
  for (g = 0; g < 256; g++) {
    analogWrite(GREENPIN, g);
  // fade from yellow to green
  for (r = 255; r > 0; r--) {
    analogWrite(REDPIN, r);
  // fade from green to teal
  for (b = 0; b < 256; b++) {
    analogWrite(BLUEPIN, b);
  // fade from teal to blue
  for (g = 255; g > 0; g--) {
    analogWrite(GREENPIN, g);

with the above code all i get is a weird change of color like from blue to magenta to almost white..... what i notice is the blue is always lit. maybe the wiring is mess up

another thing is the code so this work with my XBMC i found this one
Code: [Select]
//Developed by Rajarshi Roy
import java.awt.Robot; //java library that lets us take screenshots
import java.awt.AWTException;
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import java.awt.Dimension;
import processing.serial.*; //library for serial communication

Serial port; //creates object "port" of serial class
Robot robby; //creates object "robby" of robot class

void setup()
port = new Serial(this, Serial.list()[0],9600); //set baud rate
size(100, 100); //window size (doesn't matter)
try //standard Robot class error check
robby = new Robot();
catch (AWTException e)
println("Robot class not supported by your system!");

void draw()
int pixel; //ARGB variable with 32 int bytes where
//sets of 8 bytes are: Alpha, Red, Green, Blue
float r=0;
float g=0;
float b=0;

//get screenshot into object "screenshot" of class BufferedImage
BufferedImage screenshot = robby.createScreenCapture(new Rectangle(new Dimension(1368,928)));
//1368*928 is the screen resolution

int i=0;
int j=0;
//I skip every alternate pixel making my program 4 times faster
for(i =0;i<1368; i=i+2){
for(j=0; j<928;j=j+2){
pixel = screenshot.getRGB(i,j); //the ARGB integer has the colors of pixel (i,j)
r = r+(int)(255&(pixel>>16)); //add up reds
g = g+(int)(255&(pixel>>8)); //add up greens
b = b+(int)(255&(pixel)); //add up blues
r=r/(684*464); //average red (remember that I skipped ever alternate pixel)
g=g/(684*464); //average green
b=b/(684*464); //average blue

port.write(0xff); //write marker (0xff) for synchronization
port.write((byte)(r)); //write red value
port.write((byte)(g)); //write green value
port.write((byte)(b)); //write blue value
delay(10); //delay for safety

background(r,g,b); //make window background average color

Arduino Code: (transfer this program to the Arduino)
//Developed by Rajarshi Roy
int red, green, blue; //red, green and blue values
int RedPin = 9; //Red pin 9 has a PWM
int GreenPin = 10; //Green pin 10 has a PWM
int BluePin = 11; //Blue pin 11 has a PWM
void setup()

//initial values (no significance)
int red = 255;
int blue = 255;
int green = 255;

void loop()

//protocol expects data in format of 4 bytes
//(xff) as a marker to ensure proper synchronization always
//followed by red, green, blue bytes
if (Serial.available()>=4) {
if(Serial.read() == 0xff){
red = Serial.read();
green= Serial.read();
blue = Serial.read();
//finally control led brightness through pulse-width modulation
analogWrite (RedPin, red);
analogWrite (GreenPin, green);
analogWrite (BluePin, blue);
delay(10); //just to be safe

But again if the first simple test didnt work this would work even less

do you recommend i get a digital strip instead ?


First thing I would check with a continuity meter ( when board has no power ) is between the gate of the blue FET and PWM3 ( physically to pin 5 of the actual chip )

If the gate is open circuit and floating , the charge on the gate can keep it on for ages ( thats how some memories work )

I always fit a 22k resistor beteen gate and source, to keep things definate.
45 years of editing projects with a knife and soldering iron, then I found Arduino !


You should have a small current limiting resistor between the PWM pins and the MOSFET.
How long is this strip because powering it through your Arduino could be bad.
What Arduino do you have? If it's an UNO then your powering the LED strip from the Vin pin.
Don't PM me for help as I will ignore it.


I though if you use mosfets you didnt have to use resistors, the power is applied at the other end of the strip


I though if you use mosfets you didnt have to use resistors,

Wrong, a FET gate looks like a capacitor, when a capacitor is discharged it looks like a short circuit, you need something to limit this current to protect your arduino. I would go with a 100R resistor here, not 22K as that will slow down the FET turn on and increase the heat the FET produces.

It will however not stop it from working so it is not the problem you are looking for.
So forget trying to use other people's code and just write something to control one colour at a time. Then you can isolate if you have a hardware fault or a software one.

Go Up