Please, I have a problem with the lamp turning on

30.00 is only default when BUTTON_MENU is pressed
Enter the temperature adjustment menu. Set is the target temperature
and currentTemp is the water temperature given by the ds18 sensor
By pressing the BUTTON_OK button, the set target temperature is confirmed and the comparison between
setTemp and currentTemp
The lamp represents the water heater

Even by connecting it to the GND Arduino, the same problem remains

If 30c is the "ambient" temperature... when your sketch checks if the water is "too high" or "too low", rather than IF > 30 ... IF < 30, use IF 32 ... IF < 28... that way your ambient temperature can be +/-2 degrees without turning the lamp on. Does that sound good?

 if(currentTemp >= setTemp+2) {
    Serial.println("Temperature is too high!");
    digitalWrite(13, LOW);
  }
  else if(currentTemp < setTemp-2) {
    Serial.println("Temperature is too low!");
        digitalWrite(13, HIGH);
  }

My result with the sketch edit: temperature reading without the lamp on.

The GND symbol is ground. There is no need to explicitly connect a GND symbol to the Arduino GND.

Removing the GND symbol at the buttons makes the buttons not work.

a7

How do I make it start the comparison when the button is pressed?

Make a function that checks the temperature.

When you poll the BUTTON_OK button, have the sketch call the checkTemperature function.

I don't have any idea about it

Make a function that checks the temperature.

void checkTemperature()
{
 if(currentTemp >= setTemp+2) {
    Serial.println("Temperature is too high!");
    digitalWrite(13, LOW);
  }
  else if(currentTemp < setTemp-2) {
    Serial.println("Temperature is too low!");
        digitalWrite(13, HIGH);
  }
}

When you poll the BUTTON_OK button, have the sketch call the checkTemperature function.

     else if(digitalRead(BUTTON_OK) == LOW) {
        checkTemperature();
        confirmTemp();
      }

The circuit will damage the Arduino, unless you add a resistor in series with the LED.

The problem of turning on the light after pressing the ok button has been resolved
Now the comparison is not done because the temperature exceeded the required temperature and the lamp is still on

I know this, thank you, but this emulator only has one resistor with a value of 1k ohm
Actually I use resistors

This is a technical forum. Please post the correct circuit, rather than an idiot diagram.

That is why we ask for real schematics.

See post #28.

The problem is that it doesn't compare

You can check here

If done correctly, it does check. See my post #23

A wise person once said, I’ll add this to my something was learned today list.
:thinking:

1 Like

Where do you set pin 13 as OUTPUT?

Post#17... probably overlooked.

Make a function that checks the temperature.

void checkTemperature()
{
 if(currentTemp >= setTemp+2) {
    Serial.println("Temperature is too high!");
    digitalWrite(13, LOW);
  }
  else if(currentTemp < setTemp-2) {
    Serial.println("Temperature is too low!");
        digitalWrite(13, HIGH);
  }
}
When you poll the BUTTON_OK button, have the sketch call the checkTemperature function.

     else if(digitalRead(BUTTON_OK) == LOW) {
        checkTemperature();
        confirmTemp();
      }

in this code "if(currentTemp >= setTemp+2) { " not working why?