
Digital Object Counter Using 74LS90, 7447, IR Sensor & ESP32/ESP8266
Build a flicker-free digital object counter with a 74LS90 BCD counter, 7447 7-segment decoder, IR obstacle sensor, and ESP32/ESP8266 single-pulse generator. Includes pinouts, wiring table, Arduino code, and the 74LS90 reset fix.

What you will build and learn
Prerequisites
Soldering basic wires, Arduino IDE installed on computer
2. Project Overview
This project demonstrates a reliable digital object counter that combines classic 74-series TTL digital logic with an ESP32 or ESP8266 microcontroller. A 74LS90 decade counter IC counts incoming clock pulses in binary (BCD, 0000 to 1001), and a 7447 BCD-to-7-segment decoder IC converts that 4-bit binary value into decimal digits (0 to 9) on a common-anode 7-segment display.
Why Place an ESP Between the IR Sensor and the 74LS90?
Wiring an IR obstacle module directly to pin 14 (CLK A) of a 74LS90 frequently causes double or triple counts. Cheap IR comparators produce noisy voltage transitions when an object enters at an angle, vibrates, or pauses near the threshold—each brief dip triggers another falling edge on the counter.
Routing the sensor through an ESP solves two problems at once:
- Hardware Bring-Up Mode: The ESP first runs a clean 1 Hz square-wave generator, letting you verify the 74LS90, 7447, and 7-segment display independently before adding the sensor.
- Debounced Single-Pulse Mode: Once verified, the ESP reads the IR sensor, filters edge chatter in software, sends exactly one clean 50 ms falling-edge pulse per object, and waits until the object clears before allowing the next count.
3. System Architecture & Block Diagram
Signal Flow
+-------------------+ +------------------------+ +--------------------+ +-------------------+ +---------------------+
| IR Obstacle | 3.3V | ESP32 / ESP8266 | 3.3V | 74LS90 | 4-bit | 7447 | 7x | 7-Segment Display |
| Sensor Module +------>+ Debounce + Single +------>+ BCD Decade Counter +------>+ BCD to 7-Segment +------>+ (Common-Anode) |
| (Active-LOW OUT) | GPIO13| Falling-Edge Pulse Gen | GPIO4 | (0000 to 1001) | BCD | Decoder IC | 330Ω | Digits 0 to 9 |
+-------------------+ +------------------------+ +--------------------+ +-------------------+ +---------------------+
^
|
Regulated +5V & GND
(Shared GND w/ ESP)
flowchart LR
A[IR Obstacle Sensor<br/>Powered by 3.3V] -->|Active-LOW OUT<br/>GPIO 13 / D7| B[ESP32 / ESP8266<br/>Debounce & 1-Pulse Logic]
B -->|1 Clean Falling Edge<br/>GPIO 4 / D2| C[74LS90<br/>BCD Counter IC]
C -->|QA, QB, QC, QD<br/>4-Bit BCD| D[7447<br/>BCD-to-7-Segment Decoder]
D -->|Segments a-g<br/>via 7x 330Ω| E[Common-Anode<br/>7-Segment Display]
4. Bill of Materials (BOM)
| Component | Qty | Specification / Notes | Role in Circuit |
|---|---|---|---|
| 74LS90 IC | 1 | 14-pin DIP, TTL Decade Counter | Counts falling-edge pulses from 0 to 9 in BCD |
| 7447 IC | 1 | 16-pin DIP, BCD-to-7-Segment Decoder | Decodes 4-bit BCD (A–D) to 7-segment outputs (a–g) |
| 7-Segment Display | 1 | Common-Anode (e.g., 5161BS) | Displays decimal count (0–9). Common-cathode requires 7448 |
| ESP32 or ESP8266 | 1 | ESP32 DevKit / NodeMCU / Wemos D1 Mini | Generates 1 Hz test pulses or debounced single IR pulses |
| IR Obstacle Sensor | 1 | Standard LM393 active-LOW IR module | Detects passing objects |
| 330 Ω Resistors | 7–8 | 1/4 W carbon/metal film | Current limiting for segments a–g (+1 optional for reset pull-down) |
| 0.1 µF Capacitor | 1–2 | 104 ceramic decoupling capacitor | Filters +5 V supply noise across IC power rails |
| 5 V Power Supply | 1 | Regulated 5 V (USB / 7805 regulator) | Powers 74LS90, 7447, and display (do not use 6 V) |
| Breadboard & Jumpers | 1 set | 830-point breadboard + M-M/M-F wires | Circuit prototyping and interconnections |
| Push Button (Optional) | 1 | Tactile SPST switch | Manual counter reset to 0 |
5. IC Pinout Reference & BCD Truth Table
74LS90 (14-Pin DIP) & 7447 (16-Pin DIP) Pinouts
74LS90 (BCD Counter) 7447 (BCD to 7-Segment)
+------U------+ +------U------+
CLK B -| 1 14 |- CLK A B -| 1 16 |- VCC (+5V)
R0(1) -| 2 13 |- NC C -| 2 15 |- f
R0(2) -| 3 12 |- QA (LSB) LT -| 3 14 |- g
NC -| 4 11 |- QD (MSB) BI/RBO -| 4 13 |- a
+5V -| 5 10 |- GND RBI -| 5 12 |- b
R9(1) -| 6 9 |- QB D -| 6 11 |- c
R9(2) -| 7 8 |- QC A -| 7 10 |- d
+-------------+ GND -| 8 9 |- e
+-------------+
BCD-to-Decimal Truth Table
| Decimal Digit | QD (D) | QC (C) | QB (B) | QA (A) | Lit Segments (Common-Anode) |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | a, b, c, d, e, f |
| 1 | 0 | 0 | 0 | 1 | b, c |
| 2 | 0 | 0 | 1 | 0 | a, b, d, e, g |
| 3 | 0 | 0 | 1 | 1 | a, b, c, d, g |
| 4 | 0 | 1 | 0 | 0 | b, c, f, g |
| 5 | 0 | 1 | 0 | 1 | a, c, d, f, g |
| 6 | 0 | 1 | 1 | 0 | c, d, e, f, g |
| 7 | 0 | 1 | 1 | 1 | a, b, c |
| 8 | 1 | 0 | 0 | 0 | a, b, c, d, e, f, g |
| 9 | 1 | 0 | 0 | 1 | a, b, c, f, g |
6. Master Pin-by-Pin Wiring Table
A. 74LS90 Setup (BCD Mod-10 Mode)
- Pin 5 (VCC) -> Breadboard +5V
- Pin 10 (GND) -> Breadboard GND
- Pin 12 (QA) -> Pin 1 (CLK B)
- Pin 14 (CLK A) -> ESP GPIO 4 (ESP8266: D2)
- Pins 2, 3, 6, 7 -> Breadboard GND
B. 74LS90 to 7447 Connections
- Pin 12 (QA) -> Pin 7 (A)
- Pin 9 (QB) -> Pin 1 (B)
- Pin 8 (QC) -> Pin 2 (C)
- Pin 11 (QD) -> Pin 6 (D)
C. 7447 to Display Connections
- Pin 16 -> +5V, Pin 8 -> GND
- Pins 3, 4, 5 (LT, BI/RBO, RBI) -> +5V
- Pins 13, 12, 11, 10, 9, 15, 14 -> Display segments a through g via 330Ω resistors
- Display Common Pin -> Breadboard +5V
D. ESP & IR Sensor Connections
- IR Sensor VCC -> ESP 3V3
- IR Sensor GND -> Common GND
- IR Sensor OUT -> ESP GPIO 13 (ESP8266: D7)
- ESP GPIO 4 (D2) -> 74LS90 Pin 14
- Decoupling: 0.1 µF across 74LS90 Pins 5 & 10
7. Working Principle
- Object Detection: Reflected infrared triggers LM393 comparator, pulling OUT LOW (0V).
- Software Debouncing & Latch-Out: ESP detects edge, verifies after 50ms, sets objectPresent=true, locks out further counts until clear.
- Single Falling-Edge Pulse: ESP pulses GPIO 4 LOW for 50ms, driving 74LS90 clock directly.
- Binary Counting: 74LS90 increments 4-bit BCD output on falling edge.
- Decoding & Display: 7447 decodes BCD to active-LOW segment outputs to display digits 0-9.
8. Source Code (Arduino IDE)
Sketch 1: 01_1Hz_Hardware_Test.ino
const int PULSE_PIN = 4;
void setup() {
pinMode(PULSE_PIN, OUTPUT);
digitalWrite(PULSE_PIN, HIGH);
#ifdef LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
#endif
}
void loop() {
digitalWrite(PULSE_PIN, LOW);
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, HIGH);
#endif
delay(500);
digitalWrite(PULSE_PIN, HIGH);
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, LOW);
#endif
delay(500);
}
Sketch 2: 02_IR_Obstacle_Object_Counter.ino
const int PULSE_PIN = 4;
const int SENSOR_PIN = 13;
const unsigned long DEBOUNCE_MS = 50;
const unsigned long PULSE_MS = 50;
bool objectPresent = false;
void setup() {
pinMode(PULSE_PIN, OUTPUT);
digitalWrite(PULSE_PIN, HIGH);
pinMode(SENSOR_PIN, INPUT_PULLUP);
Serial.begin(115200);
}
void sendOnePulse() {
digitalWrite(PULSE_PIN, LOW);
delay(PULSE_MS);
digitalWrite(PULSE_PIN, HIGH);
}
void loop() {
int sensorState = digitalRead(SENSOR_PIN);
if (sensorState == LOW && !objectPresent) {
delay(DEBOUNCE_MS);
if (digitalRead(SENSOR_PIN) == LOW) {
objectPresent = true;
sendOnePulse();
Serial.println("Object detected -> +1 pulse sent");
}
} else if (sensorState == HIGH && objectPresent) {
delay(DEBOUNCE_MS);
if (digitalRead(SENSOR_PIN) == HIGH) {
objectPresent = false;
}
}
}
9. Troubleshooting & Common Breadboard Pitfalls
- The 10 kΩ Reset Pull-Down Trap: Never use 10 kΩ on 74LS90 pins 2 & 3. Tie directly to GND, or use a 330 Ω pull-down with reset button.
- Display stuck on 0: Check reset pins 2 & 3, confirm shared GND between ESP and breadboard.
- Only toggles 0 and 1: Missing QA (Pin 12) to CLK B (Pin 1) cascade jumper.
- Display completely dark: Ground Pin 3 (LT) to test all segments; verify display is common-anode on +5V.
10. YouTube Short Demonstration
Watch the live demonstration: YouTube Short #OdNpPZEFGeU
Digital Object Counter Using 74LS90, 7447, IR Sensor & ESP32/ESP8266
Build a flicker-free digital object counter with a 74LS90 BCD counter, 7447 7-segment decoder, IR obstacle sensor, and ESP32/ESP8266 single-pulse generator. Includes pinouts, wiring table, Arduino code, and the 74LS90 reset fix.
What you will build and learn
Prerequisites
Soldering basic wires, Arduino IDE installed on computer
2. Project Overview
This project demonstrates a reliable digital object counter that combines classic 74-series TTL digital logic with an ESP32 or ESP8266 microcontroller. A 74LS90 decade counter IC counts incoming clock pulses in binary (BCD, 0000 to 1001), and a 7447 BCD-to-7-segment decoder IC converts that 4-bit binary value into decimal digits (0 to 9) on a common-anode 7-segment display.
Why Place an ESP Between the IR Sensor and the 74LS90?
Wiring an IR obstacle module directly to pin 14 (CLK A) of a 74LS90 frequently causes double or triple counts. Cheap IR comparators produce noisy voltage transitions when an object enters at an angle, vibrates, or pauses near the threshold—each brief dip triggers another falling edge on the counter.
Routing the sensor through an ESP solves two problems at once:
- Hardware Bring-Up Mode: The ESP first runs a clean 1 Hz square-wave generator, letting you verify the 74LS90, 7447, and 7-segment display independently before adding the sensor.
- Debounced Single-Pulse Mode: Once verified, the ESP reads the IR sensor, filters edge chatter in software, sends exactly one clean 50 ms falling-edge pulse per object, and waits until the object clears before allowing the next count.
3. System Architecture & Block Diagram
Signal Flow
+-------------------+ +------------------------+ +--------------------+ +-------------------+ +---------------------+
| IR Obstacle | 3.3V | ESP32 / ESP8266 | 3.3V | 74LS90 | 4-bit | 7447 | 7x | 7-Segment Display |
| Sensor Module +------>+ Debounce + Single +------>+ BCD Decade Counter +------>+ BCD to 7-Segment +------>+ (Common-Anode) |
| (Active-LOW OUT) | GPIO13| Falling-Edge Pulse Gen | GPIO4 | (0000 to 1001) | BCD | Decoder IC | 330Ω | Digits 0 to 9 |
+-------------------+ +------------------------+ +--------------------+ +-------------------+ +---------------------+
^
|
Regulated +5V & GND
(Shared GND w/ ESP)
flowchart LR
A[IR Obstacle Sensor<br/>Powered by 3.3V] -->|Active-LOW OUT<br/>GPIO 13 / D7| B[ESP32 / ESP8266<br/>Debounce & 1-Pulse Logic]
B -->|1 Clean Falling Edge<br/>GPIO 4 / D2| C[74LS90<br/>BCD Counter IC]
C -->|QA, QB, QC, QD<br/>4-Bit BCD| D[7447<br/>BCD-to-7-Segment Decoder]
D -->|Segments a-g<br/>via 7x 330Ω| E[Common-Anode<br/>7-Segment Display]
4. Bill of Materials (BOM)
| Component | Qty | Specification / Notes | Role in Circuit |
|---|---|---|---|
| 74LS90 IC | 1 | 14-pin DIP, TTL Decade Counter | Counts falling-edge pulses from 0 to 9 in BCD |
| 7447 IC | 1 | 16-pin DIP, BCD-to-7-Segment Decoder | Decodes 4-bit BCD (A–D) to 7-segment outputs (a–g) |
| 7-Segment Display | 1 | Common-Anode (e.g., 5161BS) | Displays decimal count (0–9). Common-cathode requires 7448 |
| ESP32 or ESP8266 | 1 | ESP32 DevKit / NodeMCU / Wemos D1 Mini | Generates 1 Hz test pulses or debounced single IR pulses |
| IR Obstacle Sensor | 1 | Standard LM393 active-LOW IR module | Detects passing objects |
| 330 Ω Resistors | 7–8 | 1/4 W carbon/metal film | Current limiting for segments a–g (+1 optional for reset pull-down) |
| 0.1 µF Capacitor | 1–2 | 104 ceramic decoupling capacitor | Filters +5 V supply noise across IC power rails |
| 5 V Power Supply | 1 | Regulated 5 V (USB / 7805 regulator) | Powers 74LS90, 7447, and display (do not use 6 V) |
| Breadboard & Jumpers | 1 set | 830-point breadboard + M-M/M-F wires | Circuit prototyping and interconnections |
| Push Button (Optional) | 1 | Tactile SPST switch | Manual counter reset to 0 |
5. IC Pinout Reference & BCD Truth Table
74LS90 (14-Pin DIP) & 7447 (16-Pin DIP) Pinouts
74LS90 (BCD Counter) 7447 (BCD to 7-Segment)
+------U------+ +------U------+
CLK B -| 1 14 |- CLK A B -| 1 16 |- VCC (+5V)
R0(1) -| 2 13 |- NC C -| 2 15 |- f
R0(2) -| 3 12 |- QA (LSB) LT -| 3 14 |- g
NC -| 4 11 |- QD (MSB) BI/RBO -| 4 13 |- a
+5V -| 5 10 |- GND RBI -| 5 12 |- b
R9(1) -| 6 9 |- QB D -| 6 11 |- c
R9(2) -| 7 8 |- QC A -| 7 10 |- d
+-------------+ GND -| 8 9 |- e
+-------------+
BCD-to-Decimal Truth Table
| Decimal Digit | QD (D) | QC (C) | QB (B) | QA (A) | Lit Segments (Common-Anode) |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | a, b, c, d, e, f |
| 1 | 0 | 0 | 0 | 1 | b, c |
| 2 | 0 | 0 | 1 | 0 | a, b, d, e, g |
| 3 | 0 | 0 | 1 | 1 | a, b, c, d, g |
| 4 | 0 | 1 | 0 | 0 | b, c, f, g |
| 5 | 0 | 1 | 0 | 1 | a, c, d, f, g |
| 6 | 0 | 1 | 1 | 0 | c, d, e, f, g |
| 7 | 0 | 1 | 1 | 1 | a, b, c |
| 8 | 1 | 0 | 0 | 0 | a, b, c, d, e, f, g |
| 9 | 1 | 0 | 0 | 1 | a, b, c, f, g |
6. Master Pin-by-Pin Wiring Table
A. 74LS90 Setup (BCD Mod-10 Mode)
- Pin 5 (VCC) -> Breadboard +5V
- Pin 10 (GND) -> Breadboard GND
- Pin 12 (QA) -> Pin 1 (CLK B)
- Pin 14 (CLK A) -> ESP GPIO 4 (ESP8266: D2)
- Pins 2, 3, 6, 7 -> Breadboard GND
B. 74LS90 to 7447 Connections
- Pin 12 (QA) -> Pin 7 (A)
- Pin 9 (QB) -> Pin 1 (B)
- Pin 8 (QC) -> Pin 2 (C)
- Pin 11 (QD) -> Pin 6 (D)
C. 7447 to Display Connections
- Pin 16 -> +5V, Pin 8 -> GND
- Pins 3, 4, 5 (LT, BI/RBO, RBI) -> +5V
- Pins 13, 12, 11, 10, 9, 15, 14 -> Display segments a through g via 330Ω resistors
- Display Common Pin -> Breadboard +5V
D. ESP & IR Sensor Connections
- IR Sensor VCC -> ESP 3V3
- IR Sensor GND -> Common GND
- IR Sensor OUT -> ESP GPIO 13 (ESP8266: D7)
- ESP GPIO 4 (D2) -> 74LS90 Pin 14
- Decoupling: 0.1 µF across 74LS90 Pins 5 & 10
7. Working Principle
- Object Detection: Reflected infrared triggers LM393 comparator, pulling OUT LOW (0V).
- Software Debouncing & Latch-Out: ESP detects edge, verifies after 50ms, sets objectPresent=true, locks out further counts until clear.
- Single Falling-Edge Pulse: ESP pulses GPIO 4 LOW for 50ms, driving 74LS90 clock directly.
- Binary Counting: 74LS90 increments 4-bit BCD output on falling edge.
- Decoding & Display: 7447 decodes BCD to active-LOW segment outputs to display digits 0-9.
8. Source Code (Arduino IDE)
Sketch 1: 01_1Hz_Hardware_Test.ino
const int PULSE_PIN = 4;
void setup() {
pinMode(PULSE_PIN, OUTPUT);
digitalWrite(PULSE_PIN, HIGH);
#ifdef LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
#endif
}
void loop() {
digitalWrite(PULSE_PIN, LOW);
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, HIGH);
#endif
delay(500);
digitalWrite(PULSE_PIN, HIGH);
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, LOW);
#endif
delay(500);
}
Sketch 2: 02_IR_Obstacle_Object_Counter.ino
const int PULSE_PIN = 4;
const int SENSOR_PIN = 13;
const unsigned long DEBOUNCE_MS = 50;
const unsigned long PULSE_MS = 50;
bool objectPresent = false;
void setup() {
pinMode(PULSE_PIN, OUTPUT);
digitalWrite(PULSE_PIN, HIGH);
pinMode(SENSOR_PIN, INPUT_PULLUP);
Serial.begin(115200);
}
void sendOnePulse() {
digitalWrite(PULSE_PIN, LOW);
delay(PULSE_MS);
digitalWrite(PULSE_PIN, HIGH);
}
void loop() {
int sensorState = digitalRead(SENSOR_PIN);
if (sensorState == LOW && !objectPresent) {
delay(DEBOUNCE_MS);
if (digitalRead(SENSOR_PIN) == LOW) {
objectPresent = true;
sendOnePulse();
Serial.println("Object detected -> +1 pulse sent");
}
} else if (sensorState == HIGH && objectPresent) {
delay(DEBOUNCE_MS);
if (digitalRead(SENSOR_PIN) == HIGH) {
objectPresent = false;
}
}
}
9. Troubleshooting & Common Breadboard Pitfalls
- The 10 kΩ Reset Pull-Down Trap: Never use 10 kΩ on 74LS90 pins 2 & 3. Tie directly to GND, or use a 330 Ω pull-down with reset button.
- Display stuck on 0: Check reset pins 2 & 3, confirm shared GND between ESP and breadboard.
- Only toggles 0 and 1: Missing QA (Pin 12) to CLK B (Pin 1) cascade jumper.
- Display completely dark: Ground Pin 3 (LT) to test all segments; verify display is common-anode on +5V.
10. YouTube Short Demonstration
Watch the live demonstration: YouTube Short #OdNpPZEFGeU

