Connecting Two 74HC595 ICs to Control a 4-Digit 7-Segment Display with NodeMCU ESP8266
Circuit Explanation
Components Needed:
- 2 x 74HC595 Shift Registers
- 1 x 4-Digit 7-Segment Display (Common Cathode)
- 1 x NodeMCU ESP8266
- Jumper Wires
- Resistors (optional: 220Ω for current limiting on 7-segment segments)
Circuit Connections:
The following steps outline the connections between the **NodeMCU ESP8266**, **74HC595 ICs**, and the **7-segment display**:
- NodeMCU to 74HC595 (IC1 and IC2):
- DATA_PIN (D7) → Pin 14 (DS) on IC1
- CLOCK_PIN (D6) → Pin 11 (SH_CP) on IC1 and IC2
- LATCH_PIN (D5) → Pin 12 (ST_CP) on IC1 and IC2
- Pin 10 (MR) → Connect to VCC to disable reset on both ICs
- Pin 13 (OE) → Connect to GND to enable outputs on both ICs
- Pin QH' (Pin 9 of IC1) → Pin 14 (DS) of IC2 to pass data
- 74HC595 to 7-Segment Display:
- QA–QH (Pin 15–Pin 7) of IC1 and IC2 connect to the 7-segment display's segments (a–g)
- The common cathode pins of the 7-segment digits are connected to GND
Explanation of Shift Register Pins:
- Pin 14 (DS)
Code Explanation:
Here is a simple example of how you would use JavaScript to control the segments of the 7-segment display:
#include "Arduino.h" // REPLACE " with <> mean write Arduino.h in <>
// Pin definitions for 74HC595
#define DATA_PIN D7 // DS pin of first 74HC595
#define CLOCK_PIN D6 // SH_CP (Shift Clock) pin
#define LATCH_PIN D5 // ST_CP (Latch Clock) pin
// Segment map for digits 0-9 (common cathode)
const uint8_t segmentMap[] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111 // 9
};
// Digit control map (only one digit is active at a time)
const uint8_t digitMap[] = {
0b0001, // Activate DIG1
0b0010, // Activate DIG2
0b0100, // Activate DIG3
0b1000 // Activate DIG4
};
void setup() {
// Set up pins for 74HC595
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
}
void loop() {
// Example: Display 1234
int numberToDisplay = 1234;
displayNumber(numberToDisplay);
}
// Function to display a number
void displayNumber(int number) {
for (int digit = 0; digit < 4; digit++) {
// Extract the specific digit
int currentDigit = (number / int(pow(10, digit))) % 10;
// Send segment data to first 74HC595
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, segmentMap[currentDigit]);
// Send digit control data to second 74HC595
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, digitMap[digit]);
// Latch the data
digitalWrite(LATCH_PIN, LOW);
digitalWrite(LATCH_PIN, HIGH);
// Small delay to prevent flickering
delay(5);
}
}
0 Comments