← All tutorialsDLD Lab 9

By Muhammad Ibrahim · Published October 27, 2026 · 12 min read

1101 Sequence Detector Using D Flip-Flops: State Diagram, State Table and Circuit

A sequence detector watches a stream of bits, one bit for every clock pulse, and raises an output when the last four bits it saw were 1, 1, 0, 1. This is the Lab 9 circuit. It is a finite state machine with four states, so it needs two flip-flops, and both come from a single 7474. The circuit was generated with the FSM Designer in the Digital Logic Suite, but it is much easier to debug if you know where every gate came from, so this page goes through the whole derivation: states, state table, flip-flop equations, wiring, and a test with real bit streams.

CHIPS
7474, 4 × 7408, 2 × 7432, 7404
GATES AND FLIP-FLOPS
15 gates, 2 flip-flops
INPUTS
Switch X and a clock button
OUTPUT
1 LED (Z)
The finished Lab 9 circuit in LogicBench: a 7474 flip-flop chip with AND, OR and NOT chips on three breadboards, a data switch named X, a push button used as the clock, and an LED named Z.
The finished circuit as saved in the circuit file.

Components needed for the 1101 sequence detector

  • One 7474 (dual D flip-flop), four 7408 (quad AND), two 7432 (quad OR) and one 7404 (hex inverter)
  • A DIP switch with one switch in use, renamed X (the data input)
  • A Push Button, which is the clock (I labelled it 'CLK (press to step)')
  • A Light Bar with one LED in use, named Z
  • Regulated +5V Power and Ground (GND) parts for each of the three breadboards

Open the circuit

Open the exact detector from the lab. Switch to Simulate, set X, then press the Push Button once for every bit. The LED named Z shows the detection.

Download the .json file

1101 sequence detector state diagram

start1 / 00 / 01 / 00 / 00 / 01 / 10 / 01 / 0S000S101S210S311

Each edge is labelled X / Z: the input bit and the output while that bit is applied. The green edge is the detection. In S3 a 1 completes 1101, and the machine goes to S1 and not S0, so overlapping patterns are still found.

Block diagram of the Mealy machine

XNext-state logicAND and OR gatesD1, D2Flip-flops7474 (Q1, Q2)Q1, Q2present state fed backOutput logicZ = Q1·Q2·XZPush Button (CLK)X also goes straight to the output logic, so Z reacts to X before the clock edge.

The two flip-flops hold the state. The next-state logic looks at the present state and X and sets the D inputs. Because the output logic also looks at X directly, this is a Mealy machine.

7474 D flip-flop pin diagram

7474Dual D flip-flop11CLR21D31CLK41PRE51Q61Q7GND14VCC132CLR122D112CLK102PRE92Q82Q
+5 VGroundOutputInput

Two flip-flops in one chip. The pins with a bar over the name are active low. Notice that on the second flip-flop Q is pin 9 and Q' is pin 8, the other way round from the first one.

Timing diagram for the stream 1101101

bit1234567CLKXQ1Q2ZstateS0S1S2S3S1S2S3S1

The clock rises at the end of every bit. The state changes on that rising edge. Z is high only in the second half of the bit where the machine is in S3 and X is 1, just before the clock edge, which is why it has to be read before the button is pressed.

How to build the 1101 sequence detector step by step

01

Decide what each state remembers

The machine only has to remember how much of 1101 it has seen so far. S0 means nothing useful yet. S1 means the last bit was a 1 (we have '1'). S2 means the last two bits were 11. S3 means the last three bits were 110. Four states need two flip-flops, and I use the encoding S0 = 00, S1 = 01, S2 = 10, S3 = 11, written as Q1Q2.

02

Fill in the state table

For each state and each value of X, ask what the longest useful ending of the bits is. The finished table is below. The interesting rows are these: in S2 a 1 keeps you in S2, because '111' still ends in 11. In S3 a 1 completes 1101, so the output Z is 1, and the next state is S1, because that last 1 can start a new 1101. In S3 a 0 gives '1100', which has no useful ending, so you go back to S0. This 'last bit can start the next pattern' rule is what makes the detector overlapping.

03

Write the flip-flop equations

For a D flip-flop the input D is just the next value of the state bit. Read the next-state columns of the table. Q1 becomes 1 in three cases: from S1 with X=1, and from S2 with X=0 or X=1, so D1 = Q1'Q2X + Q1Q2'. Q2 becomes 1 from S0 with X=1, from S2 with X=0, and from S3 with X=1, so D2 = Q1'Q2'X + Q1Q2'X' + Q1Q2X. The output is 1 only in S3 with X=1, so Z = Q1Q2X.

