Arduino Compatible 4 Digit 7 Segment Display Counter (0000-9999)

4 Digit Arduino based counter is simple project using 4-digit 7 segment common cathode display, Atmega328 chip on board and 2 tactile switches. Projects works with 5V DC. Onboard connector helps to program the Arduino code and boot-loader.


Other Details, Schematic, PCB Layout Available Here

Download Arduino Code

Download PDF Schematic



Arduino Pin Configuration

  1. Display Digit1>D10,Digit2>D11, Digit3>D12, Digit4>D13
  2. Segments A>D2, B>D3, C>D4, D>D5, E>D6, F>D7, G>D8, D9>DP
  3. Tactile Switch 1>A2  Count Up Switch
  4. Tactile Switch 2>A3  Count Down Switch


Note : To use this board as Arduino ATmega328 required Boot-Loader and  then Arduino programing , check the connection bellow for boot loader burning and Arduino code programing.  CN1 connector is provided for both boot loader burning and Arduino code programing.

More Details About Boot Loader

More Details About Arduino Programing


 


Arduino Code Programing ( CN1) Connector

You need a USB-to-serial converter or Arduino UNO without Atmega 328 to program this board. There are pin outs on the board for programming the Atmega328P. You need to connect RX, TX, 5V and GND. Then upload the code to the board with the Arduino software.


Arduino Code 4 Digit Counter ( 0000-9999 Counts)


/*
Arduino Code 4 Digit 7 Segment Display
Counter 0000-9999
Code is modified original code from
www.adeept.com , Author Tom
Arduino Code, Circuit, PCB Layout can be found on our website
www.twovolt.com
*/

int btn1pin=A2; //Set the Analog Pin A2 Switch
int btn2pin=A3; //Set the Analog Pin A3 Switch
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;
int p = 9;
int d4 = 13;
int d3 = 12;
int d2 = 11;
int d1 = 10;

long n = 0;
int x = 100;
int del = 55;
int i = 0;
int j = 1;
int k = 2;
int l = 3;
int data;
void setup()
{
pinMode(btn1pin,INPUT_PULLUP); //Set digital 2 port mode, the INPUT for the input
pinMode(btn2pin,INPUT_PULLUP); //Set digital 2 port mode, the INPUT for the input
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(p, OUTPUT);
}

void loop()
{
int d1,d2,d3,d4;
if(digitalRead(btn1pin)==HIGH) //Detection button interface to low
{
delay(10); //Delay 10ms for the elimination of key leading-edge jitter
if(digitalRead(btn1pin)==HIGH) //Confirm button is pressed
{
if(data>9999)
{
data=9999;
}else{
data = data + 1;
}
}
}
if(digitalRead(btn2pin)==HIGH) //Detection button interface to low
{
delay(10); //Delay 10ms for the elimination of key leading-edge jitter
if(digitalRead(btn2pin)==HIGH) //Confirm button is pressed
{
if(data<=0)
{
data=0;
}else{
data = data – 1;
}
}
}
d1 = data/1000%10; //The one thousand digital data
d2 = data/100%10; //The one hundred digital data
d3 = data/10%10; //Ten-digit data
d4 = data%10; //data of single digit
for(int m=0;m<80;m++){
clearLEDs(); //Turn off all LED lights
pickDigit(1); //Selection of a digital display
pickNumber(d1); //Display digital d1
delayMicroseconds(200);

clearLEDs(); //Turn off all LED lights
pickDigit(2); //Select the first two digital display
pickNumber(d2); //Display digital d2
delayMicroseconds(200);

clearLEDs(); //Turn off all LED lights
pickDigit(3); //Select the first three digital display
//dispDec(3); //Decimal display
pickNumber(d3); //Display digital d3
delayMicroseconds(200);

clearLEDs(); //Turn off all LED lights
pickDigit(4); //Select the first four digital display
pickNumber(d4); //Display digital d4
delayMicroseconds(200);
}
}

void pickDigit(int x) //Defined pickDigit (x), whose role is to open the port dx
{
digitalWrite(d1, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
switch(x)
{
case 1:
digitalWrite(d1, HIGH);
break;
case 2:
digitalWrite(d2, HIGH);
break;
case 3:
digitalWrite(d3, HIGH);
break;
default:
digitalWrite(d4, HIGH);
break;
}
}

void pickNumber(int x) //Defined pickNumber (x), whose role is to display digital x
{
switch(x)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
case 7:
seven();
break;
case 8:
eight();
break;
case 9:
nine();
break;
default:
zero();
break;
}
}

void dispDec(int x) //Decimal point setting Open
{
digitalWrite(p, HIGH);
}

void clearLEDs() //Clear screen
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(p, LOW);
}

void zero() //Define those figures 0 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}

void one() //Define those figures 1 cathode pin switch
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}

void two() //Define those figures 2 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}

void three() //Define those figures 3 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}

void four() //Define those figures 4 cathode pin switch
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void five() //Define those figures 5 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void six() //Define those figures 6 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void seven() //Define those figures 7 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}

void eight() //Define those figures 8 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void nine() //Define those figures 9 cathode pin switch
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}


Leave a Reply

Your email address will not be published. Required fields are marked *