2023-08-01 23:38:12 +02:00
|
|
|
|
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
|
|
|
|
#define MOSFET 3
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 19:35:21 +02:00
|
|
|
float tempSensor1;
|
|
|
|
float tempSensor2;
|
|
|
|
float HTemp1 = 12.0;
|
|
|
|
float HTemp2;
|
|
|
|
float LTemp1 = 10.0;
|
|
|
|
float LTemp2;
|
|
|
|
// countLowTemp
|
|
|
|
int cLTemp1 = 0;
|
|
|
|
int cLTemp2 = 0;
|
|
|
|
// countHighTemp
|
|
|
|
int cHTemp1 = 0;
|
|
|
|
int cHTemp2 = 0;
|
|
|
|
// loops to count temp before switching state
|
|
|
|
int cTemp = 5;
|
2023-08-02 01:04:39 +02:00
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
void setup() {
|
|
|
|
// put your setup code here, to run once:
|
2023-08-06 19:35:21 +02:00
|
|
|
pinMode(MOSFET, OUTPUT);
|
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
Serial.begin(9600);
|
2023-08-06 19:35:21 +02:00
|
|
|
sensors.begin();
|
2023-08-01 23:38:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|
|
2023-08-06 19:35:21 +02:00
|
|
|
//if(Serial.available()>0) {
|
2023-08-02 01:04:39 +02:00
|
|
|
|
2023-08-06 19:35:21 +02:00
|
|
|
sensors.requestTemperatures();
|
|
|
|
Serial.print("Sens 1 ");
|
|
|
|
Serial.print("Celsius temperature: ");
|
|
|
|
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
|
|
|
|
Serial.print(sensors.getTempCByIndex(0));
|
|
|
|
Serial.print(" - Fahrenheit temperature: ");
|
|
|
|
Serial.println(sensors.getTempFByIndex(0));
|
|
|
|
|
|
|
|
tempSensor1 = sensors.getTempCByIndex(0);
|
|
|
|
if(tempSensor1 > HTemp1) {
|
|
|
|
digitalWrite(MOSFET, HIGH);
|
|
|
|
} else if(tempSensor1 < LTemp1) {
|
|
|
|
digitalWrite(MOSFET, LOW);
|
2023-08-01 23:38:12 +02:00
|
|
|
}
|
|
|
|
|
2023-08-06 19:35:21 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
digitalWrite(MOSFET, HIGH);
|
|
|
|
delay(2000);
|
|
|
|
digitalWrite(MOSFET, LOW);
|
|
|
|
delay(2000);
|
|
|
|
*/
|
|
|
|
delay(1000);
|
|
|
|
// }
|
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
}
|