04

Wire the 7474 first

Connect pin 14 to +5 V and pin 7 to ground. The clear and preset pins are active low, so connect pins 1, 4, 10 and 13 to +5 V to keep them inactive. Connect the Push Button to both clock pins, 3 and 11. The first flip-flop (Q1) uses D on pin 2, Q on pin 5 and Q' on pin 6. The second flip-flop (Q2) uses D on pin 12, Q on pin 9 and Q' on pin 8. Notice that on the second flip-flop Q is pin 9 and Q' is pin 8, the other way round from the first one. It is a very easy mistake.

05

Build the product terms and the OR gates

Use the gate-by-gate table below. In short: an inverter makes X'. A first group of AND gates makes the state products Q1'Q2, Q1Q2', Q1'Q2' and Q1Q2. A second group ANDs those with X or X'. The two OR chips then join the terms into D1 and D2, and the last AND gate makes Z.

06

Feed the bits in and press the clock

Switch to Simulate. Set X to the first bit, press the Push Button once, set X to the next bit, press again, and so on. Read Z before you press the button for each bit, and see the next section for why. After the fourth bit of 1101, Z should be on.

1101 sequence detector state table

StateQ1Q2Next if X=0Next if X=1Z if X=0Z if X=1
S0 (nothing yet)00S0S100
S1 (seen 1)01S0S200
S2 (seen 11)10S3S200
S3 (seen 110)11S0S101

7474 and input pin connections

Pin or signalConnects toMeaning
7474 pins 1, 4, 10, 13+5 VClear and preset are active low, so they are held inactive
7474 pin 14 and pin 7+5 V and groundPower
Push Button7474 pins 3 and 11Clock for both flip-flops
7474 pin 5Q1First flip-flop output
7474 pin 6Q1'First flip-flop inverted output
7474 pin 9Q2Second flip-flop output
7474 pin 8Q2'Second flip-flop inverted output
X (switch)7404 pin 1, 7408 #2 pins 2 and 5, 7408 #3 pin 2 and 7408 #4 pin 2Data input, one bit per clock

Next-state and output logic: gate-by-gate pin table

The four 7408 chips are numbered 1 to 4 and the two 7432 chips are numbered 1 and 2, the way they are laid out in my file from left to right.

ChipPinsComputesGoes to
74041 to 2X'7408 #2 pin 10
7408 #11 and 2 to 3Q1'·Q27408 #2 pin 1
7408 #14 and 5 to 6Q1·Q2'7432 #1 pin 2
7408 #19 and 10 to 8Q1'·Q2'7408 #2 pin 4
7408 #112 and 13 to 11Q1·Q2' (same as above)7408 #2 pin 9
7408 #21 and 2 to 3Q1'·Q2·X7432 #1 pin 1
7408 #24 and 5 to 6Q1'·Q2'·X7432 #1 pin 4
7408 #29 and 10 to 8Q1·Q2'·X'7432 #1 pin 5
7408 #212 and 13 to 11Q1·Q27408 #3 pin 1
7432 #11 and 2 to 3D1 = Q1'Q2X + Q1Q2'7474 pin 2
7432 #14 and 5 to 6Q1'Q2'X + Q1Q2'X'7432 #2 pin 1
7408 #31 and 2 to 3Q1·Q2·X7432 #2 pin 2
7408 #34 and 5 to 6Q1·Q2 (same as above)7408 #4 pin 1
7432 #21 and 2 to 3D2 = Q1'Q2'X + Q1Q2'X' + Q1Q2X7474 pin 12
7408 #41 and 2 to 3Z = Q1·Q2·XLED Z

A full test: the stream 1101101

Z is read just before each clock press, with X already set to the new bit. This stream contains two overlapping copies of 1101.

Bit #XState before clockZ before clockState after clock
11S0 (00)0S1 (01)
21S1 (01)0S2 (10)
30S2 (10)0S3 (11)
41S3 (11)1S1 (01)
51S1 (01)0S2 (10)
60S2 (10)0S3 (11)
71S3 (11)1S1 (01)

Other bit streams to try

StreamHow many times Z goes onAt which bit
110114
110110124 and 7
1110115
11010114
1010none
110010none

How the 1101 sequence detector works

Why Z is read before the clock press

