Introduction: 7 Segment Display Common Anode Counter Arduino

About: My name is Nour Bouzid
In this instructable, I'm going to show you how to control a 7 segment display ( common ANODE) who would count from 0 to 9.

Step 1: 1. the Cables

Alright, the branching could be pretty tricky when you're dealing with a common anode 7 segment display. For my case, I have a :
KINGBRIGHT SA04-11hwa.
First look for the two anode ports for me it was the 2 and 3. If you don't know how to do that there are two ways to figure out your anode ports you can either look for your 7 segment display datasheet online or you can connect a wire to the grd of the arduino and then put a connect a positive wire and try to find your anodes. When you finally did that here's what I did :
Led1 : pin 3
Led2 : pin 4
Led3 : pin 5
Led4: pin 6
Led5 : pin7
Led6: pin 8
Led7 : pin9
Led8 : pin 10
---------------
ANODE : pin 2 (basically you put the two anodes together and back to pin 2) in the picture my two anodes are the red wires

Step 2: 2. the Code

here's the code for the counting from 0 to 9

---------------------------------------------------------------------------

// 7 bit light with common anode in series from each light

const int ANODE = 2; // common anode pin

const int LED1 = 3; // led 1 going right to left top to bottom

const int LED2 = 4; // pin for led 2

const int LED3 = 5; // pin for led 3

const int LED4 = 6; // pin for led 4

const int LED5 = 7; // pin for led 5

const int LED6 = 8; // pin for led 6

const int LED7 = 9; // pin for led 7

const int LED8 = 10; // pin for led 8

int DELAY = 0; // so it happens only 3 times

void setup() {

pinMode(ANODE, OUTPUT); // common anode is obviously an output

pinMode(LED1, OUTPUT); // led are output for low will be on

pinMode(LED2, OUTPUT); // led 2 is output

pinMode(LED3, OUTPUT); // led 3 is output

pinMode(LED4, OUTPUT); // led 4 is output

pinMode(LED5, OUTPUT); // led 5 is output

pinMode(LED6, OUTPUT); // led 6 is output

pinMode(LED7, OUTPUT); // led 7 is output

pinMode(LED8, OUTPUT); // led 8 is output

}

void loop(){

if (DELAY == 300){

delay(100000);

}

digitalWrite(ANODE, HIGH); // anode is recieving power

digitalWrite(LED1, HIGH); // stops power to led 1

digitalWrite(LED2, HIGH); // stops power to led 2

digitalWrite(LED3, HIGH); // stops power to led 3

digitalWrite(LED4, HIGH); // stops power to led 4

digitalWrite(LED5, HIGH); // stops power to led 5

digitalWrite(LED6, HIGH); // stops power to led 6

digitalWrite(LED7, HIGH); // stops power to led 7

digitalWrite(LED8, HIGH); // stops power to led 8

delay(1000); // delays before starting

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED5, LOW);

digitalWrite(LED6, LOW);

digitalWrite(LED8, LOW);

delay(500); // delays before starting

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED5, HIGH);

digitalWrite(LED6, HIGH);

digitalWrite(LED8, HIGH);

delay(500);

digitalWrite(LED3, LOW);

digitalWrite(LED5, LOW);

delay(500);

digitalWrite(LED3, HIGH);

digitalWrite(LED5, HIGH);

delay(500);

digitalWrite(LED1, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED6, LOW);

digitalWrite(LED4, LOW);

digitalWrite(LED8, LOW);

delay(500);

digitalWrite(LED1, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED6, HIGH);

digitalWrite(LED4, HIGH);

digitalWrite(LED8, HIGH);

delay(500);

digitalWrite(LED1, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

digitalWrite(LED5, LOW);

digitalWrite(LED6, LOW);

delay(500);

digitalWrite(LED1, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED4, HIGH);

digitalWrite(LED5, HIGH);

digitalWrite(LED6, HIGH);

delay(500);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

digitalWrite(LED5, LOW);

delay(500);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED4, HIGH);

digitalWrite(LED5, HIGH);

delay(500);

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED4, LOW);

digitalWrite(LED5, LOW);

digitalWrite(LED6, LOW);

delay(500);

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED4, HIGH);

digitalWrite(LED5, HIGH);

digitalWrite(LED6, HIGH);

delay(500);

digitalWrite(LED2, LOW);

digitalWrite(LED1, LOW);

digitalWrite(LED4, LOW);

digitalWrite(LED5, LOW);

digitalWrite(LED6, LOW);

digitalWrite(LED8, LOW);

delay(500);

digitalWrite(LED2, HIGH);

digitalWrite(LED1, HIGH);

digitalWrite(LED4, HIGH);

digitalWrite(LED5, HIGH);

digitalWrite(LED6, HIGH);

digitalWrite(LED8, HIGH);

delay(500);

digitalWrite(LED1, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED5, LOW);

delay(500);

digitalWrite(LED1, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED5, HIGH);

delay(500);

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

digitalWrite(LED5, LOW);

digitalWrite(LED6, LOW);

digitalWrite(LED8, LOW);

delay(500);

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED4, HIGH);

digitalWrite(LED5, HIGH);

digitalWrite(LED6, HIGH);

digitalWrite(LED8, HIGH);

delay(500);

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

digitalWrite(LED5, LOW);

digitalWrite(LED6, LOW);

delay(500);

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED4, HIGH);

digitalWrite(LED5, HIGH);

digitalWrite(LED6, HIGH);

delay(500);

}

And that's it, good luck. If you have a question comment below , I'll answer as fast as possible