Sie sind auf Seite 1von 4

/* Example sketch for Maxim Integrated DS18B20 temperature sensor

Written by cactus.io, and requires the cactus_io_DS18B20 library.


This sketch was tested using the Adafruit Prewired DS18B20 Sensor.
For hookup details using this sensor then visit
http://cactus.
io/hookups/sensors/temperature-humidity/ds18b20/hookup-arduino-to-ds18b20-temperature
-sensor
*/

#include "cactus_io_DS18B20.h"

int DS18B20_Pin = 2; //DS18S20 Signal pin on digital 2


int DS18B20_Pin3 = 3; //DS18S20 Signal pin on digital 3
int DS18B20_Pin4 = 4; //DS18S20 Signal pin on digital 4
int DS18B20_Pin5 = 5; //DS18S20 Signal pin on digital 5
int inlet_temp;
int outlet_temp;
int inside_temp;
int outside_temp;
int pump_on;
bool pump_enabled=false;
int i;
int inside_setpoint=65;
int x;

// Create DS18B20 object


DS18B20 ds(DS18B20_Pin);
DS18B20 ds3(DS18B20_Pin3);
DS18B20 ds4(DS18B20_Pin4);
DS18B20 ds5(DS18B20_Pin5);
void setup() {

ds.readSensor();//outlet temp
ds3.readSensor();//inlet temp
ds4.readSensor();//room temp
ds5.readSensor();//outside temp

Serial.begin(9600);
//Serial.println("Maxim Integrated DS18B20 Temperature Sensor | cactus.io");
//Serial.println("DS18B20 Serial Number: ");

// we pass the serial number byte array into the printSerialNumber function
//printSerialNumber(ds.getSerialNumber());
//printSerialNumber(ds3.getSerialNumber());
//printSerialNumber(ds4.getSerialNumber());
//printSerialNumber(ds5.getSerialNumber());
//Serial.println("");
//Serial.println("");

//Serial.println("Temp (C)\tTemp (F)\tTemp (C)\tTemp (F)\tTemp (C)\tTemp (F)\tTemp


(C)\tTemp (F)");
//Serial.println("Temp (F)\tTemp (F)\tTemp (F)\tTemp (F)");

//Serial.println("CLEARDATA"); // clears sheet starting at row 2


Serial.println("CLEARSHEET"); // clears sheet starting at row 1

// define 5 columns named "Date", "Time", "Timer", "Counter" and "millis"


Serial.println("LABEL,Date,Time,INLET,OUTLET,INSIDE, OUTSIDE, PUMP STATUS");

// set the names for the 3 checkboxes


Serial.println("CUSTOMBOX1,LABEL,spare");
Serial.println("CUSTOMBOX2,LABEL,spare");
Serial.println("CUSTOMBOX3,LABEL,Start/Stop Pump");

// check 2 of the 3 checkboxes (first two to true, third to false)


Serial.println("CUSTOMBOX1,SET,0");
Serial.println("CUSTOMBOX2,SET,0");
Serial.println("CUSTOMBOX3,SET,0");

// initialize digital pin 8 as an output.


pinMode(8, OUTPUT);

void loop() {
ds.readSensor();
outlet_temp=ds.getTemperature_F();//outlet temp

//Serial.print(ds.getTemperature_C()); Serial.print(" *C\t");


//Serial.print(outlet_temp); Serial.print(" *F\t");

ds3.readSensor();
inlet_temp=ds3.getTemperature_F();//inlet temp

//Serial.print(ds3.getTemperature_C()); Serial.print(" *C\t");


//Serial.print(inlet_temp); Serial.print(" *F\t");

ds4.readSensor();
inside_temp=ds4.getTemperature_F();//room temp
//Serial.print(ds4.getTemperature_C()); Serial.print(" *C\t");
//Serial.print(inside_temp); Serial.print(" *F\t");

ds5.readSensor();
outside_temp=ds5.getTemperature_F();//outside temp

//Serial.print(ds5.getTemperature_C()); Serial.print(" *C\t");


//Serial.print(outside_temp); Serial.println(" *F");

// Add a 2 second delay.


//delay(10000);

// START OF EXCEL CODE

// simple print out of number and millis. Output e.g.,:


"DATA,DATE,TIME,TIMER,4711,13374,AUTOSCROLL_20"
Serial.println( (String) "DATA,DATE,TIME," + inlet_temp + "," + outlet_temp +
"," + inside_temp + "," + outside_temp + "," + pump_on + ",AUTOSCROLL_20" );

i++;
// and for forced quit of Excel with saving the file first
//if(i==450)
//{
Serial.println("CUSTOMBOX3,GET");
x=Serial.readStringUntil(10).toInt();
if(x) {
pump_enabled=true;
}
else
{
pump_enabled=false;
}
if (pump_enabled==true){
if (inside_temp < inside_setpoint)
{
digitalWrite(8, HIGH);
pump_on=1;
}

else
{
digitalWrite(8, LOW);
pump_on=0;
}
}
else{
digitalWrite(8, LOW);
pump_on=0;
}

if(i==200)
{

Serial.println("SAVEWORKBOOKAS,test-run");

}
delay(10000);

// We call this function to display the DS18B20 serial number.


// It takes an array of bytes for printing
void printSerialNumber(byte *addr) {
byte i;

for( i = 0; i < 8; i++) {


Serial.print("0x");
if (addr[i] < 16) {
Serial.print('0');
}
Serial.print(addr[i], HEX);
if (i < 7) {
Serial.print(", ");
}
}
}

Das könnte Ihnen auch gefallen