Code was working smoothly, then adjusted pump on temperaturein the if statement , after that it stopped working. the freeze protection if statement was working afterwards but has soon stopped. Am I missing something or is this a iot sketch bug that I seem to get every now and then as found in previous projects ?
#include "thingProperties.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 13
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int myled = 17;
int pump_circ = 21;
void setup() {
pinMode(myled, OUTPUT); // Initialize serial and wait for port to open:
pinMode(pump_circ, OUTPUT);
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
sensors.begin();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
float tempC_accin = sensors.getTempCByIndex(0);
Serial.print("Accumulator input temp ");
Serial.println(tempC_accin);
Serial.print("temp1");
Serial.println(temp1);
temp1 = tempC_accin;
if (temp1 >= 30 )
{digitalWrite(pump_circ, HIGH);
Serial.println("pump on");
pump = true;}
if (temp1 <= 12)
{digitalWrite(pump_circ, HIGH);
Serial.println("pump on");
pump = true;}
else {
digitalWrite(pump_circ, LOW);
Serial.println("pump off High temp");
pump = false;
}
}
You turn the pump on if temp1 is greater than or equal to 30, then you have another if that checks if it is less than or equal to 12, and if not then turn the pump off. So if it's, say 33, you turn the pump on, check to see if it's less than or equal to 12 (it's not) and turn the pump off again.
if (temp1 >= 30 )
{digitalWrite(pump_circ, HIGH);
Serial.println("pump on");
pump = true;} //This turns pump on
if (temp1 <= 12)
{digitalWrite(pump_circ, HIGH);
Serial.println("pump on");
pump = true;}
else {
digitalWrite(pump_circ, LOW);
Serial.println("pump off High temp");
pump = false; //this turns pump off again immediately
}
Look at the two comments I added. The first line turns the pump on if temp is 30 or above. The second line turns the pump off because it is not below 12.
I suspect it isnt a coding issue, I have had similar issues on other projects where it seems parts of the code are corrupt in the actual esp32 unit despite using other boards
so what is the error exaclty that has been pointed out, so far I interpret there is 2 different ways of writing an if statement mine and Guix. Both methods work, I have tried both however my thing is not driving the "pump_circ" when I can't really see why it isn't. I hope it's a simple coding issue so far I havn't found it.
the OR function if ( temp1 >= 30 || temp1 <= 12 ) is intended else the pump is off is my understanding of what it needs to work.......did work? Karmas interpretations seems the same as mine
Gotcha, yeah I changed if statement to the OR function just above to prove a point. I don't think its my code around the IF statements just hoping someone can` point out any errors in my code as I am stuck.......if I delete the THING and start fresh with the same code it will more than likely work.
#include "thingProperties.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 13
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int myled = 17;
int pump_circ = 21;
void setup() {
pinMode(myled, OUTPUT); // Initialize serial and wait for port to open:
pinMode(pump_circ, OUTPUT);
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
sensors.begin();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
float tempC_accin = sensors.getTempCByIndex(0);
Serial.print("Accumulator input temp ");
Serial.println(tempC_accin);
Serial.print("temp1");
Serial.println(temp1);
temp1 = tempC_accin;
if ( temp1 >= 20 || temp1 <= 12 )
{digitalWrite(pump_circ, HIGH);
Serial.println("pump on");
pump = true;}
/*
else {
digitalWrite(pump_circ, LOW);
Serial.println("pump off High temp");
pump = false;
}
*/
}