Go Down

Topic: D-Flip Flop issue (Read 11211 times) previous topic - next topic


Hey there!
I just got myself the 4013 flip flop and am trying to understand how exactly it works.
I've hooked it up to the +5V of my arduino, but somehow nothing's happening..
Here's what I'd expect should happen:

1) D is attached to +5V and Gnd, D = HIGH
2) Clk is attached to +5V and Gnd, Clk = HIGH
3) S is attached to Gnd, S = LOW
4) R is attached to Gnd, R = LOW

Since both - D and Clk - are HIGH, I'd expect the LED to turn on (also to measure an output voltage of around 4-5V, which I don't). The LED is connected to Q.
I'd also expect the LED to stay on when I remove the Clk wire.
Additionally, if I connect R to +5V and Gnd, I'd expect the LED to turn off and stay off.

None of that is actually happening. Upon powering the circuit, the LED stays off, no matter what wires I connect/disconnect. If I connect the LED to NQ, it turns on, as expected.

Is there anything I'm missing here?



If you have an O-scope or a miltimeter it would help you debug circuits like this much quicker (a cheap multimeter can be bought for ~20$).

Now about the flip-flop. I believe most flip flops are positive EDGE triggered so the CLK line must be clocked in such a way so the flip-flop will detect the positive edge. Connecting the CLK constantly HIGH may not be triggering the FF. So, try pulling out the CLK pin and then putting it back in to very crudely simulate a clock. Alternatively, configure an arduino PWM and connect it to this pin to clock it properly.

in 1) you say D is connected to +5v and GND. How is it connected to both?
Basically, looking at 4013 flip flop datasheet, you want:
S -> LOW
R -> LOW
CLK -> POSITIVE EDGE TRIGGERED (confirmed from datasheet) so you MUST have a rising edge to trigger it!

Also, since there are two FFs on that IC, make sure you got your pins connected correctly.


Jan 26, 2011, 12:25 pm Last Edit: Jan 26, 2011, 12:39 pm by Christoph680 Reason: 1
Hey Igor!
Thanks for the quick reply ;)
I do own a (cheap) multimeter.. I also thought about debugging it that way, but all I can get out of it is what I wrote above. NQ shows a voltage of +4-5V and Q is around 0.2V

About 1):
There's a line running from +5V over a 1k resistor to Gnd. Before that resistor I added the wire going to D.
So, using the multimeter, I can confirm that D is HIGH, S is LOW and R is LOW too.
The only thing that bothers me now is the edge triggering. I already tried pulling the Clk line out before powering the circuit and then plugging it in. The thing is, I need to control the flip flops (both, D and Clk) from a simple pushbutton, while the reset afterwards comes from the arduino. The arduino will globally reset all flip flops on the circuit (there's around 6 of them, so 12 flip flops overall)

Pins are definitely connected correctly. Only thing that could be wrong is the wiring of Vdd and Vss. Vdd runs from +5V and Vss runs to Gnd.


What's also interesting is that if I completely remove the LED and the resistor leading to it from Q, I get 0V on Q and +4-5V on NQ. The LED lights up on NQ.
However, if I add the LED and resistor to Q, I get 0V on NQ and +4-5V on Q, however, the LED doesn't turn on.. that somehow seems illogical..
I'm testing with the multimeter from the wire leading to Vdd and the Q/NQ pins.

Also, another observation:
Setting the third pin (Clk1) HIGH gives me +5V on Q and 0V on NQ, while D is either floating or connected to Gnd. Afterwards, setting it to LOW leaves +5V on Q and 0V on NQ, which obviously shouldn't happen since D is always LOW. This way, when Clk1 becomes LOW, Q should also become LOW and not stay HIGH. Like I said, it can't be wired wrong, it's the third pin, which is Clk1.

Also, setting R to HIGH should give me 0V on Q and +5V on NQ, which it doesn't. Even when Clk1 and D are LOW.


Okay, wiring all cables up to arduino ports that are obviously pulled down fixes the issues and the IC works fine.. now the question would be how I can wire the flip flop up so that D and Clk are simultaneously controlled by one pushbutton and only R is controlled by the arduino..

I noticed that S sets D immediately to HIGH, but keeps it on HIGH as long as R isn't HIGH. That might be the simplest solution. Could I simply wire S up to my pushbutton and wire R to the arduino? I don't think that's essentially what S is supposed to do (override D and Clk for the period it is on HIGH), but at least it works :D


Are you just trying to get the output to toggle each time you push the pushbutton?  If so just connect !Q to D and connect the pushbutton to the clock input.  Every time you push the button Q will toggle.


I'd say you had two options.
One is to use  Set and Reset inputs as you just described:

May need transistor to get decent current thru the LED to make it turn on.
The other would be to pull down the clock line with a resistor and use the switch connecting to +5VC to clock in the D input (high or low), and use arduino to Set, or Reset,to the opposite state.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Could I simply wire S up to my pushbutton and wire R to the arduino?

If you just want the PB to set and Ard to reset then yes. In this case there's no obvious reason to have a FF in the first place, just run the button into the Arduino (unless you don't have the extra pin).

Or do you want to toggle the FF?


Rob Gray aka the GRAYnomad www.robgray.com


Hi Christoph680

Check out this link for a cheap logic probe.  http://www.electronics-tutorials.com/test-equip/led-test-lamp.htm Sometimes easier then using a multimeter for quick checks of logic levels.

It may be better to post a drawing of your connections.  From you last description, you tied a resistor between +V and Gnd, taking a connection from the +V side for a high.  From your descritpion, you could never take that pin low, as it would short the +V connection.  That is not he way to create a high.  You want to connect the reistor between +V and the pin.  That way you can pull the pin low.

Also, what size resistor are you using with your LED?  Make sure you are not exceeding the current capabilty of the outputs.

A very simple way to set the Q output to H (1), set D, CLK and R low,  pulse the S (set) to high then low.  The Q should go H.


The other thing  you can do for a test tool is download Visual Analyzer
Its a soundcard based PC oscilloscope that you can use to look at signals with, often times a picture is worth way more than what a digital multimeter can tell you.

Or get a proper hardware based scope like this one, www.dpscope.com $89, have to do a little assembly yourself, is what I use whenn debugging.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]


Or a little "buffered" LED "logic analyzer" that will show you states of several pins without loading the circuit.
This can be as simple as a logic chip from the same family set up to drive LEDs.  pretty much any simple gate can be made into an LED buffer.

Go Up