Introduction: 2x 7-Segment Display With 3 Pins From Arduino
Ever being bothered by the insufficient pin on your Arduino to create the number of outputs you desire?
Hello everyone, in this instructable I would like to share to you about my idea: driving 2 common cathode 7 segment display that has a total of 20 pins, 18 usable while using only 3 pins from Arduino.
Of course this is no magic, the Arduino does not drive the 7 segment leds directly, this requires additional parts which are shift register and 7 segment driver integrated circuits, namely the famous IC 74HC595N and IC CD4511 respectively.
The idea of employing a 74HC595N shift register is to increase the number of digital outputs depending the number of IC is used. It is usually more than enough. Only 3 pins required to drive a 595N IC and giving out 8 outputs in bits, meaning 8 digital I/Os, or 8 ON/OFFs.
Then, the IC CD4511 is used that it can convert 4 bit binary electrical signal into decimal that drives the 7 segment.
A fritzing file can be obtained at the end of this instructable.
- Power Supply (Phone charger / Battery)
- Arduino Board
- 1kΩ resistor
- x2 CD4511 IC
- x1 74HC595 IC
- x2 Common Cathode 7 segment display
Step 1: Wiring and Placement
Set up the circuit as the picture above.
IC from left to right : 74HC595N ---> CD4511 ---> CD4511
- pin9, pin15 +rail
- pin7, pin12 -rail
- pin2, pin3, pin15 +rail
- pin4, pin7 -rail
Notice in the 2nd picture, there are 2 resistors connected to the lower right corner of the display. The purpose of the resistors is an additional decimal point display for displaying numbers below 1. In this project we will only display integer numbers.
Step 2: More Components Placement
Add a 10uF ceramic capacitor to the shift register as shown. It is okay to connect the capacitor directly to the negative rail since it is the same. I connect this way because it is easier that I won't be bending the capacitor's legs. The value of the capacitor you should find is 104 written on it.
Next, add a potentiometer as shown in the 2nd picture. Any value of potentiometer can be used. I used a 5kΩ pot.
Note that the position of the + and - terminal connected to the potentiometer may affect the displaying results, as later on it might meant the displaying number increases by turning the knob clockwise, reverse the terminal and the number increases by turning the knob counterclockwise. This is a part of the program that can be changed, the concept is voltage dividing and reversing the + - terminal will reverse the results. Though if it does not give out the results you desire you can change the connection rather than the program because it is easier this way.
Step 3: Arduino Wiring
I will be using a different arduino board rather than a UNO R3 board. And I will be using the power supplied from the arduino instead of a battery or external power supply.
Connect the wires as shown,
- Blue wire to pin 11
- Green wire to pin 8
- Yellow wire to pin 12
- Orange wire to pin A0
Step 4: Shift Register to 7seg Driver Wiring
The following steps is getting more complex and might be more confusing. Take a deep breath and clear your mind if you need to.
We will be using 2 sets of wires with different colors to do easy wiring identification. In my case I will be using
- x2 orange wire
- x2 dark blue wire
- x2 green wire
- x2 white wire
Its okay to use your own color preference. Go ahead if you are brave enough to use random or same color of wires and do direct wiring, you'll be an expert if you did it on the first attempt and get the chance to say "they called me a mad man".
One set of color for one CD4511, because the input for CD4511 is 4 bits.
Connect to the first driver as shown (74HC595N | CD4511):
- Q7 | A (pin7 | pin7) White
- Q6 | B (pin6 | pin1) Green
- Q5 | C (pin5 | pin2) Dark Blue
- Q4 | D (pin4 | pin6) Orange
The reason connecting the first driver from the highest number (Q7) is because the program is written to output MSB (most significant bit). To reverse the connection you need to later modify the code into LSB (least significant bit) to get the same results with different setup.
Next, connect the next set of wires as shown in 2nd picture. Don't mind the fact I used 3 sets of wires, I was having insufficient wire length lol.
- Q3 | A (pin3 | pin7) White
- Q2 | B (pin2 | pin1) Green
- Q1 | C (pin1 | pin2) Dark Blue
- Q0 | D (pin0 | pin6) Orange
Step 5: CD4511 Driver to 7 Segment Display
By using the 2nd and 3rd picture as reference, connect the terminals to its respective assigned letters.
The reason I chose not to use different colors to assign to the terminals to the displays is because it is different from connecting the shift register to the driver.
You can play with the connections with the shift register and the driver, its configuration can be different due to its various parameters (coding: MSB/LSB, algorithm; IC placement: left right, right left) that make it flexible and can have many types of possible setups/configs/connections to make it work the same way and most importantly, easy to troubleshoot error, while the connection from the driver to the display is absolute, it has only one configuration/connection to make it work: if it doesn't work, you connected it wrong.
Step 6: Code
Last but not least, upload the code into your arduino board. The code can be found at my GitHub repository : https://github.com/seighton/SR-Drv_7segARDUINO
Test run can be found on my YouTube channel.
If you want it fancy try go for soldering onto a prototype board like I did (first picture on intro).