18b20 and servo controlling tap

I have an Arduino Uno (kit) that I bought myself for Christmas.

I bought a Dallas 18b20 and a 4k7 resistor of which I can confirm is working.

The aim is to control a servo to adjust a tap based on temperature to keep water output to within 2-3 degrees of required temperature.

This is what got me started Water Temperature Regulator using Arduino - YouTube

I have tried some code based on the LM335, but i could not calibrate the LM335 i had hence i bought a 18b20.

I have merged some code and at this stage I am stuck.

Any help is appreciated.

Russell.

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


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

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int thresholdcold = 25; // Threshold for cold temperature
int thresholdhot = 30; // Threshold for hot temperature
int thresholdnormal = 28; // Threshold for normal temperature
int servocold = 179; // Angle in which servo will go to
int servohot = 0; // Angle in which servo will go to
int servonormal = 89;  // Angle in which servo will go to
int previousPosition = 0;
Servo servo1;

void setup(void)
{
  // Start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  servo1.attach(3); // Attaches servo to specified pin
 
}

void loop()
{
 sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.print(Temperatures); // Print out the temperature
  Serial.println("degrees C"); // Print out "degrees C" to indicate value is in degrees celcius
 
 
  if(Temperatures < thresholdcold) // If temperature is above the threshold, activate sequence
  {
    	if (servocold != previousPosition){
	    servo1.write(servocold);
		previousPosition = servocold;
		}
  }
 
  else if(Temperatures > thresholdhot) // If temperature is above the threshold, activate sequence
  {
    		if (servohot != previousPosition){
	    servo1.write(servohot);
		previousPosition = servohot;
		}
  }
 
  else if(Temperatures >= thresholdnormal) // If temperature is above the threshold, activate sequence
  {
    
	if (servonormal != previousPosition){
	    servo1.write(servonormal);
		previousPosition = servonormal;
		}
  }
 
  delay(1000);
 
}

I am stuck.

What with ?
What happens that shouldn't happen and what happens that should ?

I get an error in

In functionvoid loop():
Temperatures was not declared in this scope

Thank you,'

Russell

I'm not familiar with that library but you are clearly trying to use a variable called "Temperatures" that you have not defined at the top of your program.

In addition you are trying to print a value from a (non-existent) variable that has never had a variable put into it.

sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.print(Temperatures); // Print out the temperature

I wonder should this code be something like the following (assuming you have int Temperatures = 0; at the top of the program) ? And while it will work OK, it is not normal practice to have capitals at the start of variable names.

Temperatures = sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.print(Temperatures); // Print out the temperature

...R

It seems to me that

sensors.requestTemperatures(); // Send the command to get temperatures

is probably requesting the temperature but is not doing anything with the value returned, but that is a guess because I am not familiar with the library.

Try

float Temperatures = sensors.requestTemperatures();
Serial.print(Temperatures); // Print out the temperature

or

Serial.print(sensors.requestTemperatures());

requestTemperatures issues a request to all sensors on the bus to read the temperature - they only do it on request. You then need to get the temperature from whichever of them you're interested in.

Consider this example from the library page:

void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
 
Serial.print("Temperature for Device 1 is: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
}

@wildbill's expertise to the rescue ...

I had intended to say earlier that I have no trouble using an LM335. However one issue that may be relevant for your application is the speed of response to temperature changes. The LM335 is nowhere near as fast as a thermocouple. I would be worried that the water could reach a dangerous (or uncomfortably low) temperature in the time it would take an LM335 to respond.

I don't know whether the Dallas device responds more quickly than the LM335.

It would be useful to have a thermocouple thermometer for verifying the action of your project. I have one that came with a cheap digital multimeter.

...R

I spent many hours with the LM335 but was not happy with the output hence the change to the Dallas.

Thank you for your replies. I will put them into practice today.

Russell.

Ok, all additions help to read the temp from the Dallas, of which i have no problems with.

It seems I need help with the control of the servo based on temperature that is being output and written.

Lets say the hotter the temp the more the tap is open by the servo and the colder the temp the less the tap is open by the servo.

Tap open / temperature hot = servo @0 and tap closed / temperature cold = servo @179.

Any help is appreciated.

Thank you,

Russell.

Ok, I have been able to modify the code from here do do what I need.

http://forum.arduino.cc/index.php?topic=238143.5

Link referenced based on subject 18b20.

Russell.