This is a Mealy machine, which means the output depends on the state and on the current input X. Z = Q1Q2X has an X in it, so Z goes high the moment you set X to 1 while the machine is in S3, before any clock edge. When you press the button the state moves on to S1 and Z drops again. If you only look at Z after pressing the button for the fourth bit, you will see nothing and think the detector is broken. A Moore machine, where the output depends only on the state, would instead show the detection one clock later, and it would need five states for this pattern. The Mealy version also means Z can flicker if X changes between clock edges, so it should only be read when the clock is about to tick.

The clock edge

The 7474 is positive-edge triggered, so the state changes when the button goes from released to pressed, and not when it is let go. Both flip-flops get the same clock signal, so the two state bits always change together. If you connect the clock to only one of the two pins, 3 or 11, one state bit will never change and the machine gets stuck.

Starting state and reset

In the simulator the flip-flops start at 00, which is S0. A real 7474 powers up in a random state, and in this circuit clear and preset are tied high, so there is no reset. You can still get to S0 on purpose: hold X at 0 and press the clock twice. From S1 and S3 a 0 goes straight to S0, and from S2 a 0 goes to S3 and then to S0, so two presses always get you there. A cleaner fix is a reset switch on the clear pins (1 and 13), which are active low.

Push buttons on real hardware

The simulated button gives one clean edge for each press. A real push button bounces, so a single press can look like several clock pulses and the machine will skip around the state table. Real circuits put a debounce circuit after the button, for example an SR latch built from two NAND gates. In LogicBench you do not need it, but it is the first thing to add when you move this circuit to a breadboard.

The designer's version has duplicate gates

The circuit uses 15 gates. If you compare the gate table with the equations you can see that three of them repeat something that already exists. Q1·Q2' is built twice (7408 #1, pins 4 and 5 and pins 12 and 13), Q1·Q2 is built twice (7408 #2 pins 12 and 13, and 7408 #3 pins 4 and 5), and Z is the same product as the last term of D2, so the Z gate repeats 7408 #3 pins 1 and 2. If each product were built once and wired to every place that uses it, the 8 AND gates that remain would fit on two 7408 chips instead of four, and the 3 OR gates would fit on one 7432 chip instead of two. The circuit file keeps the designer's version, so if you try the cleaner one, run it against the state table again.

Expected output of the 1101 sequence detector

  • The stream 1111 never turns Z on, because 1111 is not 1101 and the machine never reaches S3.
  • The stream 1101 turns Z on when X is set for the fourth bit, before you press the button.
  • The stream 1101101 turns Z on twice, at bit 4 and at bit 7.
  • The streams 101 and 11001 never turn Z on.
  • After the clock press that ends a detection, the machine is in S1, not S0, because the last 1 may start a new pattern.

1101 detector not working? Common mistakes

Z never turns on

Check that the clock reaches both pin 3 and pin 11 of the 7474, and that pins 1, 4, 10 and 13 are on +5 V. A clear or preset pin that is floating or low holds a flip-flop in one state.

The first flip-flop works but the second one behaves strangely

Check Q and Q' on the second flip-flop. They are pin 9 (Q) and pin 8 (Q'). On the first flip-flop it is the other way round, pin 5 is Q and pin 6 is Q'.

Z is on, but it is off again after I press the button

That is correct for a Mealy output. Z shows the detection during the bit, and after the clock the machine has already moved to the next state.

The first stream works but the next one gives a wrong answer

The machine is still in the state the last stream left it in. Before every new test, set X to 0 and press the clock twice to bring it back to S0.

Frequently asked questions

How many flip-flops does a 1101 sequence detector need?

Two. The machine has four states (S0 to S3) and two flip-flops can store four combinations, so a single 7474, which is a dual D flip-flop, holds the whole state.

What is an overlapping sequence detector?

It keeps looking for the pattern while still using bits from the previous match. In 1101101 the last 1 of the first 1101 is also the first 1 of the second one, so an overlapping detector finds both.

What is the difference between a Mealy and a Moore 1101 detector?

In a Mealy machine the output depends on the state and the current input, so it goes high as soon as the last bit is applied. In a Moore machine the output depends only on the state, so 1101 needs a fifth state and the detection shows one clock later.

What are the D flip-flop equations of the 1101 detector?

With S0 = 00, S1 = 01, S2 = 10 and S3 = 11 (written Q1Q2): D1 = Q1'Q2X + Q1Q2', D2 = Q1'Q2'X + Q1Q2'X' + Q1Q2X, and the output is Z = Q1Q2X.

How do you reset the detector to the first state?

Hold X at 0 and give two clock pulses. From S1 and S3 a 0 goes straight to S0, and from S2 it goes to S3 and then to S0, so two pulses always get you there.


Try it yourself

Open LogicBench and follow along — the simulator is free and needs no account.

Launch the simulator