RGB(W) arduino device

Keep getting surprised how simple it is again and again.

Comments on the sketch please :smiley: (so that I can learn how to make these things correctly)

EDIT: I just noticed that the variable V_DIMMER is a value between 0-100 right? This I need to take in to account also

Yep,

Other that that I give you green light to push the upload button and launch your new RGBW controller :wink:

not yet, I found a bug in it :smiley:

I included some code that would take in to account if the different colors have different Luminosity and you would like to harmonize them but in the analog write I just use the one dedicated for RED color

analogWrite(message.header.childId, 256*incomingDimmerStatus/100 * brightr/256);

I guess I will remove this code for nowā€¦

Korttoma,

Would you mind giving a quick hardware rundown for this project. Iā€™ve been looking at trying to add some RGBW lights recently and Iā€™m curious if this is a better/cheaper solution.

Thanks

Hardware is as simple as a transistor and a resistor per channel. I got the idea from here ā†’ Jerome Bernard: RGB Led Strip controlled by an Arduino

Transistors: IRLZ44N
Resistors 10kohm

Iā€™ve also built a simple single-channel LEDStripDimmer circuit and sketch for a Warm White LED strip that I am going to mount under my kitchen cabinets. I will share everything here once I complete it beyond the prototyping stage.

I know this is a bit out of scope but where is everyone getting their rgbw strips from?

This is the one I got.
http://www.aliexpress.com/item/RGBW-RGB-Warm-White-3528-SMD-60led-m-Flexible-Waterproof-300LED-Strip-Light-RGBW-44key-IR/1498052414.html

Price has gone up 4$ since I got it though.

[quote=ā€œkorttoma, post:12, topic:178207ā€]Iā€™we been looking in to this RGB(W) a bit today and it seems there are not enought PWM outputs on the Pro mini for all four channels.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

Only 3,5 and 6 are free since the radio is using 9,10 and 11.

I guess the easiest solution would be to have a separate arduino for white using a normal dimmer sketch and separate arduino for RGB sketch.
Unless there is a easy way to free one more PWM from the radio side.

Any thoughts on this?[/quote]
Hello all - Iā€™m new to Vera but not new to AVRs at all here.

There are a couple of options for this:

  1. Atmel has a good app note on low-jitter efficient software PWM. You can achieve reasonable dimming performance on any I/O pin, Iā€™ve gotten up to 8 channels on a MegaXX8. Bad news is I donā€™t know if anyone has implemented this using the Arduino development environment - but you can most definitely achieve this using avr-gcc (FYI, itā€™s perfectly feasible to program Arduino hardware with any other AVR development environment, I use avr-gcc all the time.) An example of 12-bit software PWM (a bit more than that - the PWM engine ran at 8 bits but was dithered using a sigma-delta modulator) with an 8-bit-to-12-bit gamma lookup table running on an ATTinyX5 is at GitHub - Entropy512/I2C_RGB: I2C Controllable RGB LED driver in an Atmel ATTinyX5 - I have some HSV to RGB translation code somewhere, I canā€™t remember if I did it node-side or controller-side. The code above was never very reliable because the Tinyā€™s USI makes implementing a reliable I2C slave a nightmare - but since you would be using some other interface than I2C-via-USI, youā€™d just be using the dimming stuff which was pretty solid.
  2. There are a lot of good dimmer chips out there with multichannel PWM. The PCA9635 is really easy to work with (other than being an SOIC, but Sparkfun sells some great SOIC adapters.) - An example of driving a 9635 is at GitHub - Entropy512/DMX_PCA9635: DMX-512 to I2C bridge, supporting PCA9635 I2C devices

The above two projects are currently pretty much abandoned, I wound up too busy with other things, and the I2C-RGB thing was superseded by the far cheaper WS2801 nodes.

(offtopic question - how do you keep the forumā€™s insistence on no less than 4 verification questions per post from driving you insane?)

Here is the finished RGBW sketch if someone wants itā€¦

