Help, configuring blue to red colour, configure multiple onewire sensors

Hey guys,

I got my arduino, and I am totally lost with coding, i followed some docs to wire up correctly, found a code on youtube.
I tried myself altering code to try get more steps of colour fade and made 0 difference..

can I get some help?

I want to use 3x onewire sensors and make each sensor choose a colour based on temperature.
i also dislike that my current codes dont fade smoothly, more like jump different colour tones

in order to do this I need to remove one of the rgb signals as the arduino board has only 6 pwm outputs...

this is what im working with,
i also attached the diagram for my setup

ty

// 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 ...

#include "OneWire.h"
//#include "Streaming.h"

const int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
#define MIN_TEMP 20
#define MAX_TEMP 40

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2

// 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    0
#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));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED + k, OUTPUT);
    rgb[k]=0;
    analogWrite(RED + k, rgb[k] * bright[k]/256);
  }
}

void loop() {
  float temperature = constrain(getTemp(), MIN_TEMP, MAX_TEMP);
  
  float deltaTemp = (MAX_TEMP - MIN_TEMP);
  float deltaHue = 4 - 0;
  hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp * 100, deltaHue * 100, 0) / 100.0;
  
  //Serial << "Temperature: " << temperature << endl;
  //Serial << "HUE: " << hue << endl;
  
  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);
}

float getTemp(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
   //no more sensors on chain, reset search
   ds.reset_search();
   return -10;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -10;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -10;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = ds.reset();
 ds.select(addr);  
 ds.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = ds.read();
 }
 
 ds.reset_search();
 
 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
}

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);
  }
}

rgb-led-strips-mosfets-temperature.png

Software means little without knowing the hardware setup you have. So please post a schematic and while you are about it read the how to use this forum sticky post and post that code correctly. The forum software mangles code not posted correctly as you will see if you look back at your post.

sorry my code was mangled.. i sorted it out and added a diagram.

i hope you can help with my code to complete my project..
to recap,

i need the colour red/blue only
thermal set between 10-60 degree
blue cold, red hot
smooth fade

3 input sensors,
each sensor needs to set 1 set of red/blue leds

i have mosfet all working. to allow string of led

toxsickcity:
Hey guys,

I tried myself altering code to try get more steps of colour fade and made 0 difference..

i also attached the diagram for my setup

Your fritzing diagram does not show any sensors just rgb leds.

Post a link to your inspiration.

#include "OneWire.h"
//#include "Streaming.h"

const int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
#define MIN_TEMP 20
#define MAX_TEMP 40

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2

this is the sensor..

this works

I think I forgot to explain whats going on,

I got the codes from a bloke.

He uses a onewire thermal sensor and I think that the codes call for another codes called onewire.h

Currently the codes all in all allow 1 sensor to control 1 RGB string,

I need to change plenty of codes and possibly different sensors..

I think it is best to start new, as I dont like how the fade is not smooth and the usage of CHUNKY Onewire Sensors which wont fit into small places..

I am asking for someone to help me with setting up what I need.

I need to control 3 pairs of RED/BLUE LED's using 3 sensors.

I have tried endlessly tried to add codes and other segments of the code changed trying to add sensors to the codes and tried even changing colours..

I'm just lost

Please Help,

My Project is Simple..
I am building a WALL Computer with plexi/LED colours
I am wishing to apply each component such as HDD/Motherboard/Radiator/VGA to have the lighting beneath the Plexi to represent heat levels of the device.

Please see the image here for idea of what I am going to build

I think I forgot to explain whats going on,

Yes you did.

You might also have forgotten to read How to use this forum as it tells you how to ask a question.

I have tried endlessly tried to add codes and other segments of the code changed trying to add sensors to the codes

So what we need to see is one of those attempts so we can guide you as to what to do to fix your problem.

You have also not posted a schematic of how things are wired and not posted anything about the sensors you want to use. Again read how to use this forum.

I read the how to page,

I've put the code in code boxes,
I uploaded the schematic diagram. first post.

