2023-08-06 23:12:01 +02:00
|
|
|
/* References:
|
|
|
|
* https://lastminuteengineers.com/multiple-ds18b20-arduino-tutorial/
|
|
|
|
*/
|
2023-08-02 01:04:39 +02:00
|
|
|
#include "ArduinoJson.h"
|
|
|
|
|
2023-08-06 19:35:21 +02:00
|
|
|
#include <OneWire.h>
|
|
|
|
#include <DallasTemperature.h>
|
|
|
|
|
|
|
|
// Data wire is conntec to the Arduino digital pin 4
|
|
|
|
#define ONE_WIRE_BUS 2
|
2023-08-06 23:12:01 +02:00
|
|
|
#define MOSFET1 3
|
|
|
|
#define MOSFET2 4
|
2023-08-06 19:35:21 +02:00
|
|
|
// Setup a oneWire instance to communicate with any OneWire devices
|
|
|
|
OneWire oneWire(ONE_WIRE_BUS);
|
|
|
|
|
|
|
|
// Pass our oneWire reference to Dallas Temperature sensor
|
|
|
|
DallasTemperature sensors(&oneWire);
|
2023-08-06 23:12:01 +02:00
|
|
|
DeviceAddress Thermometer;
|
|
|
|
int deviceCount = 0;
|
2023-08-06 19:35:21 +02:00
|
|
|
|
|
|
|
int analogPin = 2;
|
2023-08-01 23:38:12 +02:00
|
|
|
int data = 0;
|
|
|
|
char userInput;
|
2023-08-02 01:35:46 +02:00
|
|
|
char* commandVer;
|
2023-08-06 23:12:01 +02:00
|
|
|
// temperature values in °C
|
2023-08-06 19:35:21 +02:00
|
|
|
float tempSensor1;
|
|
|
|
float tempSensor2;
|
2023-08-06 23:12:01 +02:00
|
|
|
// HighTemp - when to turn on the power
|
2023-08-06 19:35:21 +02:00
|
|
|
float HTemp1 = 12.0;
|
2023-08-06 23:12:01 +02:00
|
|
|
float HTemp2 = 16.0;
|
|
|
|
// LowTemp - when to turn of the power
|
2023-08-06 19:35:21 +02:00
|
|
|
float LTemp1 = 10.0;
|
2023-08-06 23:12:01 +02:00
|
|
|
float LTemp2 = 14.0;
|
2023-08-06 23:57:29 +02:00
|
|
|
bool fetState1;
|
|
|
|
bool fetState2;
|
2023-08-06 23:12:01 +02:00
|
|
|
|
|
|
|
uint8_t addrSensor1[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD1, 0xB1, 0x75 };
|
|
|
|
uint8_t addrSensor2[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD7, 0xDA, 0x9A };
|
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
void setup() {
|
|
|
|
// put your setup code here, to run once:
|
2023-08-06 23:12:01 +02:00
|
|
|
pinMode(MOSFET1, OUTPUT);
|
2023-08-07 00:44:15 +02:00
|
|
|
pinMode(MOSFET2, OUTPUT);
|
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
Serial.begin(9600);
|
2023-08-06 19:35:21 +02:00
|
|
|
sensors.begin();
|
2023-08-06 23:12:01 +02:00
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2023-08-02 01:04:39 +02:00
|
|
|
|
2023-08-06 19:35:21 +02:00
|
|
|
sensors.requestTemperatures();
|
|
|
|
|
2023-08-06 23:12:01 +02:00
|
|
|
tempSensor1 = sensors.getTempC(addrSensor1);
|
2023-08-06 19:35:21 +02:00
|
|
|
if(tempSensor1 > HTemp1) {
|
2023-08-06 23:12:01 +02:00
|
|
|
digitalWrite(MOSFET1, HIGH);
|
2023-08-06 23:57:29 +02:00
|
|
|
fetState1 = 1;
|
2023-08-06 19:35:21 +02:00
|
|
|
} else if(tempSensor1 < LTemp1) {
|
2023-08-06 23:12:01 +02:00
|
|
|
digitalWrite(MOSFET1, LOW);
|
2023-08-06 23:57:29 +02:00
|
|
|
fetState1 = 0;
|
2023-08-06 23:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tempSensor2 = sensors.getTempC(addrSensor2);
|
|
|
|
if(tempSensor2 > HTemp2) {
|
|
|
|
digitalWrite(MOSFET2, HIGH);
|
2023-08-06 23:57:29 +02:00
|
|
|
fetState2 = 1;
|
2023-08-06 23:12:01 +02:00
|
|
|
} else if(tempSensor1 < LTemp1) {
|
|
|
|
digitalWrite(MOSFET2, LOW);
|
2023-08-06 23:57:29 +02:00
|
|
|
fetState2 = 0;
|
2023-08-01 23:38:12 +02:00
|
|
|
}
|
2023-08-06 23:57:29 +02:00
|
|
|
|
2023-08-07 00:44:15 +02:00
|
|
|
StaticJsonDocument<96> jsonOut;
|
|
|
|
//jsonOut["sensor"] = "1";
|
2023-08-07 01:41:27 +02:00
|
|
|
jsonOut["1"]["temp"] = tempSensor1;
|
|
|
|
jsonOut["1"]["state"] = fetState1;
|
2023-08-07 00:44:15 +02:00
|
|
|
|
|
|
|
//jsonOut["sensor"] = "2";
|
2023-08-07 01:41:27 +02:00
|
|
|
jsonOut["2"]["temp"] = tempSensor2;
|
|
|
|
jsonOut["2"]["state"] = fetState2;
|
2023-08-07 00:44:15 +02:00
|
|
|
serializeJson(jsonOut, Serial);
|
2023-08-07 01:27:10 +02:00
|
|
|
Serial.println();
|
2023-08-07 01:08:16 +02:00
|
|
|
delay(5000);
|
2023-08-06 19:35:21 +02:00
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
}
|