Iā€™m not very good when it comes to hardware (software developer, not EE) so Iā€™d appreciate if someone could sanity check my post. I can use a soldering iron, I know what a resistor does in theory, but I have no idea how it is used in practice (for example, I had to learn about pull-up resistors from sparkfun.com about 2 hours ago) and I know enough not to short out a capacitor with a screwdriver, but that is pretty much itā€¦ I can however follow instructions to the letter :stuck_out_tongue:

I want to use an Arduino to PWM dim an RGBW strip Iā€™ve got attached to the back of my TV.
I also want to have a ā€œsensorā€ that flicks a virtual switch whenever the TV turns on or off (that Iā€™ll use to turn on/off the RGBW strip and various room lightning).

I will use a (non-dimmable) 12v transformer to power the Arduino and the RGBW strip, pretty much as linked above (mosfets, etc), should be a non-issue I think.
The TV has an USB out, so I figure I can use this to detect the on/off status of the TV by connecting it to the Arduino input pins. I will NOT power the Arduino from the TVā€™s USB.

I want to protect the TVā€™s USB controller (at all costs) from any dumb things I do (which will be a lot), I think I have two options:
a) Use an opto-isolator (NEC PS2501 ?) and keep the TVā€™s USB feed electrically isolated from the Arduino. I guess I need to add a resistor after the isolator on both the USB and the Arduino end to keep from causing a short - Is this correct? If yes, what size? After or before isolator?
b) The second alternative I came up with is connect the USB 5v from the TV to one of the Arduinos input pins, should be pulled high when the TV starts. To protect the TV Iā€™ve tried to find 5v 500ma fuses, but I canā€™t find any polyfuses in that size. I also donā€™t know where to put it (5v, GND, both?). Suggestions?
Also, if I do b), should I use a diode on the USB 5v line to prevent ā€œbackcurrentā€ from when I break the Arduino by applying 12v to the wrong place?

If I do b), do I connect the USB GND to the Arduino GND? Bit confused since theyā€™ll essentially have different groundsā€¦ the Arduino is fed from the 12v transformer while the USB is fed from the TVā€™s internal powersupply. Also, do I need a resistor here somewhere?

Any input would be appreciated!

Just put together a device and uploaded this to it. Works, but when you select 100% on any of the channels it turns off. Iā€™ll tinker with the sketch and all to see if I can contribute anything useful.

Wonder how hard it will be to combine the 3 and/or 4 devices into one single Vera device with the correct number of settings inside it.