so my understanding is to put a and b after sensor in attempt to seperate 2 sensors first on digital pin 2, second on digital pin 4.

// 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 ...

#include "OneWire.h"
//#include "Streaming.h"

const int DS18S20a_Pin = 2; //DS18S20 Signal pin on digital 2
#define MIN_TEMP 20
#define MAX_TEMP 40

//Temperature chip i/o
OneWire ds(DS18S20a_Pin); // on digital pin 2

const int DS18S20b_Pin = 4; //DS18S20 Signal pin on digital 4
#define MIN_TEMP 20
#define MAX_TEMP 40

//Temperature chip i/o
OneWire ds(DS18S20b_Pin); // on digital pin 4

this brings an error,

Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Uno"

sketch_jan06a:20: error: redefinition of 'OneWire ds'

 OneWire ds(DS18S20b_Pin); // on digital pin 4

                        ^

sketch_jan06a:13: error: 'OneWire ds' previously declared here

 OneWire ds(DS18S20a_Pin); // on digital pin 2

         ^

exit status 1
redefinition of 'OneWire ds'

If i change, "OneWire ds(DS18S20b_Pin); // on digital pin 2" to "OneWire dsb(DS18S20b_Pin); // on digital pin 2" the verify code passes, but have a feeling it is ignoring 2nd sensor..

my hopes were to simply see if adding this code would register the temperature on both pins 2 and 4, so if i moved sensor from pin 2 to pin 4 it would continue working. i would hoped it worked then continue to work out how to separate the colouring.


another method i tried to copy all code then paste it at the bottom, thinking i can make it run 2 programs then change most of code constants and vars with prefix of 2, but got errors stating things were not defined and others.. i will stay away from that method...

so thats my last two attempts at coding,

question, can i simply copy and paste the code and run the two programs(segments of code) like code for sensor 1, code for sensor 2,

the include, onewire.h code looks like this
attached file

thanks

EDIT:
I have a diagram coming...

OneWire.h.ino (14.4 KB)

toxsickcity:

// HSV fade/bounce for Arduino - scruss.com - 2010/09/12

OneWire ds(DS18S20a_Pin); // on digital pin 2
OneWire ds(DS18S20b_Pin); // on digital pin 4




this brings an error,

You are trying to define 2 objects with the same name. Both are named 'ds'. That is the error.
Each of them needs a unique name so that you can distinguish when you use them in your code.

I uploaded the schematic diagram. first post.

No you didn't. You uploaded a physical layout diagram NOT a schematic. That thing you uploaded is next to useless for communicating what you did and there were no component names ( numbers ) on what you had.

question, can i simply copy and paste the code and run the two programs(segments of code) like code for sensor 1, code for sensor 2,

No not without understanding what you are doing.

The sensor is a 1 wire bus sensor, that means it only needs one wire ( one pin ) for as many sensors as you want. You do not need two instances of this bus.

I have a diagram coming...

I hope it is not another Fritzing abortion.

I have edited my code,

I was able to get the 2 sensors working, but only one sensor is controlling leds.
its all a learning curve,

i was able to get the led working by changing / renaming the "Temp" to "Temp2" in the code which i guess controls the led's

sensor 2 assigns to "Temp2" such as GetTemp

I have both sensors working as, I moved my sensor from pin 2 to 4, lights were being controlled, pin 2 was not.

so Ive further tried editing code to allow me to add 2nd thermal colour but get error

"exit status 1
'getTemp' was not declared in this scope"

i want Temp & Temp2 to be in the code.

this is the code as of now.

// 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 ...

#include "OneWire.h"
//#include "Streaming.h"

const int DS18S20a_Pin = 2; //DS18S20 Signal pin on digital 2
#define MIN_TEMP 20
#define MAX_TEMP 40

//Temperature chip i/o
OneWire ds(DS18S20a_Pin); // on digital pin 2

const int DS18S20b_Pin = 4; //DS18S20 Signal pin on digital 4
#define MIN_TEMP 20
#define MAX_TEMP 40

