Pushbutton to change and remember new state?

Hi everyone,

My scenario is that I'd like to have a momentary pushbutton switch controlling a two state circuit (ie. On/On, each state doing something different). There would be a second pushbutton, a few feet away that would operate the same circuit. Pushing either button would toggle from State A to B, or vice versa. 12v current would be maintained through the component to the proper state after it's switched.

Is there a component that does this? I know the Arduino could handle this through a couple of output pins to a pair of transistors or relays, but I think the Arduino is overkill here.

A diagram:

Thanks in advance.

edit: new title, more relevant

You are describing a [u]type "T" Flip-flop[/u]. The T flip-flop changes state every time it sees a negative-going edge on it's input (or positive-going edge, depending on the device).

The issue is, that these things work at MHz speeds, and mechanical switches "bounce". That means you can get several state-changes every time you push the button, and you have to "de-bounce" the switch. Another issus is that most logic circuits work at 5V and you'll need some additional circuitry to boost the logic signals to 12V.

I'm not sure if you can actually find a "T" flip-flop, but you can make one from a "J-K" flip-flop such as the [u]74LS73[/u] can be wired to work as a type-T by tying the J & K inputs high and triggering the clock input.

You can also use a D-type FF (eg 4013), wire /Q back to D.

Whatever you use you will have to add some debounce circuitry to the FF's clock input.

CMOS flip flops will run at 12v.


Rob

OK, now that I've read about these Flip-Flops, let's see if I get this right:

The J-K FF acting as a T-FF: J&K will be pulled high all of the time (mimicing the T), and the Push Button goes to Clock, which is normally LOW (since the button is normally open). Pushing the button sends Clock HIGH, and then releasing the button drops it to LOW again. Because J&K are HIGH, as the Clock dropped, the output on Q and /Q are both toggled to their complementary. I would connect Q to Output-A and /Q to Output-B from my original diagram to turn one off and the on at the same time.

Close?

As for the D-FF: Tying /Q to D acts as the clock for the FF, creating the rising/falling edges needed to capture data. In this case, the input on D doesn't matter, and I would use S&R to trigger the different state. Not sure how I would set both S&R to opposite states with only one pushbutton?

In either case, how do I keep 12V flowing to Output-A and Output-B after the toggle event?

Here's the full circuit diagram. Anything in BLUE is my wishlist to the circuit. The black is the original circuit.

The original circuit is normally used with a toggle switch (where my OUTPUT A & B are), that activates a twin-coil switch motor. It dumps a capacitor charge to one side while simulataneously starting to charge the other side, in anticipating of the next toggle/dump. That charge & hold process is why I need the constant 12v to the ON side of the trigger. It also controls the LEDs display that show which side of the switch was last thrown. Hopefully this helps put it in perspective.

I would use S&R to trigger the different state.

No, with a D-type S and R do not enter into the equation unless you want to use them for power-up state setting. You simply clock the FF with your switches and it changes state each time.

In either case, how do I keep 12V flowing to Output-A and Output-B after the toggle event?

The outputs constantly drive either 12v or 0v so that's not a problem. However now that we see the whole circuit the FF does not exactly mimic that switch.

The switch goes open circuit for the "off" pole, therefore the cap discharges through a 10k resistor. The FF will actively discharge the cap which will be much faster and could maybe blow up the FF. I think you will need a 10k in series with the FF outputs and a diode in parallel with the resistor. This will allow the FF to charge the cap fast and discharge slow as the switch does.

But even then the FF is applying a dead short to the cap, ie what a cap is discharged to 0v you apply 12v directly to it. For a brief period that's a dead short. Plus it has to dive a LED as well.

Altogether now I see the whole circuit I'm not convinced a single FF is the right thing for the job because I'm not sure of the timing and currents involved (someone else may be).

I'm thinking you could use your FF to control a small relay that mimics the switch exactly. Or if you want a solid-state solution use an analogue switch that is rated for the current needed or some more FETs.


Rob

Just to throw another vairable into the mix - could the Arduino make life simpler? Momentary push buttons go to Digital IN pins. Use code to toggle the state of outputs - A and B would be Digital OUT pins. The 5v output pins link to a Base on a transister, controlling the flow of 12V through to the different OUTPUT lines...

