Hi All
I'm sure I'm not the first one to broach the subject, but I can't find anything that can help me.
Can anyone point me in the right direction for a sketch to control an rgb led strip with a temperature sensor to illuminate a radiator cabinet so that when the radiator is cold it illuminates blue and when the radiator is hot it illuminates red.
I am a hopeless coder but good with the hardware side of things.
Any help would be most appreciated.
Thanks
I am a hopeless coder but good with the hardware side of things
So you need to post your schematic because without knowing what you are using or how it is wired up it is imposable to write any code.
I haven't done the hardware yet, I was hoping for a code example first and I'll build the hardware around that.
DillyDog:
I haven't done the hardware yet, I was hoping for a code example first and I'll build the hardware around that.
No that is not how it works, sorry.
Post the documentation/links you have for your hardware first.
OK, so here is the proposed circuit.
What I would like the LED to be blue when cold and change through orange to red when the radiator gets hot.
Where's the current limiting resistors for your leds ?
Where's the data sheet for the leds and mosfets and why aren't all three mosfets wired the same ?
What's up with the two on the right ?
The RGB leds works by writing analog values to their pins. There are 3 pins, one for Red, one for Green and the last one is for the Blue, hence (RGB).
To have an idea about how things work, see the following simple sketch: (I am using Arduino UNO)
#define RGB_RED 9
#define RGB_GREEN 10
#define RGB_BLUE 11
void setup() {
analogWrite(RGB_RED, 120);
analogWrite(RGB_GREEN, 120);
analogWrite(RGB_BLUE, 120);
}
void loop() {
}
I have connected the red pin of the led to pin 9 in arduino, green pin to pin 10 and the blue pin to pin 11. The reason I chose pins 9, 10 and 11 to the RGB led is that they produce PWM signals, not just 0 and 1 values. You are free to use any other PWM pins (marked with '~' on the board). The analogWrite function generates the required PWM according to the supplied value. You can write values in the rang of [0, 255].
If you don't find this explanation good enough for understanding how things work, you can search using the keywords "RGB led arduino" for example. I think you may find this tutorial useful.
Concerning the temperature sensor, I haven't used one yet. However, I think this tutorial greatly covers a lot of aspects of the sensor.
We are here for any further issues.
Regards,
Ahmad.
@ jokes_finder,
Don't get mad but actually I was just thrown off a little because I didn't take enough time to examine the circuit carelfully and I am so accustomed to people who use Fritzing using DIFFERENT COLORS for different signals it caught me off guard when the OP used the same color FOR both the signal AND the power for each of the three colors so you could see which led those lines were related to. Personally, I would have limited that three color scheme to the PWM control signals and use red for the Mosfet Drain and black for the mosfet Source. I don't like the OP's Fritzing because it makes it look like the gates are all shorted to ground and the sources all have a resistor in series. If that were true it would be correct for the resistors but wrong for the gates so I don't know what the hell he's doing there but the illustration is confusing.
Have you heard of the WS2803 ? (SEE ATTACHED)
@OP,
Please draw a correct schematic with pen & paper and take a photo with a cell phone and post it. This Fritzing sucks. I'm sure you didn't wire it the way it looks and I don't know what's going on there. Please post a real schematic.
WS2803-preliminary-En.pdf (437 KB)
Sorry raschemmel for being a bit vague in the first place. I'm probably a bit unorganised when it comes to to circuit design. I tend to draw in block form until a design intention is formulated so being asked for a schematic at this stage threw me a bit!. All I really know is that I will be using an LM35 for temperature sensing and n-channel FETs on the PWM outputs, mainly because I don't know exactly how much of what spec LED I will be using. I hate Fritzing myself but thought it would do to give you an idea of what my intensions were and I failed
In reality, what is stuck on the PWM outputs is a bit irrelevant at the moment, so long as I can get a sketch to do what I want it to do.
I'm a lighting designer by trade and I thought that the arduino would be perfect for this little side project since DMX, DALI, etc would be a bit of overkill for what is in essence a one-trick-pony!
So, shall I come back when I've spec'd up all the hardware?
OK, here's the schematic, nicely drawn in Fritzing. Circuit works fine with a basic RGB sketch, so just need some help with the code now.
This is the sketch I'm using. Instead of it just cycling through HSV, I would like it to go from blue (cold) to red (hot) and back the other way rather than going through green, if that makes sense.
// HSV fade/bounce for Arduino - scruss.com - 2010/09/12
// Note that there's some legacy code left in here which seems to do nothing
// but should do no harm ...
// don't futz with these, illicit sums later
#define RED 9// pin for red LED
#define GREEN 10 // pin for green - never explicitly referenced
#define BLUE 11 // pin for blue - never explicitly referenced
#define SIZE 255
#define DELAY 20
#define HUE_MAX 6.0
#define HUE_DELTA 0.01
//long deltas[3] = { 5, 6, 7 };
long rgb[3];
long rgbval;
// for reasons unknown, if value !=0, the LED doesn't light. Hmm ...
// and saturation seems to be inverted
float hue=0.0, saturation=1, value=1;
/*
chosen LED SparkFun sku: COM-09264
has Max Luminosity (RGB): (2800, 6500, 1200)mcd
so we normalize them all to 1200 mcd -
R 250/600 = 107/256
G 250/950 = 67/256
B 250/250 = 256/256
*/
long bright[3] = { 107, 67, 256};
//long bright[3] = { 256, 256, 256};
long k, temp_value;
void setup () {
randomSeed(analogRead(4));
for (k=0; k<3; k++) {
pinMode(RED + k, OUTPUT);
rgb[k]=0;
analogWrite(RED + k, rgb[k] * bright[k]/256);
}
}
void loop() {
hue += HUE_DELTA;
if (hue > HUE_MAX) {
hue=0.0;
}
rgbval=HSV_to_RGB(hue, saturation, value);
rgb[0] = (rgbval & 0x00FF0000) >> 16; // there must be better ways
rgb[1] = (rgbval & 0x0000FF00) >> 8;
rgb[2] = rgbval & 0x000000FF;
for (k=0; k<3; k++) { // for all three colours
analogWrite(RED + k, rgb[k] * bright[k]/256);
}
delay(DELAY);
}
long HSV_to_RGB( float h, float s, float v ) {
/* modified from Alvy Ray Smith's site: http://www.alvyray.com/Papers/hsv2rgb.htm */
// H is given on [0, 6]. S and V are given on [0, 1].
// RGB is returned as a 24-bit long #rrggbb
int i;
float m, n, f;
// not very elegant way of dealing with out of range: return black
if ((s<0.0) || (s>1.0) || (v<1.0) || (v>1.0)) {
return 0L;
}
if ((h < 0.0) || (h > 6.0)) {
return long( v * 255 ) + long( v * 255 ) * 256 + long( v * 255 ) * 65536;
}
i = floor(h);
f = h - i;
if ( !(i&1) ) {
f = 1 - f; // if i is even
}
m = v * (1 - s);
n = v * (1 - s * f);
switch (i) {
case 6:
case 0:
return long(v * 255 ) * 65536 + long( n * 255 ) * 256 + long( m * 255);
case 1:
return long(n * 255 ) * 65536 + long( v * 255 ) * 256 + long( m * 255);
case 2:
return long(m * 255 ) * 65536 + long( v * 255 ) * 256 + long( n * 255);
case 3:
return long(m * 255 ) * 65536 + long( n * 255 ) * 256 + long( v * 255);
case 4:
return long(n * 255 ) * 65536 + long( m * 255 ) * 256 + long( v * 255);
case 5:
return long(v * 255 ) * 65536 + long( m * 255 ) * 256 + long( n * 255);
}
}
Thanks guys