Today we are going to create a project with 7-segment LED 2-digit by using Arduino UNO, include the wiring and coding. Now to see this project step by step:
Figure 1: 7-Segment 2-digit 10-pins |
Project Requirement:
- Arduino UNO
- Breadboard
- Jump Wire
- 7-Segment 2-Digit 10-pins LED
1. Understand the segments in 7-Segment LED
7-Segment LED has 7 segments LED to display the number from Zero to Nine for each one digit. Each segment has is own variable and work independently. See the figure 2 below:
Figure 2: 7 Segments and Binary Code |
To set the 7-Segment LED with binary code, you have to write the code sequence from a-g and left to right with start up binary header "0b".
Figure 3.7-segment 2-digit 10-pins |
Figure 3 show the 7-segment 2-digit 10-pins, how to set each pin on this LED.
a, b, c, d, e, f and g are not on order, so please carefully in wiring. Otherwise your LED display will not show the number you want.
"ds1" is the power pin to support digit 1 on the right side and "ds2" is the power pin to support digit 2 on the left side. "dp" is point pin next to the digit buttom.
Make sure you have connected with the right pin of Arduino and 7-Segment LED.
2. Circuit Wiring
Set Arduino UNO digital pin from 2 to 8 are the pins to control the 7-Segment display. Arduino UNO pin 12 & 13 are the switch power for the two digits on 7-Segment LED.
Figure 4. Arduino UNO and 7-Segment Wiring |
3. Coding
- int digit[10] = {0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b11111111, 0b1101111};
- int digit1, digit2;
- void setup()
- {
- for (int i = 2; i < 9; i++)
- {
- pinMode(i, OUTPUT);
- }
- pinMode(12, OUTPUT);
- pinMode(13, OUTPUT);
- }
- void loop() {
- for (int j = 0; j <= 99; j++)
- {
- digit2 = j / 10;
- digit1 = j % 10;
- for ( int k = 0; k < 20; k++)
- {
- digitalWrite(12, HIGH);
- digitalWrite(13, LOW);
- dis(digit2);
- delay(10);
- digitalWrite(13, HIGH);
- digitalWrite(12, LOW);
- dis(digit1);
- delay(10);
- }
- }
- }
- void dis(int num)
- {
- for (int i = 2; i < 9; i++)
- {
- digitalWrite(i, bitRead(digit[num], i - 2));
- }
- }
Test the Project
You will counter from 00 to 99 and loop this count on you 7-Segment LED.
Figure 5. Testing |
Now let enjoy you day guys, leave you comment below this post for you idea in this project.
Thank!!!