Comparing two values

hello everyone. i have arduino mega, nextion display, and max6675 thermocouple. also i have a slider on my display to set a temperature value. my goal is to compare temperature read value and set value so i can open/close my relay in order to result of comparison. i have checked the usage of “if” command and i think im using it in the right way.

And my relay is working i have tried to make it work with only thermocouple in another sketch. i have assigned an integer constant value for setting temperature when i heat the sensor, relay was openning and when i cool the sensor it was closing.

So i have to do this process on a variable set value not a constant. ill change the set value on display and ,i’ll control relay according to this set value.

im using
float temp
temp=thermocouple.ReadCelsius()

temp value is perfectly displayed on the screen

for the slider value

uint32_t number2 = 0
h0.getValue(&number2)

i cant compare temp and number2. Please help me. Thank you very much.

tez_deneme_27.05_20.53.ino (1.95 KB)

Does it work if both are floats?

Paul

i cant compare temp and number2.

Post the complete program where you tried this.

Do you actually mean that you can’t compare them or that you get unexpected results ?

thanks for your replies.

there are two sketches attached. sketch2 is with maxx6675 thermocouple, nextion display without a slider, and relay.

on sketch 2 i set a value as an integer and compare this set value with temperature value afterwards my relay is working fine. it does the things that i ask for. (i mean high or low stiuations.)

but on sketch 1 i use a slider as a set value. it doesnt work i mean the relay stays its initial state. :(:frowning:

sketch1_27.05_21.45.ino (2.05 KB)

sketch2_27.05_21.45.ino (954 Bytes)

POST the code.

#include “Nextion.h”
#include “max6675.h”

int thermoSO = 53;
int thermoCS = 51;
int thermoSCK = 49;
MAX6675 thermocouple(thermoSCK, thermoCS, thermoSO);
int vccPin = 47;
int gndPin = 45;
int role = 39;
NexText t0 = NexText(0, 4, “t0”);
NexNumber n2 = NexNumber(0, 10, “n2”);
NexSlider h0 = NexSlider(0, 1, “h0”);
NexNumber n0 = NexNumber(0, 3, “n0”);
float temp;
uint32_t number2;
int setval;
char buffer[100] = {0};

NexTouch *nex_listen_list =
{
&h0,
NULL
};

void h0PopCallback(void *ptr) // Release event for slider
{
uint32_t number2 = 0; // Create variable to store value of slider
h0.getValue(&number2); // Read the value of the slider
setval = (int)number2;

Serial3.print(“n1.val=”); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial3.print(number2); // This is the value you want to send to that object and atribute mentioned before.
Serial3.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial3.write(0xff);
Serial3.write(0xff);
} // End of release event

void setup() {

Serial3.begin(9600);
pinMode(role, OUTPUT);
pinMode(vccPin, OUTPUT);
digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT);
digitalWrite(gndPin, LOW);
digitalWrite(role,LOW);
delay(500);
h0.attachPop(h0PopCallback);
} // End of setup

void loop()
{
nexLoop(nex_listen_list);
readSensor();
sendTemperatureToNextion();
h0.getValue(&number2); // Read the value of the slider
setval = (int)number2;
if(temp<setval)
{
digitalWrite(role,HIGH);
delay(500);
digitalWrite(role,LOW);
delay(1500);
}
else
{
digitalWrite(role,LOW);
}
unsigned long A_Current_Microseconds = micros();
delay(500);
}

void readSensor()
{
temp = thermocouple.readCelsius();

}

void sendTemperatureToNextion()
{
String command = “t0.txt=”"+String(temp,4)+""";
Serial3.print(command);
Serial3.write(0xff);
Serial3.write(0xff);
Serial3.write(0xff);
}

Needs more [code][/code]

but on sketch 1 i use a slider as a set value. it doesnt work i mean the relay stays its initial state

Whenever you have problems with a comparison not doing what you expect then the first thing to do is to print the values being compared just before you compare them. Are they what you expect ?

You have more than one "number2"

void h0PopCallback(void *ptr)  // Release event for slider
{
  uint32_t number2 = 0;  // Create variable to store value of slider
  h0.getValue(&number2);  // Read the value of the slider
  setval = (int)number2;
  
  
  Serial3.print("n1.val=");  // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
  Serial3.print(number2);  // This is the value you want to send to that object and atribute mentioned before.
  Serial3.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
  Serial3.write(0xff);
  Serial3.write(0xff);
}  // End of release event

Why bother passing a pointer forward? You don't use it.

TolpuddleSartre: void h0PopCallback(void *ptr)  // Release event for slider {  uint32_t number2 = 0;  // Create variable to store value of slider  h0.getValue(&number2);  // Read the value of the slider  setval = (int)number2;      Serial3.print("n1.val=");  // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.  Serial3.print(number2);  // This is the value you want to send to that object and atribute mentioned before.  Serial3.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.  Serial3.write(0xff);  Serial3.write(0xff); }  // End of release event

Why bother passing a pointer forward? You don't use it.

That is almost certainly the call-back event handler for a slider object in the Nextion library. The OP has no control over how those are defined. Regards, Ray L.