Comparing the values of 6 DS18B20's with RGB LED output for min temperature.

Hello, I am new to coding and really a novice in all sense of the word when it comes to my experience with Arduino, nevertheless, here I am. I am currently working on a little project which involves measuring the temperature change across the surface of a metal cylinder containing a fluid under pressure. The temperature sensors six (block type ds18b20s) will measure the surface temperature of the cylinder across the length of the cylinder (vertically attached to the side of the cylinder), with each temperature sensor, measuring a particular zone of the cylinder (oriented vertical and numbered 1-5 from top to bottom). Sensor 6 measures ambient temperature for reference via comparison.
So the programme really is to compare all the temperature sensor values (1-6) against each other and find the lowest reading. Each DS18B20 temperature sensor is then associated with a particular colour of LED depending on their placement on the device . Temperature Sensor 1 at the top is associated with blue LED , Tsensor 2 with green, Tsensor 3 and Tsensor 4 with amber colour and Sensor 5 with red. As the volume of the fluid in the cylinder changes the temperature distribution across the cylinder body changes. Any way, I have been able to connect all the DS18B20 sensors and get readings from all of them when connected to an Arduino uno board, as well as successful connected a RGB module (KY-016) to the Arduino. to achieve the above stated desired outcome, I wrote the following sketch, which doesn’t work for some reason (I know why, it’s wrong and full of errors). I have omitted the code for finding the addresses of the 6 ds18b20 sensors.I considered putting the sensor outputs in an array and then selecting for minimum sensor output value in Celsius, but after reading several DS18B20 projects, went for the if/else statement route (disclaimer, I have no experience with this as well). I get the error message at the bottom of the pasted sketch. I have looked online, read/watched tutorials, gone through several comment sections and played with different and increasingly bizarre variations of the code. Can anyone point me in the right direction on how to get what I am trying to achieve, and also point out the multiple errors in my code. Thanks

#include <DallasTemperature.h>

#include <OneWire.h>
int min;
int i;

const int redPin = 8;
const int greenPin = 10;
const int bluePin = 12;

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Addresses of 6 DS18B20s
uint8_t sensor1[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x46, 0x32, 0xBD };
uint8_t sensor2[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x5E, 0x12, 0x04 };
uint8_t sensor3[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x5E, 0xDB, 0x52 };
uint8_t sensor4[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x3D, 0xA2, 0x39 };
uint8_t sensor5[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x23, 0x54, 0xA0 };
uint8_t sensor6[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x23, 0xEC, 0x50 };

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
}

void loop(void)
{
  sensors.requestTemperatures();
  
  Serial.print("Sensor 1: ");
  printTemperature(sensor1);
  
  Serial.print("Sensor 2: ");
  printTemperature(sensor2);
  
  Serial.print("Sensor 3: ");
  printTemperature(sensor3);

  Serial.print("Sensor 4: ");
  printTemperature(sensor4);

  Serial.print("Sensor 5: ");
  printTemperature(sensor5);

  Serial.print("Sensor 6: ");
  printTemperature(sensor6);
  
  Serial.println();
  delay(1000);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
  Serial.print((char)176);
  Serial.print("C  |  ");
}
int k=0;                                                                                                

//get the values from the DS8B20's  
  
  //Sensors for logic

