Hi everybody.
I'm want to compare 3 DS18B20 temp sensors on 1 wire.
How do I do that??
I'm been trying different sketches but I am not getting there.
I want to compare sensor 3 against sensor 1 and get a value, then see if sensor 3 is 5 degrees C higher than sensor 1.
then I want to compare sensor 2 against sensor 1 to see if the temperature is lower than 1 degree.
Does somebody know and could give me a hint how to write this??
Thanks to wildbill I starting to get there, but still having some trouble with the state in the end of sketch.
Status Log
starting one wire sensors
Locating 1-wire devices...
Found 3 devices.
Givarna visar...
Temp solpanel is: C: 28.75
Temp Invatten is: C: 26.00
Temp utvatten is: C: 26.00
Manuellt on = 1, off = 0: 0
Status State1: 0
Status State2: 0
Diff 1 is:2.75
Diff 2 is:0.00
I can't get Diff 2 to change to 1, even moving sensor 2 (utvatten) to same water temp as sensor 3 (solpanel)
Diff 1 works OK
What have I done wrong??
/* This Arduino sketch reads 3 DS18B20 "1-Wire" digital
temperature sensors. Marcs testing.
*/
#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);
//Adjustments
//Set max pool temp
float poolMax = 31.0;
//if poolMax paus system
float poolCooldown = 1.0;
//Set solpanel diff to start
float setDiff = 5.0;
//Set minimum diff temp
float minDiff = 1.0;
//set state
int state1 = 0;
int state2 = 0;
// Assign the addresses of your 1-Wire temp sensors.
// Solpanel S3, invatten S1, utvatten S2
DeviceAddress solpanel = { 0x28, 0x43, 0x41, 0xD9, 0x04, 0x00, 0x00, 0x1A };
DeviceAddress invatten = { 0x28, 0x10, 0xBB, 0xD9, 0x04, 0x00, 0x00, 0x76 };
DeviceAddress utvatten = { 0x28, 0x53, 0x70, 0xDA, 0x04, 0x00, 0x00, 0x80 };
// Number of temperature devices found
int numberOfDevices;
//variables used for control logic
float Temp1, Temp2, Temp3; // storage for comparing the inlet and outlet temps
const boolean ON = HIGH; // makes the code easier to read
const boolean OFF = LOW; // makes the code easier to read
//variables used for control logic
float differential1 = 0.0 ;
float differential2 = 0.0 ;
int invalidCount = 0;
//define pin ManPump On
const int manon = 11;
//define pin for pump relay
const int pumpOn = 13;
const int ledPin = 12; // the number of the green LED pin
// variables will change:
int manonState = 0; // variable for reading the Manual On status
//this part of the code runs once to get everything setup and started.
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
Serial.println ("starting one wire sensors");
sensors.begin();
// locate devices on the one wire bus
Serial.println("");
Serial.print("Locating 1-wire devices...");
Serial.println ("");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// set the resolution to 10 bit (good enough?)
sensors.setResolution(solpanel, 10);
sensors.setResolution(invatten, 10);
sensors.setResolution(utvatten, 10);
//set pins to output
{
pinMode (pumpOn, OUTPUT);
pinMode (manon, INPUT);
pinMode(ledPin, OUTPUT); // green LED
}
//give time for everything to start
delay (2000);
}
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);
}
}
void loop(void)
{
// read the state of the switch value:
manonState = digitalRead(manon);
// check if the switch is on.
// if it is, the buttonState is HIGH:
if (manonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
state1 = 1;
}
if (manonState == LOW) {
// turn LED off:
digitalWrite(ledPin, LOW);
//state1 = 0;
}
{
Serial.print("Givarna visar...\n\r");
sensors.requestTemperatures();
Serial.print("Temp solpanel is: ");
printTemperature(solpanel);
Serial.print("\n\r");
Serial.print("Temp Invatten is: ");
printTemperature(invatten);
Serial.print("\n\r");
Serial.print("Temp utvatten is: ");
printTemperature(utvatten);
Serial.print("\n\r");
Serial.println(""); // radbryt
Serial.print ("Manuellt paa = 1, av = 0: ");
Serial.println(manonState);
Serial.println("");
Serial.print ("Status State1: ");
Serial.println(state1);
Serial.println("");
Serial.print ("Status State2: ");
Serial.println(state2);
Serial.println("");
delay(1500);
//Sensors for logic
Temp1 = sensors.getTempC(invatten);
Temp2 = sensors.getTempC(utvatten);
Temp3 = sensors.getTempC(solpanel);
//difference between solpanel and invatten gives us our differential
differential1 = Temp3-Temp1;
Serial.print("Diff 1 is:");
Serial.println(differential1);
Serial.println("");
differential2 = Temp2-Temp1;
Serial.print("Diff 2 is:");
Serial.println(differential2);
Serial.println("");
//logic1
{
if ((differential1 > 5.0) && (Temp1 < poolMax)); { // compare the temps,
(state1 = 1); // return 1 if heat is on
if (differential1 < 5.0)
(state1 = 0);
}
//Logic2 ( This doesn't work, Why??)
{
if (differential2 > 1.0 );
(state2 = 1);
if (differential2 < 1.0 );
(state2 = 0);
}
delay (2000);
}
}
}