I already have RGB light strips in the kitchen, so I need to make two 3-channel RGB control modules for them (2 sets of cabinetsā€¦no way to link them via wire without ripping out drywall. Kitchen is downstairs so no access method to run wiring up one wall and down another. I may go ahead and make them RGBW controls in case I want to add in white laterā€¦maybe inside the cabinets so they can be trigged by a magnetic switch when a door is opened.

Thanks for the work of all involvedā€¦this is some really cool stuff.

OKā€¦figured out the error making it turn off at 100%

Change this line:

     analogWrite(message.header.childId, 256*incomingDimmerStatus/100);

to

     analogWrite(message.header.childId, 255*incomingDimmerStatus/100);

Lights operate on 0-255, so using 256 to multiply by basically was setting 100% to 0. If you send higher numbers to the pins, they just cycle over the 0-255 range again.

256 = 0
257 = 1
ā€¦
510 = 254
511 = 255
512 = 0

and so onā€¦

@Korttoma, Iā€™ve been doing research, but I specifically want to use this in my vera. Is there any ways you could do a simple write up of how you did all the hardware (And what is needed) to accomplish this? I would like to use this behind my Bathroom Mirrors (there is a gap between the mirrors and the wall).

@Korttoma, Iā€™ve been doing research, but I specifically want to use this in my vera. Is there any ways you could do a simple write up of how you did all the hardware (And what is needed) to accomplish this? I would like to use this behind my Bathroom Mirrors (there is a gap between the mirrors and the wall).[/quote]

The hardware is pretty basic. In addition to your Arduino/radio combo, youā€™ll need
4x NPN MOSFETS (I use 30N06L) to handle the regulation of the 12V power to the LED strip
4x 120 ohm resistors

I donā€™t have the schematic handy but in a nutshell:
D3 ā†’ resistor ā†’ PIN #1 MOSFET #1
D5 ā†’ resistor ā†’ PIN #1 MOSFET #1
D6 ā†’ resistor ā†’ PIN #1 MOSFET #1
D9 ā†’ resistor ā†’ PIN #1 MOSFET #1

MOSFET #1 PIN #2 ā†’ LED strip RED
MOSFET #2 PIN #2 ā†’ LED strip GREEN
MOSFET #3 PIN #2 ā†’ LED strip BLUE
MOSFET #4 PIN #2 ā†’ LED strip WHITE

All MOSFETs have PIN #3 connected to ground.
RGB Strip V+ goes to the 12V+

IMPORTANT TO NOTE:

With the pin configuration used here, you will move the radioā€™s CE pin (PIN #9) to PIN #4 of the Arduino. Weā€™re using PIN #9 for the WHITE pin so the sketch is written for the radio on PIN #4.

Make sure the Arduino GND is linked to the 12V+ supply ground. I use an UNO for this since it already has a DC jack built on it and will run off the 12V supply. It also provides the 3.3V for the radio.

Hereā€™s the modified code for the dimmers (one change to the multiplier in the original sketch to correct for 100% turning the LEDs off):

[code]// Example sketch showing how to control RGBW LED Strip.

//IMPORTANTE NOTE!!! one of the ā€œradioā€ pins has been moved from pin 9 to pin 4 because the White is connected to pin 9 !!!

// This code should generate 4 Dimmer devices in Vera so you can control the RED, GREEN, BLUE and WHITE individualy

#include <Relay.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>

// Set RADIO_ID to something unique in your sensor network (1-254)
// or set to AUTO if you want gw to assign a RADIO_ID for you.
#define RADIO_ID 4

#define RED 3 // pin for red LED
#define GREEN 5 // pin for green
#define BLUE 6 // pin for blue
#define WHITE 9 // pin for white

Relay gw(4,10);

void setup()
{
Serial.begin(BAUD_RATE); // Used to write debug info

gw.begin(RADIO_ID);

// Register all sensors to gw (they will be created as child devices)
gw.sendSensorPresentation(RED, S_DIMMER);
gw.sendSensorPresentation(GREEN, S_DIMMER);
gw.sendSensorPresentation(BLUE, S_DIMMER);
gw.sendSensorPresentation(WHITE, S_DIMMER);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(WHITE, OUTPUT);
  analogWrite(RED, 0);
  analogWrite(GREEN, 0);
  analogWrite(BLUE, 0);
  analogWrite(WHITE, 0);

// Request/wait for relay status
 gw.getStatus(RED, V_DIMMER);
setDimmerStatus(gw.getMessage()); // Wait here until status message arrive from gw
 gw.getStatus(GREEN, V_DIMMER);
setDimmerStatus(gw.getMessage());
 gw.getStatus(BLUE, V_DIMMER);
setDimmerStatus(gw.getMessage());
 gw.getStatus(WHITE, V_DIMMER);
setDimmerStatus(gw.getMessage());

}

/*

  • Example on how to asynchronously check for new messages from gw
    */
    void loop()
    {
    if (gw.messageAvailable()) {
    message_s message = gw.getMessage();
    setDimmerStatus(message);
    }
    }

void setDimmerStatus(message_s message) {
if (message.header.messageType=M_SET_VARIABLE &&
message.header.type==V_DIMMER) {
int incomingDimmerStatus = atoi(message.data);
// Change Dimmer level

 analogWrite(message.header.childId, 255*incomingDimmerStatus/100);
 // Write some debug info
 //Serial.print("Incoming change for dimmer on pin:");
 //Serial.print(message.header.childId);
 //Serial.print(", New status: ");
 //Serial.println(incomingDimmerStatus);

}
}[/code]

Hope this helpsā€¦if someone wants to post the schematic before I dig it upā€¦

Remember tooā€¦this will create 4 separate dimmers in Vera. I renamed mine under the Advanced tab for each device since the plugin will use generic names. Screenshot attached.

It seems like you have used a different schematic from what I did. I used the one from Jerome Bernards blog but I guess the principle is the same. The one I use has some 10kohm resistor to ground to ensure all channels are off until the arduino has started. How does your setup work when you turn it on?

NOTE! there seems to be some error in the picture in Jeromes blog but the idea is " 10kĪ© resistors, between each control/gate pins and ground, in order to force the signal to LOW until the Arduino kicks in!"

[url=http://www.jerome-bernard.com/blog/2013/01/12/rgb-led-strip-controlled-by-an-arduino/]http://www.jerome-bernard.com/blog/2013/01/12/rgb-led-strip-controlled-by-an-arduino/[/url]

It seems like you have used a different schematic from what I did. I used the one from Jerome Bernards blog but I guess the principle is the same. The one I use has some 10kohm resistor to ground to ensure all channels are off until the arduino has started. How does your setup work when you turn it on?

NOTE! there seems to be some error in the picture in Jeromes blog but the idea is " 10kĪ© resistors, between each control/gate pins and ground, in order to force the signal to LOW until the Arduino kicks in!"

[url=http://www.jerome-bernard.com/blog/2013/01/12/rgb-led-strip-controlled-by-an-arduino/]http://www.jerome-bernard.com/blog/2013/01/12/rgb-led-strip-controlled-by-an-arduino/[/url][/quote]

I havenā€™t paid much attention to the startup stateā€¦Iā€™ll have to look next time I reassemble it. I think it starts up in the same state it was previously, which didnā€™t bother me so I didnā€™t actually care.

I used the Adafruit tutorials as the guide: Usage | RGB LED Strips | Adafruit Learning System

I was hesitant to use the Jerome Bernard one since the breadboard layout errorā€¦amazing how your trust in someoneā€™s circuit is shaken if they post instructions with an error and it isnā€™t correct 14 months later. His blog links back to the Adafruit tutorial also, so I just fell back on that by default.

The resistor in the Adafruit schematic is for lower-capacity MOSFETs like I usedā€¦

All my breadboards are tied up in other sensor tests and things, and I havenā€™t gotten around to getting the LED board etched yet. Iā€™ll reassemble this weekend and if the 10K resistors are helpful Iā€™ll add them to the board I put together in Eagle.

Hi All,

I just wanted to let others know that apparently the MOSFETs mentioned in Jeromeā€™s blog (IRFZ44N) donā€™t work well with 3.3v Arduinos. I have also been unable to get them to work with a 5v Pro Mini. Just wanted to let others know in case they are ordering parts based on the blog. I also noticed now (too late) that later on in the comments of the blog post Jerome says he switched to a logic level MOSFET (IRLZ44N).

If anyone has any ideas for how I can make my IRFZ44N MOSFET work Iā€™m open to trying whatever is suggested. If thereā€™s not much I can do I will just have to wait for some IRFZ44N MOSFETs.

Thanks,

Pete

[quote=ā€œpetewill, post:38, topic:178207ā€]Hi All,

I just wanted to let others know that apparently the MOSFETs mentioned in Jeromeā€™s blog (IRFZ44N) donā€™t work well with 3.3v Arduinos. I have also been unable to get them to work with a 5v Pro Mini. Just wanted to let others know in case they are ordering parts based on the blog. I also noticed now (too late) that later on in the comments of the blog post Jerome says he switched to a logic level MOSFET (IRLZ44N).

If anyone has any ideas for how I can make my IRFZ44N MOSFET work Iā€™m open to trying whatever is suggested. If thereā€™s not much I can do I will just have to wait for some IRFZ44N MOSFETs.

Thanks,

Pete[/quote]

I havenā€™t had time to build my own LED dimmer yet.
Are you saying I should recommend IRLZ44N instead in the buying guide on mysensors.org?

Anyone who has build led dimmer here that can confirm this?

According to the specs the IRLZ44N would like at least 4.4 volts G-S to start conducting efficiently
The IRLZ44N would work well at 2.5 volts.

The 10K resistors to pull the gate down to ground instead of letting them float when the arduino is not powered or is starting up.
And itā€™s important to have a common ground between the Arduino power and the LED power to drive the MOSFET properly.