Set and reset (Setpoint a range)

Hello everybody
I am here to ask you about a solution to make advanced set point.
for example if we want to measure the temperature then the fan will turn off when the temperature is 25 c, that means 25 is the set point
then the system will turn the fan on and off near 25 many and many times which is not good for relays fan and many other things
then my question is : if I make a range from 22 to 27, then the setpoint is not a value it is a range
in PLC for example we use Set and Reset which means if temperature is 22 Reset and it will be off until the temperature reach 27 , then Set and still on until temperature reach 22 etc.
but what about Arduino ?
is there any similar thing
anyone can help me by a code ?
thank you

Are you asking about hysteresis?

In measurements:
Set point can be a "particular point" or "a range" depending on how you define it. You can do both conveneintly in Arduino UNO/NNAO/MEGA.

1 Like

Thank you
do you have an example code please ?

:slightly_smiling_face: :sweat_smile:


if (temperature > 27)
  turn off
else if (temperature < 25)
  turn on
1 Like

are you sure that this simple code is enough ?
then between 25 and 27 sometimes on and sometimes off
means when the temperature 26 and it is increasing to 27 it is still off
the opposite when it is 26 and decreasing to 25 it will be on
if you see what I mean

Not unless you do something to change it.

1 Like

Yes, yes it is.

Run your finger carefully through the very simple logic and you will see it exactly does what you want.


1 Like

Demonstration sketch using LM35 Temp Sensor (Fig-1)


#define L 13

void setup()
  pinMode(L, OUTPUT);

void loop()
  unsigned int myTemp = 100 * (1.1 / 1023.0) * analogRead(A4);
  Serial.println(myTemp, DEC);
  if (myTemp > 26 && myTemp < 27)
    digitalWrite(L, LOW);
  if (myTemp > 25 && myTemp < 26)
    digitalWrite(L, HIGH);
  delay(1000);  //test interval
1 Like

When will this be true?

When will this be true?

  if (myTemp > 25 && myTemp < 26)

The original simple expression did exactly and what was needed, why complicate it?

Even if you’d gotten it right.


1 Like

Post-10 is a demonstative presentation which is in line with @haidar952's proposition. In order to make it sense, his proposition should include much more wider range insted of (26, 27) and (25, 26). It is time for the OP to have his proposition refined.

Let all the ideas be floated even some of them are truly weird.

I am trying to do this by Arduino
I can do it using PLC
When I write
if (temperature > 27)
turn off
Then the value 26 or 25 is not match the condition
Then it will be on
So if I have a programing structure which do that
In PLC there is Set structure which means that output will still on until new structure Rest then still off until Set ...
What about Arduino programing

Assemble a few brain cells and get them functioning together.

Carefully look at post # 6 and appreciate what it is saying.

Then look through the code in post # 10; however flawed it is, one thing about it than can be said is that it appears to be a complete Arduino sketch.

Mix and match, show us your attempt at writing your own program.

Or wait patiently and someone will do the work for you, sooner or later.


1 Like

And you could draw a more complete diagram, even though we all get what you mean:


Turn on when the temperature rises over the upper limit, turn off when the temperature falls below the lower limit, otherwise do nothing, leave the thing on or off like it was.


The condition is "if temperature is greater than 27".

Why do you think that 25 or 26 degrees match the condition of "greater than".

"Greater than"(>) is not the same as "not equal to" (!=).

I think I misunderstood the OP's issue.
On the Arduino platform, outputs are persistent. If a pin is set to on or off (HIGH or LOW), it will stay that way until specifically written in the opposite direction.

Thank you very much
But why you are angry
We are here to discuss
To reach it together
Anyway thanks Sir

1 Like


Dear Sir
When I try it
The condition is "Greater than 27" you had right
But is 26 or 25 is greater?
So if I want to reduce the temperature to be lower than 23 then turn fan off
It don't match the condition
In this simple code we only do two setpoints instead of one
But we don't make a range
Arduino will be grazy between the two setpoints
I tried it
On off on off on off every scan
I will try all your suggestions
And I appreciate your efforts

Show us the code where you tried it and it didn’t work.

A complete program that we could run for ourselves.

Like you might get by studying post # 6, post # 10 and applying some effort.