CD4017 Decade Counter IC Documentation
The CD4017 is a 5-stage Johnson decade counter integrated circuit (IC) used for counting and decoding applications. It is a popular IC used in digital circuits, microcontrollers, and other electronic devices. The CD4017 can be used to generate a binary count from 0 to 9, making it suitable for various applications such as clocks, timers, and sequencers.
The CD4017 IC has 16 pins, with the following pinout:
| Pin Number | Pin Name | Function |
| --- | --- | --- |
| 1 | VCC | Positive Supply Voltage |
| 2 | Q0 | Output (Binary 0) |
| 3 | Q1 | Output (Binary 1) |
| 4 | Q2 | Output (Binary 2) |
| 5 | Q3 | Output (Binary 3) |
| 6 | Q4 | Output (Binary 4) |
| 7 | Q5 | Output (Binary 5) |
| 8 | Q6 | Output (Binary 6) |
| 9 | Q7 | Output (Binary 7) |
| 10 | Q8 | Output (Binary 8) |
| 11 | Q9 | Output (Binary 9) |
| 12 | CLK | Clock Input |
| 13 | CLR | Clear Input (Active Low) |
| 14 | ENABLE | Enable Input (Active High) |
| 15 | GND | Ground |
| 16 | VCC | Positive Supply Voltage |
### Example 1: Basic Decade Counter using CD4017
In this example, we will use the CD4017 to generate a decimal count from 0 to 9. We will connect the clock input (CLK) to a push-button, and the outputs (Q0-Q9) to LEDs to display the count.
Connect the push-button to pin 12 (CLK) and the LEDs to pins 2-11 (Q0-Q9). Connect VCC to +5V and GND to GND.
```c
const int clockPin = 2; // Clock input
const int resetPin = 3; // Clear input
const int enablePin = 4; // Enable input
void setup() {
pinMode(clockPin, INPUT);
pinMode(resetPin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(resetPin, HIGH); // Initialize clear input to high
digitalWrite(enablePin, HIGH); // Initialize enable input to high
}
void loop() {
if (digitalRead(clockPin) == LOW) {
count++;
if (count > 9) {
count = 0;
}
delay(50); // Debounce time
}
// Display count on LEDs
if (count == 0) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
...
} else if (count == 1) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
...
}
...
}
```
### Example 2: CD4017 as a Sequencer
In this example, we will use the CD4017 to sequence a series of events. We will connect the clock input (CLK) to a timer circuit, and the outputs (Q0-Q9) to relays that control different loads.
Connect the timer circuit to pin 12 (CLK) and the relays to pins 2-11 (Q0-Q9). Connect VCC to +5V and GND to GND.
```c
const int clockPin = 2; // Clock input
const int relayPins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11}; // Relay pins
void setup() {
pinMode(clockPin, INPUT);
for (int i = 0; i < 9; i++) {
pinMode(relayPins[i], OUTPUT);
}
}
void loop() {
static int sequence = 0;
if (digitalRead(clockPin) == LOW) {
sequence++;
if (sequence > 9) {
sequence = 0;
}
// Sequence the relays
for (int i = 0; i < 9; i++) {
if (i == sequence) {
digitalWrite(relayPins[i], HIGH);
} else {
digitalWrite(relayPins[i], LOW);
}
}
delay(1000); // Time between sequence steps
}
}
```
Note: These examples are for illustration purposes only and may require additional components and modifications to work in a real-world application.