2 position temperature controller with logic gates

This is the code I used in arduino. Works well.

#define temp_low_sensor 6
#define temp_high_sensor 7
#define power_relay 8

boolean set_bit;

void setup() {
pinMode(temp_low_sensor, INPUT);
pinMode(temp_high_sensor, INPUT);
pinMode(power_relay, OUTPUT);

digitalWrite(power_relay,LOW);
}

void loop() {

if(digitalRead(temp_low_sensor) == LOW && digitalRead(temp_high_sensor) == LOW){ //turning on relay if temperature is Low
digitalWrite(power_relay,HIGH);
set_bit = 1; // variable used to sense Low to high & high to Low transition
}

else if(digitalRead(temp_low_sensor) == HIGH && set_bit==1){ // Keep running the Relay ON if temperature is Low and in Low transition
digitalWrite(power_relay,HIGH);
}

else if(digitalRead(temp_high_sensor) == HIGH){ // turn the relay off, once the temperature is High
digitalWrite(power_relay,LOW);
set_bit = 0;
}
}

Needed: I want to implement this without controller as this is 2 input one output. The truth table is

Low sensor High sensor relay

0 0 1 (when temp is too low)
1 0 1 ( when temp is low)
1 1 0 (when temp is high)
1 0 0 (when temp is in range)
0 0 1 (when temp is too low)

We cant call this as truth table, as it violates the property of showing different output for same input for different times.

What I am trying to do is the Logic diagram, But I could not make it, as it has one "set_bit" variable, that I used in code.

I tried NAND gate and helpless.

Thank you for your help in advance. :slight_smile:

Needed: I want to implement this without controller

So, you don't have an Arduino question. Why ARE you here?

I asked for assist, Not opinion.

britto:
Low sensor High sensor relay

0 0 1 (when temp is too low)
1 0 1 ( when temp is low) <-----------------
1 1 0 (when temp is high)
1 0 0 (when temp is in range) <---------------
0 0 1 (when temp is too low)

for the one marked, you have the same input but different output! is that correct?

britto:
I asked for assist, Not opinion.

But you are asking in the WRONG place. You do NOT have an Arduino problem, so don't let the door hit you in the ass on the way out.

Hope you got it many times Paul

britto:
Hope you got it many times Paul

I guess you are not interested in getting help. did you not see my question?

StoneInTheSword:
If that is right, then there surely needs to be another input to differentiate between those two lines?

That's exactly what I'm trying to get out of him!

yes sherzaad, That is correct.

And the inputs we have are Low sensor & high sensor. Need to use some logic of gate to get the line(which you mentioned for differentiating).

(You could report your own post to a moderator and ask that it be moved to "General Electronics".)

The truth table is missing one important input: the state of the output. If the output is currently off then both inputs must be low to turn it on. If the output is currently on then both inputs must be high to turn it off.

This should be very easy to implement in basic logic gates once you wire the output around to the input of a gate.

Then go and look up "flip flop" because that is what you just invented and it is a useful basic concept.

britto:
yes sherzaad, That is correct.

And the inputs we have are Low sensor & high sensor. Need to use some logic of gate to get the line(which you mentioned for differentiating).

ok interesting challenge but fairly easy to implement (with one assumption that you need to confirm)

britto:
Low sensor High sensor relay

0 0 1 (when temp is too low)
1 0 1 ( when temp is low) <-----------------
1 1 0 (when temp is high)
1 0 0 (when temp is in range) <---------------
0 0 1 (when temp is too low)

assumption: once relay is '1' it should stay '1' for a minimum time to temp to go from 'low' to 'in range'

that's probably the easiest way of doing if you have no other way of determining that temp is in range.

a logic circuit along with a monostable shuold do the trick I reckon

something like this probably...

Yes, by using flip flop, it is achievable. But I am trying to implement with only logic gates. Is that possible even if it goes complex ?

britto:
Yes, by using flip flop, it is achievable. But I am trying to implement with only logic gates. Is that possible even if it goes complex ?

Yes... though its would go complex as you say... will probably need to include some resistors and capacitors as well... will let you convert my schematic (if you are happy with its operation that is!:)) to a purely logic gate based one if that's what you want!

good luck! :slight_smile:

britto:
Yes, by using flip flop, it is achievable. But I am trying to implement with only logic gates. Is that possible even if it goes complex ?

Yes. A flip-flop can be built from logic gates. It is not complex.

Show us where you are up to. Have you done the logic table with the output used as an input?