Introduction: Driving Multiplexed 7 Segment Display
- In this tutorial I will show you how to drive multiplexed seven segment displays using an Arduino board
Step 1: Components:
- Arduino board - I'm using Arduino Nano but any board with more than 10 digital outputs should do it
- Display - I couldn't find a datasheet for mine but any multiplexable board with BCD input should do it.
- Voltage supply
- You will also need stuff for soldering or a breadboard.
Step 2: Connect Wires
For this project I am using only digital pins. A,B,C,D will be used to set a four bit number, which will be displayed on a digit. 1,2,3,4,5,6 will be used to set, on which digit will the number be displayed. I'm powering the display with a lab voltage supply but it should work on a 5V battery as well. You could make it brighter by increasing the voltage, but I don't recommend it, `cause:
1. If your powering the Arduino board and the display from the same voltage supply (unlike me, I'm using my PC's
USB port to power the board) the voltage could go over the maximum input voltage, and fry your board.
2. If the processor somehow stopps, the over current could burn out the seven segment displays.
Step 3: The Code
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int disppin = 7;
int t = 5; int i, indx=0;
int no[6]; //array containing numbers to be written for each pin
long int no2bdisp =123456; //number to be displayed
void setup() {
pinMode(2, OUTPUT); // D2 A
pinMode(3, OUTPUT); // D3 B
pinMode(4, OUTPUT); // D4 C
pinMode(5, OUTPUT); // D5 D
pinMode(7, OUTPUT); // D7 1
pinMode(8, OUTPUT); // D8 2
pinMode(9, OUTPUT); // D9 3
pinMode(10, OUTPUT); // D10 4
pinMode(11, OUTPUT); // D11 5
pinMode(12, OUTPUT); // D12 6
}
void loop() {
while (1)
{
//*************** Write number on displays ***********************
for (i = 0; i < 6; i++) {
digitalWrite(d, HIGH && (no[i] & B00001000));
digitalWrite(c, HIGH && (no[i] & B00000100));
digitalWrite(b, HIGH && (no[i] & B00000010));
digitalWrite(a, HIGH && (no[i] & B00000001));
digitalWrite(disppin, HIGH);
delay(t);
digitalWrite(disppin, LOW);
disppin++;
if (!(disppin < 13))
disppin = 7;
//*************** Split number to digits ***********************************
while (no2bdisp > 0) {
no[indx] = no2bdisp % 10;
no2bdisp /= 10;
indx++;
}
}
}
}
Step 4: It's Working!
You can change the displayed numbers, by changing the no2bdisp variable.
If the display flashes you need to decrease the time between refreshes (t).
I hope this tutorial was helpful! :)