#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);
//set maximum tank temperature
int drivhusMax = 27;
//set maximum tank temperature
int drivhusMin = 24;
DeviceAddress insideThermometer = { 0x28, 0x34, 0x6d, 0x95, 0x04, 0x0, 0x0, 0x2c };
//variables used for control logic
static bool pumpOn;
//variables to hold temperature values
float temp;
//define pin for pump relay
const int pump = A1;
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);
}
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();
//assign value to variables
temp = (sensorValue(insideThermometer));
Serial.print("Inside temperature is: ");
printTemperature(insideThermometer);
Serial.print("\n\r");
//set pins to output
pinMode (pump, OUTPUT);
if ( (drivhusMax > temp ) )
{
digitalWrite (pump, LOW);
pumpOn =false;
}
if ( (drivhusMin < temp ) )
{
digitalWrite (pump, HIGH);
pumpOn = true;
}
Serial.print ("pump state ");
Serial.println (pumpOn);
Serial.println ("");
Serial.println ("");
}
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
float tempF = (DallasTemperature::toFahrenheit(tempC));
return tempC;
}
on off styring
on off styring
Godt nok lavet til mit drivhus, men I kan vel godt bruge det til andet :-)
Mvh.
Jens
Øl og sol er livet....
http://www.fribryg.dk" onclick="window.open(this.href);return false;
http://www.facebook.dk/fribryg" onclick="window.open(this.href);return false;
Jens
Øl og sol er livet....
http://www.fribryg.dk" onclick="window.open(this.href);return false;
http://www.facebook.dk/fribryg" onclick="window.open(this.href);return false;