DS18B20 sensors with SSR

Hello,

I’ve been working to compile a simple code in Arduino IDE to interface between a kegerator, SSR, 2 DS18B20 sensors, and an arduino uno. I’ve been homebrewing for almost a year and decided I’d like to have a more temperature controlled environment to progress my brewing passion. The kegerator serves as the box to place the fermentor in while the SSR is patched into the power cable (its rated for 24A which is more than enough). The SSR is then tied into the arduino through a digital pin and ground wire. The two temp. sensors I have wired through one digital pin using OneWire which should trigger the SSR to turn “off and on” based on different integer thresholds I have placed in if statements. Several LEDs are placed to give me temp range indicators without having the live feed up on my laptop.

Problem: I believe the data coming from my sensors is in a different data type than the integers I am defining in the if statements. I am looking for a way to successfully match the data types so the sensors can interface correctly. I have looked at many other forums and tried to alter the data type from the sensors but with no avail.

Results thus far: The SSR and temp sensors are all wired correctly through my breadboard with the proper resistors. The SSR can properly control the power when coded alone and the temp sensors are taking accurate measurements when used independently of the SSR. The kegerator also works fine.

This is my first time posting so I apologize in advance for forum syntax/proper use errors.

I used the following as my base code and added the simple if statements myself:
http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20

The code is attached but I’ll list it here below as well:

/* YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
 Connections:
 DS18B20 Pinout (Left to Right, pins down, flat side toward you)
 - Left   = Ground
 - Center = Signal (Pin 2):  (with 3.3K to 4.7K resistor to +5 or 3.3 )
 - Right  = +5 or +3.3 V

  Questions: terry@yourduino.com 
  V1.01  01/17/2013 ...based on examples from Rik Kretzinger
  
/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>

//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2
#define CHANNEL 11
#define LED_fridge 10
#define LED_frange 9
#define LED_wrange 8

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

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

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0xFF, 0x5E, 0x17, 0x20, 0x16, 0x04, 0x72 }; 
DeviceAddress Probe02 = { 0x28, 0xFF, 0x97, 0xE9, 0x00, 0x16, 0x04, 0x53 };

void setup()   /****** SETUP: RUNS ONCE ******/
{
 // start serial port to show results
 Serial.begin(9600);
  pinMode(CHANNEL, OUTPUT);
  pinMode(LED_fridge, OUTPUT);
  pinMode(LED_frange, OUTPUT);
  pinMode(LED_wrange, OUTPUT);
 //Serial.print("Initializing Temperature Control Library Version ");
 //Serial.println(DALLASTEMPLIBVERSION);
 
 // Initialize the Temperature measurement library
 sensors.begin();
 
 // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
 sensors.setResolution(Probe01, 10);
 sensors.setResolution(Probe02, 10);
 
}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
 delay(1000);                                                                          //SETS DELAY TIME: 300000 = 5 min, 600000 = 10 min
 //Serial.println();
 //Serial.print("Number of Devices found on bus = ");  
 //Serial.println(sensors.getDeviceCount());   
 //Serial.print("Getting temperatures... ");  
 //Serial.println();   
 
 // Command all devices on bus to read temperature  
 sensors.requestTemperatures();  
 
 Serial.print("Probe 01 temperature is:   ");
 printTemperature(Probe01);
 Serial.println();

 Serial.print("Probe 02 temperature is:   ");
 printTemperature(Probe02);
 Serial.println();

    if ((*Probe01) >= 70 && (*Probe01) <= 80)   //Probe01 = wort temp sensor
{
 digitalWrite(LED_wrange, HIGH);//pin8
}
else
{
 digitalWrite(LED_wrange, LOW);//pin8
}

if ((*Probe01) > 75)                 
{
 digitalWrite(CHANNEL, HIGH);
 digitalWrite(LED_fridge, HIGH); //pin10
}
else
{
 digitalWrite(CHANNEL, LOW);
 digitalWrite(LED_fridge, LOW); //pin10
}

if ((*Probe02) < (*Probe01))                  //Probe02 = ambient temp sensor
{
 digitalWrite(LED_frange, HIGH); //pin9
}
else
{
 digitalWrite(LED_frange, LOW);//pin9
}
 
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

  if (tempC == -127.00) 
  {
  Serial.print("Error getting temperature  ");
  } 
  else
  {
  //Serial.print("C: ");
  //Serial.print(tempC);
  Serial.print(" F: ");
  Serial.print(DallasTemperature::toFahrenheit(tempC));
 
  }

}// End printTemperature
//*********( THE END )***********

arduino_help.ino (3.63 KB)

Please edit your post to add code tags ("</>" button).

jremington:
Please edit your post to add code tags ("</>" button).

Added the code tags!

Thanks.

This is incorrect. “Probe01” is not a pointer to a temperature.

    if ((*Probe01) >= 70 && (*Probe01) <= 80)   //Probe01 = wort temp sensor

To learn how to access the temperature value, consult the tutorial linked in the code you posted.

I consulted the tutorial but it seems that it only shows how to display the input data but not how to utilize it.

What would be the correct way to write the line that you highlighted?

If I try:

if (Probe01 >= 70 && Probe01 <= 80)

then I get an error message:

ISO C++ forbids comparison between pointer and integer [-fpermissive]

      if (Probe01 >= 70 && Probe01 <= 80)

You must be looking in the wrong place. Here is the code from that tutorial, which shows how to get and print the temperature in C and F.

Note especially the following line in the code below:

  float tempC = sensors.getTempC(deviceAddress);

Code from Hacktronix tutorial:

//  This Arduino sketch reads DS18B20 "1-Wire" digital
//  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  Tutorial:
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

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

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

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

// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  sensors.setResolution(dogHouseThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
 
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
  Serial.print("Outside temperature is: ");
  printTemperature(outsideThermometer);
  Serial.print("\n\r");
  Serial.print("Dog House temperature is: ");
  printTemperature(dogHouseThermometer);
  Serial.print("\n\r\n\r");
}

Thank you! I was able to use “tempC” to power on/off the SSR based on a threshold value.

However, how would I distinguish between multiple sensors on the same digital input/bus pin?

However, how would I distinguish between multiple sensors on the same digital input/bus pin?

More study of the example is in order!

Thank you for all your help. I'm sure I'll be able to progress from here with a little tinkering!