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'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
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
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
}
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.