Hi Chris,
A thermiser is not a very good temp sensor, use the DS18b20 you can use 2 or more on the same WIRE line, no problem.
Here's the code for my propagator system, this checks the light level (What's the point in keeping plants warm in the dark?) and adjust the target temp, this temp is then maintained via relay etc.
Just might give you an idea or two, regards. I have a schematic if needed.
Mel.
#include <FastIO.h>
#include <I2CIO.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// DS18b20 Data line is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12
// 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);
/*
Connections:
Heater1 pin 3
Heater2 pin 4
SDA to Arduino Analog pin 4
SCL to Arduino Analog pin 5
LightPin Analog pin A7
TempPin pin 12
*/
#define DS1307_I2C_ADDRESS 0x68
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); // Set the LCD I2C address
//*****constants*****
int Light,LightPin=A7,TargetTemp,Heater1=3,Heater2=4,TempPin=12;
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
float TEMP;
void setup()
//----------------Start of Set up---------------------
{
TargetTemp=23; //Set Normal/Target temp to 23c
pinMode(Heater1,OUTPUT);
pinMode(Heater2,OUTPUT);
pinMode(13,OUTPUT);
Wire.begin();
lcd.begin(20,4); // tells Arduino the LCD dimensions
// start serial port
Serial.begin(9600);
//Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
}
//------------End of Setup loop------------------------
//--------------Start of Main loop------------------
void loop()
{
GetTime();
GetTemp();
TestIt();
digitalWrite(13,HIGH); //Flash LED
delay(100); //For 100mS
digitalWrite(13,LOW); //LED off
}
//------------End of main loop-----------------------------
void GetTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
//if (second <=5)
{
//lcd.clear(); // clear LCD screen
lcd.setCursor(0,0);
lcd.print(" ");
lcd.print(hour, DEC);
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.print(" ");
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print("20");
lcd.print(year, DEC);
//delay(1000);
}
}
//------------------------------------------------------------------------------------------
void GetTemp()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
TEMP=(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
}
//-----------------------------------------------------------------------------------------------------------
void TestIt()
{
Light=analogRead(LightPin);
Light=Light/4;
if(Light>200)
{TargetTemp=25;}
if(Light>160 && Light<200)
{TargetTemp=18;}
if(Light<160)
{TargetTemp=14;}
// Set Temp******
lcd.setCursor(1,1);
lcd.print("Target Temp:");
lcd.print(TargetTemp);
lcd.print(".00c ");
lcd.setCursor(1,2);
lcd.print("Current Temp:");
lcd.print(TEMP);
lcd.print("c ");
if (TEMP < TargetTemp)
{
digitalWrite(Heater1,LOW); //Heater ON
digitalWrite(Heater2,LOW);
lcd.setCursor(1,3);
lcd.print("Heater ON ");
lcd.print("Lite=");
lcd.print(Light);
lcd.print(" ");
}
if (TEMP > TargetTemp)
{
digitalWrite(Heater1,HIGH);
digitalWrite(Heater2,HIGH); //Heater OFF
lcd.setCursor(1,3);
lcd.print("Heater OFF ");
lcd.print("Lite=");
lcd.print(Light);
lcd.print(" ");
//lcd.clear();
}
}
//*************************************************************************************************************
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
//-----------------------------------------------------------------
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
//------------------------------------------------------------------
// Gets the date and time from the ds1307
void getDateDs1307
(
byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read() &0x07);
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
//==================================================================================