Skip to content
Home > Components > Logic Components > D Flip-Flop

D Flip-Flop

A digital memory element that captures and stores a single bit of data on the rising edge of a clock signal.

Component Preview

D Flip-FlopD Flip-Flop

The D (Data) Flip-Flop is the fundamental building block of digital memory. It tracks its input (D) and updates its output (Q) to match that input only when a rising clock edge is detected. It holds that value steady until the next rising clock edge.

Logic ComponentsSequential LogicMemory

Overview

D Flip-Flops are crucial for creating registers, shift registers, and finite state machines. Unlike combinational logic (AND, OR), the D Flip-Flop has "state" (memory) and relies on a synchronized clock signal to operate.

Pin Reference

PinTypeDescription
DinputData Input. The logic value (HIGH or LOW) to be stored.
CLKinputClock Input. The flip-flop captures the value of D on the rising edge (transition from LOW to HIGH) of this signal.
QdigitalThe current stored state.
Q'digitalThe inverted stored state (NOT Q).

Configurable Attributes

This basic D Flip-Flop has no configurable attributes.

Working Principle

State Transition Table

CLK (Edge)DQ (Next State)Q' (Next State)
(Rising)001
(Rising)110
0, 1, XNo Change (Q)No Change (Q')
  • Rising Edge: The moment the CLK pin transitions from LOW (0) to HIGH (1).
  • Hold: At all other times (CLK is constant 0, constant 1, or falling from 1 to 0), changes on the D pin are ignored, and the outputs hold their current values.

Wiring Diagram

Wiring Diagram

Example Arduino Code

You can emulate the behavior of a hardware D Flip-Flop in code, evaluating on rising edges.

cpp
const int pinD = 2;   // Data Input
const int pinCLK = 3; // Clock Input
const int pinQ = 4;   // State Output

bool lastClkState = LOW;
bool stateQ = LOW;

void setup() {
  pinMode(pinD, INPUT);
  pinMode(pinCLK, INPUT);
  pinMode(pinQ, OUTPUT);
}

void loop() {
  bool currentClkState = digitalRead(pinCLK);
  
  // Detect Rising Edge
  if (currentClkState == HIGH && lastClkState == LOW) {
    // Capture Data
    stateQ = digitalRead(pinD);
  }
  
  // Drive Output
  digitalWrite(pinQ, stateQ);
  
  lastClkState = currentClkState;
}

Simulation Notes

  • The initial state of Q is LOW (0) by default upon starting the simulation.
  • Ensure your clock signal is clean. In the simulator, the Clock Generator component provides a perfect signal. If using a push-button, be aware of switch bouncing if debouncing logic is not applied.

Notes / Warnings

  • This is a standard Edge-Triggered D Flip-Flop without asynchronous Set or Reset pins. For Set/Reset capabilities, use the D Flip-Flop (SR) variant.

Released under the MIT License.