//Temperature chip i/o
OneWire dsb(DS18S20b_Pin); // on digital pin 4


// 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    0
#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));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED + k, OUTPUT);
    rgb[k]=0;
    analogWrite(RED + k, rgb[k] * bright[k]/256);
  }
}
//temperature1
void loop() {
  float temperature = constrain(getTemp(), MIN_TEMP, MAX_TEMP);
  
  float deltaTemp = (MAX_TEMP - MIN_TEMP);
  float deltaHue = 4 - 0;
  hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp * 100, deltaHue * 100, 0) / 100.0;
  
  //Serial << "Temperature: " << temperature << endl;
  //Serial << "HUE: " << hue << endl;
  
  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);
}
//temperature2
  float temperature = constrain(getTemp2(), MIN_TEMP, MAX_TEMP);
  
  float deltaTemp2 = (MAX_TEMP - MIN_TEMP);
  float deltaHue = 4 - 0;
  hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp2 * 100, deltaHue * 100, 0) / 100.0;
  
  //Serial << "Temperature: " << temperature << endl;
  //Serial << "HUE: " << hue << endl;
  
  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);
}


// sensor1
float getTemp(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
   //no more sensors on chain, reset search
   ds.reset_search();
   return -10;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -10;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -10;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = ds.reset();
 ds.select(addr);  
 ds.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = ds.read();
 }
 
 ds.reset_search();
 
 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
}

//2nd sensor


float getTemp2(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !dsb.search(addr)) {
   //no more sensors on chain, reset search
   dsb.reset_search();
   return -10;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -10;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -10;
 }

 dsb.reset();
 dsb.select(addr);
 dsb.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = dsb.reset();
 dsb.select(addr);  
 dsb.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = dsb.read();
 }
 
 dsb.reset_search();
 
 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
}

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);
  }
}

I tried adding temperature2 codes, i have issues here

[color=red]//temperature2
  float temperature = constrain(getTemp2(), MIN_TEMP, MAX_TEMP);
  
  float deltaTemp2 = (MAX_TEMP - MIN_TEMP);
  float deltaHue = 4 - 0;
  hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp2 * 100, deltaHue * 100, 0) / 100.0;
  
  //Serial << "Temperature: " << temperature << endl;
  //Serial << "HUE: " << hue << endl;
  
  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);
}

[/color]

the next I added sensor2 code which works

//2nd sensor

float getTemp2(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !dsb.search(addr)) {
   //no more sensors on chain, reset search
   dsb.reset_search();
   return -10;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -10;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -10;
 }

 dsb.reset();
 dsb.select(addr);
 dsb.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = dsb.reset();
 dsb.select(addr);  
 dsb.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = dsb.read();
 }
 
 dsb.reset_search();
 
 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
}[/color]

'getTemp' was not declared in this scope"

This is because you do not have matching braces in the loop function so the compiler never sees the getTemp definition.

If you place the cursor on an opening brace and click, you will see the matching brace highlighted. Do this on the opening brace of the loop function definition and it will match just after the commented out delay call. This leaves the rest of your function hanging. Remove this brace and then you will get a different error message telling you that you are trying to use the same name ( which is temperature ) for a variable that has already been defined. Correct that and it will tell you about the variable deltaHue ..... Remember also to change the names of the variables after that so the new value is actually used in the code.

You can not have two variables with the same name in the same piece of code. This is because the computer would not know which one to choose to take the value from or where to put the value.

The same goes for writing to the LEDs each section is writing to the same LED.

Different variables must have different names. You have been told about this once already in this thread.

Also:-

rgb[0] = (rgbval & 0x00FF0000) >> 16; // there must be better ways

No there aren't better ways, that is the way to do it.

thats it for me tonight,

I seem to have both sensors and led strings working

sensor on pin 2 with leds pwm 9,10,11 are fading as normal through the temperatures

sensor on pin 4 with leds pwm 3,5,6 are going bonkers when the temperature changes
when cold or hot leds look good, when the sensor changes to around 40 degrees c colours blink rapidly..

