loading
I would just like to show a few different methods of connecting 7 segment LED displays to an Arduino or Atmega 328 IC. They are only simple counter codes either automatically counting via the code or incremented / decremented via a pair of push button switches or a potentiometer . I have used 220 Ω resistors in all these circuits but you would be advised to calculate the correct ones required for the particular 7 segment displays that your are using. This will ensure that you do not damage the IO pins of the 328 IC. The constraints to these maximum currents, courtesy of
http://www.gammon.com.au/forum/?id=11473
are -
- The IO pins have an absolute maximum rating of 40 mA per pin.
- Also the following groups of pins should not have more than 100 mA drawn from them
* Digital pins 0 to 4
* Digital pins 5 to 1
* Analog pins A0 to A5
- In addition to that, the entire processor chip has a maximum rating of 200 mA current consumption.

The 7 segment LED displays are common cathode and the shift register is a 74HC595. I have included a photo of the 7 segment LED from the front showing the relationship between the pin numbers and the corresponding LED segment that the pin controls.



Step 1:

  1. Directly from Arduino / Atmega 328
  2. Via shift register from Arduino / Atmega 328
  3. Directly from Arduino / Atmega 328 with direct port manipulation
  4. Multiplexed via shift register from Arduino / Atmega 328 / Pushbutton counter
  5. Multiplexed via shift register from Arduino / Atmega 328 / Potentiometer counter

1 - Directly from Arduino / Atmega 328
Counts automatically from zero to nine and then repeats


Code
// Thanks to Grumpy Mike http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
// LED Segment allocation within byte = {DP ABCDEFG }
int pins [] = {2, 3, 4, 5, 6, 7, 8, 9 }; // pin 9 allocated to DP but not used (first element of binary array in char tenCode)
int digit[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int counter = 0; // initialise counter as zero
int timer = 1000; // delay timer interval
char tenCode[] = {B01111110, B00110000, B01101101, B01111001, B00110011, B01011011, B01011111, B01110000, B01111111, B01111011 };
void setup()
{
for(int i = 0; i < 8; i++) // set digital pins as OUTPUTS
pinMode(pins[i], OUTPUT);
}
void loop()
{
for(int j = 0; j < 10; j++)
{
displayEleven(digit[j]);
delay(timer);
}
}
void displayEleven(int num)
{
int mask = 1;
for(int i = 0; i < 8; i++)
{
if((mask & tenCode[num]) == 0)
digitalWrite(pins[i], LOW);
else digitalWrite(pins[i], HIGH);
mask = mask << 1;
}
}


Great Instructable Pedro!

About This Instructable