Logic gates w/Transistors

Discussion in 'The Projects Forum' started by Uber_Goober, Jan 20, 2013.

  1. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    I'm going to build a device to actuate a solenoid valve when the water level in a tank reaches a set low mark, and then shut off the valve when the tank has filled to a set high mark. I'd like to use hall effect sensors with a magnet in a small bouyant plastic float on the inside of the tank.

    I've come up with this logical diagram. When the water level reaches the low level, the signal into the OR gate will activate the solenoid. At the same time, this will activate the AND gate (because the high sensor has an inverter), with this signal feeding into the OR gate as well. This will latch the activation signal until something happens to turn off the AND gate- which will happen when the high sensor detects the magnet. Here's the logical view I came up with:

    [​IMG]

    Since this uses exactly one inverter, one AND and one OR gate it would be kind of wastefull to use 3 discrete ICs to implement this. So I thought I'd implement the gates with NPN transistors instead. Also, it just seemed kind of interesting to do.

    Now, if at any point you begin to think I may not know what I'm talking about, you're most likely correct haha. I'm a software guy but I like tinkering with hardware. But its been many years and I'm a bit rusty even on what I was able to teach myself back then. But thats not going to stop me!

    Anyway, after some research I came up with this implementation. Would love to get critiques before I go breadboard it. In a few circuits I found out there, the designer used diodes between transistor outputs/inputs to protect the transistors, but I don't quite understand why those would be needed or exactly where. So if it looks like voltage swings would damage the transistors and I need diodes to protect that, I'd be interested in learning where. One small change from the logical diagram is that the hall sensor I found has an open collector and from what I gathered reading the spec pulls the output to ground in the presence of magnetic induction. So for this sensor, its actuall the bottom that needs to be inverted. I also added a BDX53C transistor to drive the solenoid.

    Forgot to put this on the diagram, but V+ is 12VDC, from a wall wart.

    [​IMG]

    Any chance this will work? How far off am I?

    Cheers,
    Eric
     
  2. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Replace 16 components with one 80 cents controller chip.

    For instance 16f1503. And use one digital MOSFET for the output.

    Of course your transistor solution will work but costs maybe 5 dollar if you consider the PCB space + assembly efforts.
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Another option is using NAND gates to make your gates:
    http://www.kpsec.freeuk.com/gates.htm#combinations
    At first glance you would need a maximum of 6 gates, so two quad NAND gate chips, but it might be possible to get the same functionality with less than 6 gates.
     
  4. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    Yes, Markd is right. You can do it with 4 NAND gates (one 4011). 2 of the not gates cancelled each other.

    Allen
     
    Last edited: Jan 20, 2013
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    It looks like you might have some fun with this without causing much damage. <grin> If you get yourself some switches you can experiment on your breadboard with just a voltmeter and learn a lot from this.

    Generally these gates are called resistor transistor logic, or RTL. Long time back they even made chips like this.

    I once built an AND gate like yours when I was a kid, was not happy with the results as the bottom input can still drive the output (albeit with no gain) when the top Q is off. So it depends strongly on what is around it if it will work. You may find swapping the inputs sources helps.

    The one diode you have is correct, it keeps the solenoid from destroying the Q driving it.

    I also note your logic view does not agree with the schematic (look for the inverter off the sensor).
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,411
    3,353
    You can do this with one QUAD 2-INPUT NAND gates.

    Or one S-R flip-flop.

    Edit I: Or maybe no gates at all (I have to think this through).

    Edit II: The simple solution is two 2-INPUT NAND gates (half of a quad package).

    Edit III: or a two-transistor flip-flop.
     
    Last edited: Jan 20, 2013
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    What if you for instance want a 24 hours timer?

    -Display and set the time.
    -Display and set the on-time.
    -Display and set the duration.

    The tiny chip does the trick.

    No relay is used but a MOSFET.
    No realtime clock IC is used and no battery but a tiny supercapacitor.
    This one actually was found inside a 1986 VCR.

    Once you are used to digital controllers, you can build much more powerful circuits. You simply don't want to deal with logic gates again. They belong to the 1970s. Actually the 74hc164 is a fossil from that series, and used here to drive LEDs.

    A PIC is as simple as that: The chip + 1x 1uF capacitor. And a 32KHz crystal in that case.

    I would never even think to breadboard it- they chips cost about $1.
     
  8. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    Wow what a cool option. I didn't know PICs had gotten so cheap and easy to work with. Actually about 15 years ago I designed a pretty major project around a PIC. I did everything from the hardware to the firmware, to the mainframe software that crunched data for reporting. Its the only electronics I've built that ever got commercially produced. I had a blast working with the PIC but didn't even consider that for this project due to the complexity. But this chip has a built in clock, is easily programmable, and 80 cents! OMG! Well, I'll probably still build my transistor circuit just for the learning experience, but yeah I'm definitely going to look into the PIC solution. Could let me do things like easily add a max time on or another water sensor to avoid flooding. Great idea.
     
    takao21203 likes this.
  9. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    Thanks Mardk77 and the others with the NAND solutions. I've never got the hang of "negative logic design" - I always go for the literal logic implementation. But in the back of my mind I always know there's a more efficient and cooler design based on negative logic. Thanks!
     
  10. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    Cool- thanks for the ideas. I was thinking that an S-R flip flop would probably do it but I didn't think it through. And several replies mentioned the NAND approaches as well. The no-logic idea sounds interesting. Thanks!
     
  11. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    I'm pretty much sold on it. I love PICs, and have worked with them before. But for $1. Unbelievable. I'm all over it.
     
  12. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    Thanks Ernie! Yeah I will probably build several versions of it just for the tinkering fun.

    The reason for the change to my circuit diagram vs. the logic diagram is the logic diagram assumed a logical 1 for the presence of a magnetic field. The hall sensors I decided on (for no particular reason) have an OC and pull the signal to a logical 0 in a magnetic field. So I had to switch it and put the inverter on the low side instead of the high side.

    Thanks everyone for all the cool ideas!
     
  13. BillB3857

    Senior Member

    Feb 28, 2009
    2,400
    348
    You do have a safe "to drain" overflow system in place just in case, right!
     
  14. WBahn

    Moderator

    Mar 31, 2012
    17,715
    4,787
    I haven't worked with Hall effect sensors in something like this. The concern that comes to my mind is this: If I understand correctly, you have a magnet on a float and your sensor will detect when that magnet is near the sensor. So, if the magnet is not near a sensor you won't know where the magnet really is, namely above or below the sensor. So let's say the tank is filling and as the magnet approaches the high sensor something happens, -- maybe the float gets hung up, maybe the tank sloshes, whatever, and the float shoots past the sensor too fast for the system to respond. Now the tank is over the shut-off level but you will never get another signal to turn off the valve. A safety "to drain" overflow is important (assuming what is in the tank can safely be dumped into a drain)., but you probably want redundant means of detecting that the tank is above the shut-off level (and perhaps below the refill level). Putting additional sensors along the tank will address most of this.
     
  15. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    No, but I have GFI outlets :)
     
  16. Uber_Goober

    Thread Starter Member

    Jan 19, 2013
    45
    4
    What would be a good digital mosfet? Is that better than a plain old NPN transistor with enough current handling ability?

    Thanks
     
  17. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I believe he is referring to a Logic Level MOSFET, vs. Standard MOSFET. They are the ones with the RDSon listed for Vgs of 5V or less.

    IRLZ44 is a good example of a Logic Level Power MOSFET that is common.
    2N7000/2N7002 are small signal logic level.

    MOSFETs work much better as switches than bipolar junction transistors do (NPN/PNP BJTs). They have an on resistance in the milli-ohms, no C-E voltage drop. They are voltage controlled rather than current controlled, so microcontrollers can switch them quickly without taxing the controller much.

    Whereas an NPN transistor in a switching application needs a current drive into the base of about 1/10th the needed Collector/load current to switch fully on, which can be more than typical outputs are designed for.
     
  18. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    For what it is worth, the 16f1503 contains a configureable logic cell. It is a bit complicate to set up, but it can replace logic gates with upto 4 inputs. It can even work together with the microcontroller program.
     
  19. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Is the tank sealed or does it have a lid the user can remove?

    The reason I ask is that if you could add an IR rangefinder to the top, you would be able to know the level at any point, without switches.

    I'd add a float switch that would activate an emergency drain, but other than that, a range sensor should give you the water level without adding a float, and hoping the magnets stay aligned with the hall sensors.
     
  20. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I use 2n2007 and FDV301 and FDV303.

    If you want to use a regular MOSFET you need an extra transistor to drive the gate.

    Yes they are much better, much lower ON resistance.

    If I need a regular MOSFET I often use P-channel, so I can pull down the gate with a small NPN. IRF9540 for instance.

    In my circuit for instance I want to switch 12V, 2.2 Amps. I have relays here but only for 1 Amps.
     
Loading...