can you look at my code to see where the problem is

ty

// 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 ...

#include "OneWire.h"
//#include "Streaming.h"

const int DS18S20a_Pin = 2; //DS18S20 Signal pin on digital 2
#define MIN_TEMP 20
#define MAX_TEMP 40

//Temperature chip i/o
OneWire ds(DS18S20a_Pin); // on digital pin 2

const int DS18S20b_Pin = 4; //DS18S20 Signal pin on digital 4
#define MIN_TEMP2 20
#define MAX_TEMP2 40

//Temperature chip i/o
OneWire dsb(DS18S20b_Pin); // on digital pin 4


// don't futz with these, illicit sums later
#define RED       9// pin for red LED
#define RED2       3// pin for red LED
#define GREEN    10 // pin for green - never explicitly referenced
#define GREEN2    5 // pin for green - never explicitly referenced
#define BLUE     11 // pin for blue - never explicitly referenced
#define BLUE2     6 // pin for blue - never explicitly referenced
#define SIZE    255
#define SIZE2    255
#define DELAY    0
#define DELAY2    0
#define HUE_MAX  6.0
#define HUE2_MAX  6.0
#define HUE_DELTA 0.01
#define HUE2_DELTA 0.01
//long deltas[3] = { 5, 6, 7 };
long rgb[3];
long rgb2[3];
long rgbval;
long rgbval2;
// 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;
float hue2=0.0, saturation2=1, value2=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 bright2[3] = { 107, 67, 256};
//long bright[3] = { 256, 256, 256};

long k, temp_value;

void setup () {
  randomSeed(analogRead(4));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED + k, OUTPUT);
    rgb[k]=0;
    analogWrite(RED + k, rgb[k] * bright[k]/256);
  }
  randomSeed(analogRead(4));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED2 + k, OUTPUT);
    rgb2[k]=0;
    analogWrite(RED2 + k, rgb2[k] * bright2[k]/256);
  }
}
//temperature1
void loop() {
  float temperature = constrain(getTemp(), MIN_TEMP, MAX_TEMP);
  float temperature2 = constrain(getTemp2(), MIN_TEMP2, MAX_TEMP2);
  float deltaTemp = (MAX_TEMP - MIN_TEMP);
  float deltaTemp2 = (MAX_TEMP2 - MIN_TEMP2);
  float deltaHue = 4 - 0;
  float deltaHue2 = 4 - 0;
  hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp * 100, deltaHue * 100, 0) / 100.0;
  hue2 = map((temperature2 - MIN_TEMP2) * 100, 0, deltaTemp2 * 100, deltaHue2 * 100, 0) / 100.0;
  //Serial << "Temperature: " << temperature << endl;
  //Serial << "HUE: " << hue << endl;
  rgbval=HSV_to_RGB(hue, saturation, value);
  rgbval2=HSV_to_RGB2(hue2, saturation2, value2);
  
  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);}

  rgb2[0] = (rgbval2 & 0x00FF0000) >> 16; // there must be better ways
  rgb2[1] = (rgbval2 & 0x0000FF00) >> 8;
  rgb2[2] = rgbval2 & 0x000000FF;
   for (k=0; k<3; k++) { // for all three colours
    analogWrite(RED2 + k, rgb2[k] * bright2[k]/256);
    
  }
    //delay(DELAY);

}

// sensor1
float getTemp(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
   //no more sensors on chain, reset search
   ds.reset_search();
   return -10;
 }
 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -10;
 }
 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -10;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = ds.reset();
 ds.select(addr);  
 ds.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = ds.read();
 }
 
 ds.reset_search();
 
 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
}

//2nd sensor

float getTemp2(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !dsb.search(addr)) {
   //no more sensors on chain, reset search
   dsb.reset_search();
   return -10;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -10;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -10;
 }

 dsb.reset();
 dsb.select(addr);
 dsb.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = dsb.reset();
 dsb.select(addr);  
 dsb.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = dsb.read();
 }
 
 dsb.reset_search();
 
 byte MSB2 = data[1];
 byte LSB2 = data[0];

 float temp2Read = ((MSB2 << 8) | LSB2); //using two's compliment
 float Temperature2Sum = temp2Read / 16;
 
 return Temperature2Sum;
}

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);
  }
}