(I wouldn't have the slightest clue which transistor would be appropriate for this)

pbechard: Just to throw another vairable into the mix - could the Arduino make life simpler? Momentary push buttons go to Digital IN pins. Use code to toggle the state of outputs - A and B would be Digital OUT pins. The 5v output pins link to a Base on a transister, controlling the flow of 12V through to the different OUTPUT lines...

(I wouldn't have the slightest clue which transistor would be appropriate for this)

You would be correct. listen for change of state, debounce, trigger transistor, remember new state.

pbechard stated he didn't want to use an Arduino and I assume one is not present. However I agree, if there is one in the project anyway it's a no-brainer to use it for this.


Rob

Thanks Rob for paying close attention to the original post. I did state that I felt an Arduino would be overkill, but I'm not adverse to using one. I have a Uno, and could use it or a Nano for the project. I just figured there was a discrete component that could do this just as easily. The best way to learn about this whole field is to ask about the parts we don't know/understand.

Peter

the switches would be in parallel, not a problem. Hard part is making them do a solid-state inversion. Only way I could think of would be using a XOR circuit with a SPDT relay.

Let's say we don't want to use an Aduino for the time being. A 4013 D-type FF wired to toggle and diving a FET that drives an SPDT relay will do the job. Just wire the relay in place of the switch.


Rob

Graynomad:
Let’s say we don’t want to use an Aduino for the time being. A 4013 D-type FF wired to toggle and diving a FET that drives an SPDT relay will do the job. Just wire the relay in place of the switch.


Rob

Well, I ordered kits today to build out the original circuits. I got a few extra so that I could experiment with the solution we’re discussing here.

Rob - can you help me identify the proper FET and SPDT relay’s to buy (and why you chose what you did)?

I’ll take a guess:
D-type FF: HEF4013BP (can handle 12V, so need to regulate 12V down to 5V)
SPDT Relay: 12V-5A@125VAC (since the circuit is 12V based, and source is 1.5A)
FET (Transistor): no clue. :slight_smile:

I’ve also attempted an update to the circuit based on what you described. I hope it’s right, cause what I’ve built makes sense to me!

Peter

That's getting close. The transistor is upside down and the connection to the relay is wrong.

Here is a suggested circuit.

Note that the clock signal needs to be debounced with an R and C followed by a schmitt trigger (74xx14, not sure which can handle 12v, a CD40106 should to the job), as this inverts the signal the switches now connect to GND.

I didn't have an appropriate relay symbol but I think you can get the drift.

I'll look for some typical FET and relay components.


Rob

Thanks for the circuit diagram and your help so far!

Let's see if I understand things now: I had to look up the Schmitt Trigger Inverter, and it looks like it's part of the debouncing the switches and gives a nice clean and steady HIGH or LOW to the Flip-Flop. The D-FF toggles based on that HIGH/LOW input, and triggers the MOSFET. The FET allows 12V to flow through the Relay by connecting it to ground (assuming Pin 1 is Vin, Pin 8 is Vout). The relay you show is a DPDT, but you're only using one throw (Pin 3), so it's really just a SPDT. When the relay is enabled, it toggles between pins 2 & 4.

Updated whole circuit (so far):

When I look to order the Schmitt, I see multiple pins and not just the 2 shown in our schematic. Is the chip really just a collection of the Triggers, and I would only use one pair of pins in this circuit? (similar scenario with the 4016 D-FF)

Graynomad:
I’ll look for some typical FET and relay components.


Rob

Rob (or others) - can you make a suggestion for the appropriate FET and Relay so that I can order in the parts?

Thanks again for your help so far with this project. I really appreciate the people on this Arduino forum, and how willing they are to help the rookies get up to speed.

FETs aren’t my strong point but I’d say just about anything would do, try BS170 or BS270.

Likewise for the relay, here’s on from Mouser

http://au.mouser.com:80/ProductDetail/Omron-Electronics/G5V-13-DC12/?qs=sGAEpiMZZMsx4%2FFVpd5sGadV7oBVuq8S

Just about anything will do, so If you have a local electronics store I’d just get what they have, maybe run it past us before you buy.


Rob

This is pretty close to the one you listed?

Miniature SPDT Relay 12V - 10A@125VDC http://www.dipmicro.com/store/833H-1C-C-12VDC

That looks OK, they also have 2N7000 FETs that should work as well.

http://www.dipmicro.com/store/2N7000


Rob

Hi guys, Finally getting a chance to get back to this. For simplicity, I'm building out just the first part of the circuit in the diagram on the other page, stopping where the A/B jump points are. At A/B I have a red and green LED, going to ground through a common resister. This is to let me see that the output of the relay is one side or the other as I troubleshoot this circuit enhancement.

I have breadboarded things, and when I turn on the circuit, the relay immediately trips to the active side and lights LED-b (LED-a would be the Normally Closed side). Pressing and holding either of the pushbuttons turns the relay off, allowing it to light LED-a. When I release the pushbutton, the relay flips again, lighting LED-b. Remember, the objective of the circuit it to use the pushbutton as a toggle, which each press alternating between LED-a and LED-b.

I suspect that I'm not wiring my ICs correctly. Schmitt CD40106BE and FlipFlop CD4013B both call for a Vss and Vdd. Am I supposed to do anything with these? Right now I'm only wiring in the pins that Rob's schematic called for (CLK, Q, Q/, etc).

Input or thoughts are appreciated, as are all the suggestions so far.

Update: Based on some reading/videos online, I wired Vdd to the 12v+resistor line and Vss to ground on both ICs, and the results are the same. So.... still stumped.