3

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.

Vishal
  • 203
  • 2
  • 15
  • As a side note: is your transistor still alive? They usually do not take kindly relay coils without a freewheeling diode. See for example http://electronics.stackexchange.com/questions/100134/why-is-there-a-diode-connected-in-parallel-to-a-relay-coil – Sredni Vashtar Nov 25 '15 at 02:26
  • Thank you for letting me know about freewheeling diode. You have saved me from frying up the transistor. – Vishal Nov 25 '15 at 06:15

2 Answers2

1

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.

WhatRoughBeast
  • 59,978
  • 2
  • 37
  • 97
  • Yes, that was a typing mistake. I have my code on another HDD & at the time of asking this question, i was not having access to the HDD, so I typed the code here, anyways I will just edit it. Thank you for the above diagram. But I am not able to calculate things because of the inputs of nand1 and nand2 are complicated. Still I will try to learn calculating logic gates. I would verify your answer & then I will tell you if I have any problems. – Vishal Nov 25 '15 at 06:21
  • The logic isn't hard if you approach it right. Assume the tanks are filling, and both are halfway full. Then all switches are closed, and you can see the state of the SR easily. Then change one of the FULL switches, and trace the effects. – WhatRoughBeast Nov 25 '15 at 15:10
0

If your buttons are physical switches. you may place them in parallel. and in series. this will reduce the component cost.

like switch2 and switch 4 is an OR in your arduino code. so you may put them in parallel and switch1 and 3 is an AND in your arduino code. so you may put them in series.

and you have programmed a SET RESET. so you'll have to build a SET RESET like a FLIP FLOP.

there are various circuits to find on google.

on8tom
  • 439
  • 4
  • 12