long HSV_to_RGB2( 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);
  }
}

OK well done so far.

That is a very odd way to access the 1 wire bus by searching for a device every time you want to take a reading. The normal way is to search the bus and build up a list of device's addresses on the bus, this is normally done in the setup function and then just use the address of the device you want.

You are trying to do too much at once. The secret to a project is to test one step at a time. So you would normally test the two temperature sensors first and make sure the correct readings are being read. Use the Serial.print command to see what values you have at various points in your program.

You still haven't got the thing about functions. The functions HSV_to_RGB and HSV_to_RGB2 are identical, they only react to values passed into them, and they return values back to the calling function. Therefore there is no need to have two functions at all here, just one will do.

sensor on pin 2 with leds pwm 9,10,11 are fading as normal ........
sensor on pin 4 with leds pwm 3,5,6 are going bonkers

Look at your code that addresses these:-

for (k=0; k<3; k++) { // for all three colours
    analogWrite(RED + k, rgb[k] * bright[k]/256);}

With the variable RED being 9, then RED + k will generate the pin numbers 9, 10, & 11 - the three PWM pins.
However:-

 for (k=0; k<3; k++) { // for all three colours
    analogWrite(RED2 + k, rgb2[k] * bright2[k]/256);

With the variable RED2 being 3, then RED + k will generate the pin numbers 3, 4, & 5 - which is only two of the PWM pins you want and the green LEDs are being fed the values for the blue ones. - Bonkers indeed.

The lines:-

#define GREEN    10 // pin for green - never explicitly referenced
#define GREEN2    5 // pin for green - never explicitly referenced
#define BLUE     11 // pin for blue - never explicitly referenced
#define BLUE2     6 // pin for blue - never explicitly referenced

Are actually doing absolutely nothing and in the context of this code are totally meaningless.

Cool, it's all a learning curve..

So the part you mentioned about the pwm pins it seems It is outputting to pins 345
Where as I need 356

Can I ask what is going on with these lines,

for (k=0; k<3; k++) {

pinMode(RED + k, OUTPUT);

rgb[k]=0;

analogWrite(RED + k, rgb[k] * bright[k]/256);

What does it all mean. How does Red and Red2 =3?
What is k=0, k<3, and k++

I didn't write any of this code I am very noob at codes and don't understand much about it.
I am starting to get a feel about how it takes info from one place, creates values via special names...

I am thinking that to solve the 3,5,6 pins
I need to either reference Red2 at pin 3 making k=1, then adding Blue2 at pin 5 and make k =2
Or
Is there a simpler method making k =3 but skip pin 4?
Is that the ++ part?
Would I do k-++ or something?

I know eventually I will make it run 2 LEDs per sensor.. But for now.. 1 step at a time and I'm finding this project overwhelming but none the less, very interesting indeed..

void setup () {
  randomSeed(analogRead(4));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED + k, OUTPUT);
    rgb[k]=0;
    analogWrite(RED + k, rgb[k] * bright[k]/256);
  }
  randomSeed(analogRead(4));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED2 + k, OUTPUT);
    rgb2[k]=0;
    analogWrite(RED2 + k, rgb2[k] * bright2[k]/256);
  }
}

You also mentioned that my sensors code is doing too much,

Do you mean I should just apply values next to each other such as, (as some values are doubled up this allows me to erase some code)

Should it be like this? An example

// sensor1 and 2
float getTemp(){
float getTemp2(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
   //no more sensors on chain, reset search
   ds.reset_search();
   return -10;
 }
 if ( !dsb.search(addr)) {
   //no more sensors on chain, reset search
   dsb.reset_search();
   return -10;
 }
 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -10;
 }
 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -10;
 }
 ds.reset();
