Microcontroller to energize 2 relays

Discussion in 'Embedded Systems and Microcontrollers' started by mikeysela, Jul 24, 2010.

  1. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Hi I am new.

    I am trying to use a Microcontroller that can increment a count from 0 to 2 with the use of a single pushbutton/switch. So when the button is pressed, it will count up and round back down from 2 to 0 and just keep cycling through all three. In addition, I need the microcontroller to energize a 4PDT relay when the count is 1, and energize a different 4PDT relay when the count is 2, and be in off mode (i.e no current output) when the count is 0.

    Can this be done and what would I need to know?

    Thanks very much.
     
  2. davebee

    Well-Known Member

    Oct 22, 2008
    539
    46
    Do you really have to use a microcontroller to do this?

    Because if you don't, this can be done with just a few logic chips.

    A counter chip can increment on a buttonpress, and an AND gate can detect the "three" state and reset the counter to zero when the counter reaches three, and a transistor driver chip can buffer the counter "1" and "2" bits to drive the relays.

    There are details you'd need to consider - the AND gate has to issue the correct logic to reset the counter, so you might need a NAND gate instead, or use an inverter logic chip, and some counters need a fairly long reset pulse to fully reset, and you might need some debounce conditioning on the button output.

    But still, if you're not familiar with microprocessors, I think that discrete logic would be a better solution if a working circuit is all you need.
     
  3. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Hi. Thanks for the response.

    No, I do not need a uC to do this, I can use discrete logic gates. Im just wondering, what i need is a part of a much larger circuit and its all analog. Mixing in digital components won't cause any issues with the analog circuit?

    I am currently considering what you suggest, hopefully I can come up with the logic to do it.
     
  4. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Would you know a good chip that can do the binary counting from a pushbutton input?
    thanks
     
  5. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    Here is a simple counter (4017 Counter) based relay control that I have used in the past, depending on the relays you are using (The ones on the schematic were low current board mount 4PDT relays) you may have to substitute the transistors (2N3904's) with something that can handle your current requirements for the relays you have....

    Basically when the switch is first pressed, the count will increment from 0 to 1, which will power the first relay, when the switch is pressed again, the count will be 2, and relay 2 will be on (relay 1 turns off), press the switch again and the IC will reset back to 0, and both relays will be off....

    4017 Relay Control.png

    B. Morse
     
  6. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Wow, thanks Bmorse, that looks very neat. My question to you is what kind of switch is that? I would have to use a microswitch for this purpose. IS the one you have a spring return type pushbutton?
     
  7. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    Yes, it is just a circuit board mount, normally open switch, your switch should be fine, the circuit includes some "de bouncing" for the switch, that is what the capacitor and resistor is for after the switch, this will eliminate false triggering from the switch when it is pressed....

    B. Morse
     
  8. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Ok and the next question is using the circuit u gave me, the VDD on the transistors could be any value depending on the transistor i suppose. But I do not have any DC sources in my circuit, only an AC transformer output (one being 14VAC). Any idea how I would convert the AC voltage from my transformer to whatever the required DC voltage is for the transistors? Thanks
     
  9. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    Were you planning on powering a microcontroller with that transformer???

    The circuit I provided was based on a proper DC power source for a 5 volt microcontroller circuit...

    What are the ratings and specs for the relays that you have?? And what exactly are you controlling with this circuit besides the relays?

    B. Morse
     
  10. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Its a big circuit that I cant post up for you see at the moment unfrotuantely but ill do my best to describe it.

    I am using a bridge rectifier where needed to turn the AC to a DC supply. The current relays I have use 6VDC which are rectified using the bridge recitifer from a 12 VAC output from a transformer. So, my relay coils need 6VDC to energize which they get from the bridge, and the outputs from the relays are used to drive DC motors.

    The original circuit is made. However, it used a stepper relay to select from one of three states used to energize 1 of 2 coils, or be in the off state. The stepper relay is no longer possible to use, so I am trying to replace that with the circuit you gave me basically. ALL the stepper relay would do is step through the 3 states (1st relay energized, 2nd relay energized, off). Now I need another method to be able to do that. The coil on the stepper relay also used 6VDC.
     
  11. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    That should be ok then to power the circuit I provided from the 6VDC that you have, both the IC and transistors would both be powered from the same source...

    B. Morse
     
  12. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    Post the schematic you have on the whole circuit... just to make sure everything will work together...

    B. Morse
     
  13. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    I see why 6VDC would be fine for the IC circuit, but is 6V really enough for the transistor circuit? i thought those were usually around 12-15V. Since I need 6V for the relays, does the transitor get shorted or something when current passes through the base? Isn't there some sort of voltage drop across the transistor, thus giving me less voltage for the relay coil?
     
  14. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    basically the 220 ohm resistors prevents too much current from getting to the base of the transistor and prevents it from saturating, which could cause it to over heat and fail... but it will work fine with the 6 volts as power.....

    Here, read this, makes it easier for me than having to re type same information over again ;) >> http://www.kpsec.freeuk.com/trancirc.htm#npn

    B. Morse
     
    Last edited: Jul 24, 2010
  15. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Awesome, thanks for the info man. uve been much help i will let u know on the progress
     
    Last edited: Jul 24, 2010
  16. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Hey im not so sure the circuit you gave me is what I needed to accomplish. I need the sequence to be Q0- high, Q1- high, Q2- high, Q1- high, and repeat with each microswitch press. I think what you have done b yconnecting the Q3 to the reset is cause me to have to press on the microswitch twice to activate the first relay again.
     
  17. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    With the circuit, once relay 2 is energized and you press the switch again, Q3 will go high which is connected to the reset of the 4017, which will cause the 4017 to reset back to 0, which will automatically set Q0 High.... so the next press of the switch Q1 which is connected to Relay 1 will turn High...


    Check it out here in this tutorial >> http://www.doctronics.co.uk/4017.htm#reset


    B. Morse
     
  18. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Gotcha, i thought the reset just turns all outputs to 0. thank you!
     
  19. mikeysela

    Thread Starter Member

    Jul 24, 2010
    87
    1
    Hey B.

    I was just wondering which exact chips you have used here. From my findings I have the 2N3904 Small Signal NPN Transistor and CD4017BC chip for the counter. are those the right parts?

    Thank you kindly.
     
  20. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    That is correct ....

    B. Morse
     
Loading...