First appologies if my title sounds ambiguous, im fairly new to electronics, and some of the things I learned in school all those years back have escaped me.

I have a circuit that consists of a lipo battery, a magnetic switch and an electromagnet.

The electromagnet turns on when the magnetic switch is turned on by a nearby magnet. However what I need is for it to turn on every OTHER time it detects a magnet.

I vaguely remember something about using flipflops for doing this. Am I right to assume this is the best way to approach this? Or am I going to run into problems? I want the simplest circuit possible. (ive previously used an arduino to do all this and increment a counter, but I feel this is a bit overkill).

  • \$\begingroup\$ Do you already have circuitry to debounce the switch? Also, do you have a regulated supply voltage, or are you running directly off the Li-Po? \$\endgroup\$ Oct 30, 2016 at 15:30
  • \$\begingroup\$ Last but not least, do you have some sort of power-on reset signal in your design, or does the circuit need to provide it itself? \$\endgroup\$ Oct 30, 2016 at 15:31
  • \$\begingroup\$ I'm using an adafruit powerboost 500 which regulates the power supply, with a switch hooked up to the EN and GND which will essentially switch it on and off. \$\endgroup\$ Oct 30, 2016 at 15:37

1 Answer 1


Depending on the actual details of the input pulses (i.e. you are actually getting a nice pulse and not a bouncing signal which needs additional circuitry to clean up), yes you can use a flip flop to toggle every other pulse.

There are many ways you can do this. The simplest is shown in the image I found below (googling 2 bit counter flip flop):

two bit counter with flip flops

If you notice the Q1 output toggles every other clock input pulse.

This is using a negative edge flip flops. You can use positive edge flip flops (or inverter on the clk input) and the functionality will remain the same, except the output switches will occur at the rising edges of clock instead of falling.


I just wanted to add that you do not need JK flip flops for this to work. You can use T-flip flops, D-flip flops; whatever really. But the example shown uses JK flip flops.

  • \$\begingroup\$ Thank you for the example this answers my question so I shall go for this approach. \$\endgroup\$ Oct 30, 2016 at 15:36
  • \$\begingroup\$ Would something similar to this work? ti.com/product/CD4013B It looks essentially the same. \$\endgroup\$ Nov 1, 2016 at 14:45
  • \$\begingroup\$ @Festivejelly: yes, that would work perfectly. To get d flip flop's to toggle you can feed back the Q' into the D input (that way each time it receives clock it will toggle to the opposite state). If there are any hold time failures you can add an RC network between the Q' and the D input. \$\endgroup\$
    – jbord39
    Nov 1, 2016 at 15:16
  • \$\begingroup\$ I got this working but the pulse stays on until an edge change. I want the counter to count but based on pulses and skip a pulse if it's <2 \$\endgroup\$ Dec 4, 2016 at 13:34
  • \$\begingroup\$ Yes flops are going to be edge triggered. Can you draw the waveforms you are getting vs. the waveforms you want? \$\endgroup\$
    – jbord39
    Dec 4, 2016 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.