dsb.reset();
ect(addr);
 ds.write(0x44,1); // start conversion, with parasite power on at the end
dsb.write(0x44,1);

Thx so much for help thus far

Ps, the serial.print
It that all I type? Into serial monitor. Or does my code need that implemented in the main code?

You also mentioned that my sensors code is doing too much,

No I didn't say that. I said there was not much difference in the two functions and that you were using two instances of the one wire bus when both sensors could have been put on the same wire. But given your delicate state of knowledge at the moment just leave that.

Should it be like this? An example

Sorry no, totally wrong.

for (k=0; k<3; k++) {

This starts a for loop
https://www.arduino.cc/en/Reference/For
It will go through the code in between the braces many times. The first time the variable k will be equal to 0, at the end of the code in the braces the k++ means the value of k is incremented to one and the code will go again because of the test is k < 3, with a value of one it is true. Next time k will be incremented again to a value of two. Again the code is repeated because k < 3. Next time k is incremented to a value of 3. This time k is not < 3 so the loop stops and the code after the braces starts running.
So each time round the loop k is a different value. So RED + k, will be different each time round the loop. With an initial value of 9, the result of RED + k, will be 9, 10, & 11 for each pass of the code and so will address a different pin.

Now you might think this is pretty clever code, but in fact it is very stupid code, because it will only address pins that are in a consecutive sequence. If you try and access pins that are not sequential the trick won't work as you have found. Unfortunately the solution involves more complex code using an array to hold the pin numbers, and accessing the actual numbers with the loop index (what we call k ).
https://www.arduino.cc/en/Reference/Array

At the start of the code define an array:-
int secondPins [] = { 3,5,6};
Then in that second loop use:-

analogWrite(secondPins[k], rgb[k] * bright[k]/256);

damn, i burnt my arduino.. so no more on the fly testing...

a question, before it fried, i had no more bonkers flashing but only 2 of the 3 colours would fade so seems one of the pwm pin didn't work, i also moved sensor out of pin 4 and put to pin 8, maybe this stopped flashing bonkers

also
i see in my code I have two codes which repeat and its the one you told me to replace...

see top and bottom of pasted code, (analog write)

void setup () {
  randomSeed(analogRead(4));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED + k, OUTPUT);
    rgb[k]=0;
    analogWrite(RED + k, rgb[k] * bright[k]/256);
  }
  randomSeed(analogRead(4));
  Serial.begin(57600);
  for (k=0; k<3; k++) {
    pinMode(RED2 + k, OUTPUT);
    rgb[k]=0;
    analogWrite(secondPins[k], rgb[k] * bright[k]/256);
  }
}
//temperature1
void loop() {
  float temperature = constrain(getTemp(), MIN_TEMP, MAX_TEMP);
  float temperature2 = constrain(getTemp2(), MIN_TEMP2, MAX_TEMP2);
  float deltaTemp = (MAX_TEMP - MIN_TEMP);
  float deltaTemp2 = (MAX_TEMP2 - MIN_TEMP2);
  float deltaHue = 4 - 0;
  float deltaHue2 = 4 - 0;
  hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp * 100, deltaHue * 100, 0) / 100.0;
  hue2 = map((temperature2 - MIN_TEMP2) * 100, 0, deltaTemp2 * 100, deltaHue2 * 100, 0) / 100.0;
  //Serial << "Temperature: " << temperature << endl;
  //Serial << "HUE: " << hue << endl;
  rgbval=HSV_to_RGB(hue, saturation, value);
  rgbval2=HSV_to_RGB2(hue2, saturation2, value2);
  
  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);}

  rgb2[0] = (rgbval2 & 0x00FF0000) >> 16; // there must be better ways
  rgb2[1] = (rgbval2 & 0x0000FF00) >> 8;
  rgb2[2] = rgbval2 & 0x000000FF;
   for (k=0; k<3; k++) { // for all three colours
    analogWrite(RED2 + k, rgb2[k] * bright2[k]/256);

as for replacing the code, i tried it a few ways with same results 2 of 3 colours.. fade, no more flashing... tho might be because i moved sensor 4 to pin 8!?

i also put the int line at start of my code, also tried adding before brace in this setup loop
was i suppose to delete other lines?
randomSeed(analogRead(4));
Serial.begin(57600);
for (k=0; k<3; k++) {
pinMode(RED2 + k, OUTPUT);
rgb[k]=0;
analogWrite(secondPins[k], rgb[k] * bright[k]/256);
}

Yes everywhere where you had RED2 + k you replace with secondPins[k] otherwise you get the wrong pins.

Hello sorry for leaving my project for so long, but I would still like some help with it,

So I have received my new boards as the last one shorted out..

anyways
I have got it to run 2 LED Strips independently.. and I am most pleased.
using 3 pwm for each LED strip. and 1 analogue input for sensor.

Now I wish to play with colouring and limit blue to red, It's possible I might wish to add some orange, but only if the blue to red does not please me.

It would be nice to run 3 LED Strips (RED/Blue) from 1 arduino board.

I dont know where to begin with this.. I have looked into tutorials driving LED Strips but it's always RGB.

Can I simply remove green's digital pin and remove it from code?

I have been looking here, and see the code seems straight forward..
I cannot even tell where my colouring code is in my code..
I did copy the code from someone else

I also found this code online and see the colour is easier to navigate.
this code supposingly does the same as my project... Sweeps colours BLUE-RED via a thermal probe..
tho there was No diagrams for wiring.. I don't know how to make it work

It would be nice to use this code as I think I can experiment with colours alot more..
I dislike the green in my code..
this code seems to ignore green... and use the green led to make orange which looks nice

/********************************
Author: Ethan Frei
Date: On 7/11/11
Desc: Changes a RGB LED gradually
  to match the surrounding temperature.
  Blue -> Red = Cool -> Hot.
Legal: Use whatever you want to! 
  Could probably use optimization!
********************************/

byte tempPin = A0;
byte rPin = 2;
byte gPin = 3;
byte bPin = 4;

byte colorTempMap[6][3] = {{  0, 255, 255},    //light blue
                         {  0, 125, 255},      //less light blue
                         {  0,   0, 255},      //blue
                         {255, 255,   0},      //yellow
                         {255, 125,   0},      //orange
                         {255,   0,   0}};     //red
                         
byte currentColor[3];
byte newCurrentColor = 0;
float newTemp;

void setup () {
  pinMode(A1, OUTPUT);
  analogReference(INTERNAL1V1);
  outputColor(colorTempMap[0]);
  currentColor[0] = colorTempMap[0][0];
  currentColor[1] = colorTempMap[0][1];
  currentColor[2] = colorTempMap[0][2];
  newTemp = (float)analogRead(tempPin) * .193548387 - 58;
}

void loop () {
  newTemp = (float)analogRead(tempPin) * .193548387 - 58;
  newTemp = newTemp < 78 ? 78 : newTemp;
  newTemp = newTemp > 88 ? 88 : newTemp;
  newCurrentColor = map(newTemp, 78, 88, 0, 5);
  changeColors();
  delay(15);
}

void changeColors() {    
    for(int i = 0; i < 3; i++){
      if(currentColor[i] != colorTempMap[newCurrentColor][i])  
      currentColor[i] = currentColor[i] < colorTempMap[newCurrentColor][i] ? currentColor[i] + 1 : currentColor[i] - 1;
    }
    outputColor(currentColor);
}

void outputColor(byte currentRGB[]){
  analogWrite(rPin, currentRGB[0]);
  analogWrite(gPin, currentRGB[1]);
  analogWrite(bPin, currentRGB[2]);
}

Can I have some advice on where to go next.
Should I use this other code as it looks much more simple?

As nice it would be running 3 LED's from 1 board.. the orange might be the only thing to stop me from having 3 led strings on a single board

and Lastly,
Will it be simple enough to change sensor type on my project's code?
as these ONEWIRE sensors are very bulky!

Many Thanks