Electronic – arduino – Using logic gates instead of Arduino

arduinoboolean-algebralogic-gates

I have created a very simple circuit using arduino, in which I have 4 switches used to control the lamp ON/OFF as shown in the below schematic.

schematic

simulate this circuit – Schematic created using CircuitLab

Here is the program written in Arduino IDE:

int switch1 = 8;
int switch2 = 9;
int switch3 = 10;
int switch4 = 11;
int outputPin = 12;

void setup()
{
    pinMode(switch1, INPUT);
    pinMode(switch2, INPUT);
    pinMode(switch3, INPUT);
    pinMode(switch4, INPUT);
    pinMode(outputPin, OUTPUT);
}

void loop()
{
    if(digitalRead(switch2) || digitalRead(switch4))
    {
        digitalWrite(outputPin, HIGH);
    }

    if(digitalRead(switch1) && digitalRead(switch2))
    {
        digitalWrite(outputPin, LOW);
    }
}

Basically, my original project has a Motor instead of Lamp, & the four switches shown above are the two pairs of switches in each tank. i.e. I have two tanks and two switches in each tank. 1 switch at the bottom of the tank to measure the water level. If tank is empty then this switch will be open. Another switch at the top of the tank, which will verify that if the tank is full or not and accordingly it will turn on/off the valve which is not shown in the below diagrams, as I think it's not necessary now.

The above circuit works perfectly, but now I want to complete the same circuit using logic gates, instead of arduino. I have tried the circuit shown in below schematic, but I was not successful as I am new to electronics & Logic gates.

schematic

simulate this circuit

I want to use logic gates instead of Arduino to bring down the cost.

Thanks for any help.

Best Answer

I'll start by pointing out that your code is probably faulty. The last IF statement should examine switch 1 and switch 3, not 1 and 2.

With that said, let be restate your requirements:

1) If either SW2 or SW4 are open, start filling the tank (turn on the motor).

2) When both SW1 and SW3 are open, stop filling the tank (turn off the motor).

Right? And you do realize that this may cause one tank to overflow while the other tank is filling, right?

In this case, as @on8tom has pointed out, you need some sort of storage device, and a set/reset flip-flop is an excellent choice. Then

schematic

simulate this circuit – Schematic created using CircuitLab should do what you want. Note that I've added a flyback diode on the relay coil, and you should always do this. The diode should be rated for more current than the relay coil draws.

Related Topic