// library’s used
#include <OneWire.h>
#include <DallasTemperature.h>
/*-----( Declare Constants and Pin Numbers )-----*/
//Temp Sensors pin
const int DS18B20PIN_hive1 = 6;
const int DS18B20PIN_hive2 = 4;
/*-----( Declare objects )-----*/
//Setup OneWire
OneWire hive1_OneWire(DS18B20PIN_hive1);
OneWire hive2_OneWire(DS18B20PIN_hive2);
//Setup temp sensors
DallasTemperature hive1_Sensor(&hive1_OneWire);
DallasTemperature hive2_Sensor(&hive2_OneWire);
/*-----( Declare Variables )-----*/
float gethive1_Temperature(){
hive1_Sensor.requestTemperatures();
return hive1_Sensor.getTempCByIndex(0);
}
float gethive2_Temperature(){
hive2_Sensor.requestTemperatures();
return hive2_Sensor.getTempCByIndex(0);
}
void setup()/****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
Serial.println("DS18B20 test!"); //Com printout test code
hive1_Sensor.begin();
hive2_Sensor.begin();
}
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Check if any reads failed and exit early (to try again).
if (isnan(gethive1_Temperature())) {
Serial.println("Failed to read from DS18B20 Temp sensor Hive 1!");
return;
}
// Check if any reads failed and exit early (to try again).
if (isnan(gethive2_Temperature())) {
Serial.println("Failed to read from DS18B20 Temp sensor Hive 2!");
return;
}
// if any result below is NaN (not a number) then something went wrong!
// code print test to COM port to test sensors to definitions work ok
Serial.println("Hive 1");
Serial.println("------------------");
Serial.println("Queen Excluder / Brood");
Serial.print("Temperature: ");
Serial.print(gethive1_Temperature(), 2); // 2 decimal places
Serial.println(" °C"); //println line return
Serial.println("Normal Range Between 33 to 35°C");
Serial.println(" "); //print spare line
Serial.println("Hive 2");
Serial.println("------------------");
Serial.println("Queen Excluder / Brood");
Serial.print("Temperature: ");
Serial.print(gethive2_Temperature(), 2); // 2 decimal places
Serial.println(" °C"); //println line return
Serial.println("Normal Range Between 33 to 35°C");
Serial.println(" "); //print spare line
Serial.println(" "); //print spare line
}