Display Structure and Theory

Seven-Segment Display:
A 7-segment display consists of seven LEDs (segments) arranged in a figure-8 pattern, plus an optional decimal point. By lighting different combinations of segments, we can display digits 0-9 and some letters.

Segment Labeling:
     AAA
    F   B
    F   B
     GGG
    E   C
    E   C
     DDD   DP
Types:
  • Common Cathode: All cathodes connected together to GND. Set pins HIGH to light segments.
  • Common Anode: All anodes connected together to VCC. Set pins LOW to light segments.

Segment-to-Pin Mapping

SegmentPositionExample Pin
ATopPin 2
BTop RightPin 3
CBottom RightPin 4
DBottomPin 5
EBottom LeftPin 6
FTop LeftPin 7
GMiddlePin 8
DPDecimal PointPin 9

Digit Encoding Table

DigitABCDEFGBinaryHex
011111100111 11100x7E
101100000011 00000x30
211011010110 11010x6D
311110010111 10010x79
401100110011 00110x33
510110110101 10110x5B
610111110101 11110x5F
711100000111 00000x70
811111110111 11110x7F
911110110111 10110x7B

Current Limiting Calculations

LED Specifications:
Forward voltage (Vf): 2.0V (red segments)
Forward current (If): 10-20mA typical

Resistor Calculation per Segment:
R = (Vsupply - Vf) / If
R = (5V - 2.0V) / 0.015A = 200Ω

Use 220Ω (standard value): I = 3V / 220Ω = 13.6mA ✓

Total Current (All Segments ON):
8 segments × 13.6mA = 108.8mA

Note: Arduino pins can source ~40mA max, sink ~40mA max.
Solution: Use current-limiting resistors OR driver IC (74HC595, MAX7219)

Circuit Diagram - Common Cathode

7-Segment Display (Common Cathode) Pin 2 ---[220Ω]---> Segment A Pin 3 ---[220Ω]---> Segment B Pin 4 ---[220Ω]---> Segment C Pin 5 ---[220Ω]---> Segment D Pin 6 ---[220Ω]---> Segment E Pin 7 ---[220Ω]---> Segment F Pin 8 ---[220Ω]---> Segment G Pin 9 ---[220Ω]---> Segment DP Common Pin(s) ----> GND

🎛️ DIP Switch

DIP Switch Theory and Operation

DIP Switch (Dual In-line Package):
A DIP switch is a set of manual electric switches packaged in a standard IC form factor. Each switch can be independently set to ON or OFF.

Common Types:
  • SPST (Single Pole Single Throw): Simple ON/OFF per switch
  • Slide: Linear motion to toggle
  • Rocker: Rocking motion to toggle
  • Rotary: Circular positions
Typical Uses:
  • Configuration selection (address, mode)
  • Binary input (8-bit DIP = 256 combinations)
  • Feature enable/disable
  • Hardware settings without code changes

Pull-up vs Pull-down Configuration

ConfigurationSwitch OFFSwitch ONAdvantages
Pull-up
(resistor to +5V)
Pin reads HIGH Pin reads LOW Uses INPUT_PULLUP mode
No external resistors needed
Pull-down
(resistor to GND)
Pin reads LOW Pin reads HIGH More intuitive (ON=HIGH)
Requires external resistors

Circuit Diagram - Pull-up Configuration

8-Position DIP Switch (Internal Pull-ups) Switch 1 --+---> Pin 2 | GND Switch 2 --+---> Pin 3 | GND Switch 3 --+---> Pin 4 | GND ... (continue for all switches) Configure pins with INPUT_PULLUP: pinMode(pin, INPUT_PULLUP); Reading: OFF = HIGH (pulled up to 5V) ON = LOW (connected to GND)

Binary Encoding Example

8-bit DIP Switch as Binary Input:

Switch positions (1=ON, 0=OFF): 0 0 1 0 1 1 0 1
Bit values (MSB to LSB): 2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰

Decimal value = 0×128 + 0×64 + 1×32 + 0×16 + 1×8 + 1×4 + 0×2 + 1×1
= 32 + 8 + 4 + 1
= 45

Reading in Code:
value = 0;
for(int i = 0; i < 8; i++) {
if(digitalRead(pins[i]) == LOW) { // ON
value |= (1 << i);
}
}

Debouncing Considerations

DIP Switch Debouncing:
Unlike push buttons, DIP switches are typically toggled manually and held in position. However, they still exhibit mechanical bounce during the transition.

Solutions:
  • Software Delay: Read, wait 50ms, read again
  • State Change Detection: Only act on transitions, not continuous reading
  • Ignore During Setup: For configuration switches, read once at startup

Common Applications

SwitchesRangeApplication
4-bit0-15Device address, simple modes
8-bit0-255Extended addressing, settings
IndividualN/AFeature flags, enable/disable

Use Cases

Combined Demo Concept: 7-Segment + DIP Switch

Demonstration Idea:
Use a 4-bit DIP switch to select a hexadecimal digit (0-F) and display it on the 7-segment display. This demonstrates binary-to-hexadecimal conversion and visual output.

System Operation:
  1. Read 4-bit value from DIP switches (0-15)
  2. Convert to corresponding 7-segment pattern
  3. Display digit (0-9, A-F)
  4. Update display when switch changes
This creates an interactive binary-to-hex learning tool!