Subscribe to My adventures in coding!

## Using arduino uno to show numbers on 7-segment display

I created this last night to understand the display.

Display pins

```12345
|||||
-----

-----
|||||
678910

// Led control
1- Middle
2- Top Left
3- Ground
4- Top
5- Top Right
6- Bottom Left
7- Bottom
8- Ground
9- Bottom Right
10-Decimal Point
```

Now we know what pins are what, lets hook it up to the arduino.

First set your ground rail of your bread board then using a 330 ohm resiter connect the grounds to the pins 3 and 8;
Now we hook up the pins for the leds to the arduino for output.

Arduino pins 1-8 will be used for this.

```Arduino     |   Display
1        |      1
2        |      2
3        |      4
4        |      5
5        |      6
6        |      7
7        |      9
8        |      10

```

Now for the Sketch

```// On board LED
int led = 13;

// Seven Segment Led Display Pins 1-8
int pins[8] = {1, 2, 3, 4, 5, 6, 7, 8};

/*
Numbers and pins
0-9 and dot numbers set with pins 1-8 set either on or off
*/

int numbers[11][8] =
{
{0, 1, 1, 1, 1, 1, 1, 0}, // zero
{0, 0, 0, 1, 0, 0, 1, 0}, // one
{1, 0, 1, 1, 1, 1, 0, 0}, // two
{1, 0, 1, 1, 0, 1, 1, 0}, // three
{1, 1, 0, 1, 0, 0, 1, 0}, // four
{1, 1, 1, 0, 0, 1, 1, 0}, // five
{1, 1, 0, 0, 1, 1, 1, 0}, // six
{0, 0, 1, 1, 0, 0, 1, 0}, // seven
{1, 1, 1, 1, 1, 1, 1, 0}, // eight
{1, 1, 1, 1, 0, 0, 1, 0}, // nine
{0, 0, 0, 0, 0, 0, 0, 1}  // dot
};

void setup()
{
// On board led
pinMode(led, OUTPUT);

//Seven Segment Led pins set to output
for (int i = 0; i<8; i++)
{
pinMode(pins[i], OUTPUT);
}
}

void loop()
{
for (int i = 9; i>0; i--){
showNumber(i); // show 9-1
}

showNumber(10); // Show dot
noLights(1500); // Turn off lights for 1.5 seconds
}

int showNumber(int number)
{
int i; // Initialize i
for (i=0; i<8; i++) // Loop 8 times
{
digitalWrite(pins[i], numbers[number][i]); // Write on or off to pins
}
delay(1000); // Wait 1 second

}

void noLights(int time)
{
int i; // initialize i
for( i=0; i<8; i++)// loop 8 times
{
digitalWrite(pins[i], LOW); // turn off all pins 1-8
}
delay(time);
}

```

Good luck, Let me know if you see something that can be done better, I'm still learning.

### Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

S M T W T F S
12345
6789101112
13141516171819
202122232425 26
2728293031