Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15217

How to use statements to do different things depending on what is the temperature sensor readings

$
0
0

Hello world!!

Newbie here, I am trying to have different things happen depending on what is the reading of a temperature sensor. If the temperature is above a set point (ex: 0 deg C), it starts a heater controlled with pin 2, once the temperature reaches a second set point (ex: 30 deg C), it turns a pin 8 high and if the temperature reaches a third setpoint (ex: 60 deg C), it turns off the heater (pin 2 Low). If the temperature falls below the third setpoint (ex: 60 deg C), then the heater turns back on and so on, so the temperature is maintained at 60 deg C (similar to a PID controller). Pin 8 should remain HIGH after it has been triggered regardless of what the heater is doing.

I currently have the code below, but I know this is not going to work as is, maybe using "Switch statements would be better.

Any help on this would be greatly appreciated, I'm a newbie at this...

void loop() {
myNex.NextionListen();  // This function must be called repeatedly to response touch events
                          // Wait for Nextion to be booted.



int digitalValue = digitalRead(45);  // OK pin

if (((digitalValue == HIGH) && (digitalRead(47) == HIGH) && (thermocouple->readCelsius() > 0))) {
  digitalWrite(2, HIGH);  // Pin 2 turn ON Heater
  myNex.writeNum("bt8.val", 1);
  myNex.writeNum("bt28.val", 1);
  Serial.println("Starting PID Heater");
  }
  if (((digitalValue == HIGH) && (digitalRead(47) == HIGH) && (thermocouple->readCelsius())) > 30) {
    digitalWrite(8, HIGH);
    Serial.println("Starting something");
    }
    if (((digitalValue == HIGH) && (digitalRead(47) == HIGH) && (thermocouple->readCelsius())) > 60) {
      digitalWrite(2, LOW);
      Serial.println("Heater PID OFF");
}
...                        

15 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 15217

Trending Articles