if (sensor6 <= sensor1) && (sensor6 <= sensor5) { // analogWrite(redPin) 
else if (sensor1 < sensor2) && (sensor1 < sensor3) && (sensor1 < sensor4) && (sensor1 < sensor5) { // analogWrite(bluePin)
// cylinder is full}
else if (sensor2 < sensor3) { // analogWrite(greenpin) 
//cylinder is more than half full  }

else if (sensor3 < sensor4) { // analogWrite(RGB_color(255, 255, 0); // Yellow)
 //cylinder is less than half full  }
 
else if (sensor4 < sensor5) { // analogWrite(RGB_color(255, 255, 125); // Raspberry)
//cylinder is almost empty  }
  
  
Arduino: 1.8.12 (Mac OS X), Board: "Arduino Uno"

sketch_nov13b_test_code_1a_:75:1: error: expected unqualified-id before 'if'
 if (sensor6 <= sensor1) && (sensor6 <= sensor5) { // analogWrite(redPin)
 ^~
exit status 1
expected unqualified-id before 'if'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You can’t compare arrays like that.

You want to compare readings from those sensors, not their addresses.

Take a look at the examples that came with the Dallas library

I did not go down the array route (I think), and yes I do want to compare the sensor readings - so I floated the readings (which is why I included their addresses of the sensors to help in this instance)- to help with the comparison of sensor readings. Is there a way of going about this without floating the sensor readings?

teeco31:
Is there a way of going about this without floating the sensor readings?

No. You need to get the readings from the sensors and compare them. Currently you're trying to compare the addresses of the sensors.

Ok, so I couldn’t translate the advice on comparing the addresses instead of the sensors temperature reading from my code, as it is rather tricky with DS18B20’s onewire protocol- as you have to access the sensors addresses. Anyway, I decided to go another route; by creating an array and setting a minimum temp as an int , to compare sensor readings against, with specific RGB LEDs as output for different sensors returning the lowest reading. I have however come across another obstacle using this, the program doesn’t cycle through the *else if *statements after it does the initial IF (even in conditions for the first IF are not met in the first place). What I’m left with is the LED staying BLUE, evening when I hold my fingers over sensors 1 and 2 and the print shows both sensors reading higher than the others. Anyway, Can anyone help with this?

Thanks

#include <OneWire.h>
#include <DallasTemperature.h>


int red = 8;
int green = 10;
int blue = 12;


// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2


// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);



// Temperature sensor full ID Addresses of 6 DS18B20s
uint8_t sensor1[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x46, 0x32, 0xBD };
uint8_t sensor2[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x5E, 0x12, 0x04 };
uint8_t sensor3[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x5E, 0xDB, 0x52 };
uint8_t sensor4[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x3D, 0xA2, 0x39 };
uint8_t sensor5[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x23, 0x54, 0xA0 };
uint8_t sensor6[8] = { 0x28, 0xFF, 0x64, 0x19, 0xD7, 0x23, 0xEC, 0x50 };

int sensorsReadings[6] = {sensor1[8], sensor2[8], sensor3[8], sensor4[8], sensor5[8], sensor6[8] };
int count = sizeof(sensorsReadings) / sizeof(sensorsReadings[0]);
int lowestTempValue = count;



void setup(void)
{
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  
  Serial.begin(9600) ;
  sensors.begin() ;
  sensors.requestTemperatures();
  int i = 0; i < count; i++;
  

   if(sensorsReadings[i] < lowestTempValue);
    lowestTempValue = sensorsReadings[i];
    lowestTempValue = i;
   sensors.requestTemperatures();
 

  Serial.print("Sensor 1: ");
  printTemperature(sensor1);
  
  Serial.print("Sensor 2: ");
  printTemperature(sensor2);
  
  Serial.print("Sensor 3: ");
  printTemperature(sensor3);

  Serial.print("Sensor 4: ");
  printTemperature(sensor4);

  Serial.print("Sensor 5: ");
  printTemperature(sensor5);

  Serial.print("Sensor 6: ");
  printTemperature(sensor6);
  
  Serial.println();
  delay(1000);
 }


 void printTemperature(DeviceAddress deviceAddress)
 {
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
  Serial.print((char)176);
  Serial.print("C  |  ");
  Serial.print(lowestTempValue); 
  
   
  }
  
 void loop(void)
 {
   if (sensor1[8] = lowestTempValue) {digitalWrite(blue, HIGH),(green, LOW),(red, LOW);
   } else if (sensor2[8] = lowestTempValue) {digitalWrite(blue, HIGH),(green, LOW),(red, LOW);
   } else if (sensor3[8] = lowestTempValue) {digitalWrite(green, HIGH),(blue, LOW),(red, LOW);
   } else if (sensor4[8] = lowestTempValue) {digitalWrite(green, HIGH),(blue, LOW),(red, LOW);
   } else if (sensor5[8] = lowestTempValue) {digitalWrite(red, HIGH),(blue, LOW),(green, LOW);
   } else if (sensor6[8] = lowestTempValue) {digitalWrite(red, HIGH),(blue, LOW),(green, LOW);
   {
  
  

   void printTemperature(DeviceAddress deviceAddress);
   }
   }
 }
int i = 0; i < count; i++;

Oops.

Also, to compare two values,use “==”, not “=”

Also, newlines don’t cost anything.

if (sensor1[8] = lowestTempValue)

Three things here:
sensor1 is an eight element array; there is no index 8.
“==” not “=” as noted above
You should be comparing the reading, not the address

void printTemperature(DeviceAddress deviceAddress);
   }
   }
 }

This is no place for a function prototype

Thanks for the feedback, and pointing out the errors, especially (= , and ==) super rookie error on my part here. May I please ask that provide some clarity on the following;

  1. What am I doing wrong here?
int i = 0; i < count; i++;
  1. “You should be comparing the readings not the address” I haven’t got a clue what you mean here in the sketch. I have read so much over the last few days, and looked up related DS18B20’s examples in the forum, and I am still none the wiser.

Much Appreciated

teeco31:

  1. What am I doing wrong here?
int i = 0; i < count; i++;

I see the parameters for a ‘for’ statement, without any ‘for’ statement.

Have you looked at any of the examples provided with the DallasTemperature library?

I’m pretty sure there’s one to read multiple sensors, either by a provided address, or by index.

I have been reading this thread to better understand the DS18B20 sensor myself. I think the original poster is asking the question 'rather than comparing the addresses, which variable represents the measured temperature'?
Is it 'tempC'?
In which case shouldn't the OP be assigning 'tempC' to a unique variable for each sensor, then his comparator function would work better?