If statements have stopped working ?

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;
  }
  
}

Hello

if (temp1 <= 12)

I think this should be else if, so that the else below will not be executed if temps is above or equal 30.

Or change to

if ( temp1 >= 30 || temp1 <= 12 )
{
  ...
}
else
{
  ...
}

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.

Yes tried that also, still not driving the digital out pump_circ when condition is met ?

What is your arduino board?

  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.

Yes your comments are on the money

devkitC( wroom32)

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

You were told what the error is, and still claim it is the hardware?

SMH.

It very clearly is a coding issue.

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.

Read post 3 again, and try to understand 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


  ...
if ( temp1 >= 30 || temp1 <= 12 )
{
  ...
}
else
{
  ...
}

Is what I have are you saying this is wrong too

No code you posted uses the OR function, so who knows?

I can only comment to posted code.

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;
  }
 */ 
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.