#include "ArduinoJson.h" #include #include // 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; int data = 0; char userInput; char* commandVer; 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; void setup() { // put your setup code here, to run once: pinMode(MOSFET, OUTPUT); Serial.begin(9600); sensors.begin(); } void loop() { // put your main code here, to run repeatedly: //if(Serial.available()>0) { 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); } /* digitalWrite(MOSFET, HIGH); delay(2000); digitalWrite(MOSFET, LOW); delay(2000); */ delay(1000); // } }