Pages: [1]   Go Down
Author Topic: 3 x 7 segment LED  (Read 1838 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi guys, i have 3 of 7 segment leds. i would like to connect it to arduino, how can i do that , wil i have to use some circuits ? i don't want to occupy all exits of controller.

thank you
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use 7 pins to drive segments and 3 to drive digits.  That leaves 9 pins of the 19 for other purposes.

Here is code I wrote to show a timer display on a 4-digit 7-segment display.  Because the pulses are so quick (3mS) I didn't use any current limiting resistors.

Code:
#define DIGIT4 14  // LSD
#define DIGIT3 2
#define DIGIT2 3
#define DIGIT1 4  // MSD

// Bit maps for the seven segment display
const unsigned char Segments[] =
{
  0b11000000, // 0
  0b11001111, // 1
  0b10100100, // 2
  0b10000110, // 3
  0b10001011, // 4
  0b10010010, // 5
  0b10010000, // 6
  0b11000111, // 7
  0b10000000, // 8
  0b10000011, // 9
};


// List of digit select lines, least significant digit first
const unsigned char Digits[4] = {
  DIGIT4, DIGIT3, DIGIT2, DIGIT1};


void setup()
{
  for (int i=2; i<15; i++)
  {
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
  }
  digitalWrite(12, HIGH);
  digitalWrite(13, HIGH);
}

void loop()
{
  // Get time since last reset
  unsigned long hundredths = millis() / 10;
  unsigned long seconds = hundredths / 100;
  unsigned long minutes = seconds / 60;
  int hours = minutes / 60;
  int clock;

  // Display minutes:seconds up to 100 minutes, then hours/minutes
if (seconds < 100)
    clock = (seconds % 100) * 100 + (hundredths % 100);
else
if (minutes < 100)
    clock = (minutes % 100) * 100 + (seconds % 60);
  else
    clock = (hours % 100) * 100 + (minutes % 60);

  // Clear all segments before enabling a digit
  for (int s=5; s<14; s++)
  {
    digitalWrite(s,HIGH);
  }

  // Display each digit, right to left
  for (int i=0; i<4; i++)
  {
   
    // Peel a digit off the low end of the number
    int digit = clock % 10;
    clock /= 10;
   
    // Blank the MSD if it is zero
    if (i==3 && digit == 0)
    {
      for (int s=5; s<12; s++)
        digitalWrite(s,HIGH);
    }
    else
    {
      // Display the digit on the seven segments
      unsigned char segments = Segments[digit];
      for (int s=5; s<12; s++)
      {
        digitalWrite(s,segments & 1);
        segments >>= 1;
      }
    }


    if (seconds < 100)
    {
      // Steady decimal point when showing seconds and hundredths
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);

    }
    else
    if (minutes < 100)
    {
      // Steady colon when showing minutes and seconds
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);

    }
    else
    {
      // Make the colon blink each second
      digitalWrite(12, seconds & 1);
      digitalWrite(13, seconds & 1);
    }

    // Turn on the digit briefly
    digitalWrite(Digits[i], HIGH);  // Select one digit
    delay(3);
    digitalWrite(Digits[i], LOW);
  }
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"the pulses are so quick (3mS) I didn't use any current limiting resistors"

Bad engineer, don't go encouraging bad design practices elsewhere.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your time, the last question is how do you connect 3 leds together and to controller, pins?
Thank you very much

You can use 7 pins to drive segments and 3 to drive digits.  That leaves 9 pins of the 19 for other purposes.

Here is code I wrote to show a timer display on a 4-digit 7-segment display.  Because the pulses are so quick (3mS) I didn't use any current limiting resistors.

Code:
#define DIGIT4 14  // LSD
#define DIGIT3 2
#define DIGIT2 3
#define DIGIT1 4  // MSD

// Bit maps for the seven segment display
const unsigned char Segments[] =
{
  0b11000000, // 0
  0b11001111, // 1
  0b10100100, // 2
  0b10000110, // 3
  0b10001011, // 4
  0b10010010, // 5
  0b10010000, // 6
  0b11000111, // 7
  0b10000000, // 8
  0b10000011, // 9
};


// List of digit select lines, least significant digit first
const unsigned char Digits[4] = {
  DIGIT4, DIGIT3, DIGIT2, DIGIT1};


void setup()
{
  for (int i=2; i<15; i++)
  {
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
  }
  digitalWrite(12, HIGH);
  digitalWrite(13, HIGH);
}

void loop()
{
  // Get time since last reset
  unsigned long hundredths = millis() / 10;
  unsigned long seconds = hundredths / 100;
  unsigned long minutes = seconds / 60;
  int hours = minutes / 60;
  int clock;

  // Display minutes:seconds up to 100 minutes, then hours/minutes
if (seconds < 100)
    clock = (seconds % 100) * 100 + (hundredths % 100);
else
if (minutes < 100)
    clock = (minutes % 100) * 100 + (seconds % 60);
  else
    clock = (hours % 100) * 100 + (minutes % 60);

  // Clear all segments before enabling a digit
  for (int s=5; s<14; s++)
  {
    digitalWrite(s,HIGH);
  }

  // Display each digit, right to left
  for (int i=0; i<4; i++)
  {
   
    // Peel a digit off the low end of the number
    int digit = clock % 10;
    clock /= 10;
   
    // Blank the MSD if it is zero
    if (i==3 && digit == 0)
    {
      for (int s=5; s<12; s++)
        digitalWrite(s,HIGH);
    }
    else
    {
      // Display the digit on the seven segments
      unsigned char segments = Segments[digit];
      for (int s=5; s<12; s++)
      {
        digitalWrite(s,segments & 1);
        segments >>= 1;
      }
    }


    if (seconds < 100)
    {
      // Steady decimal point when showing seconds and hundredths
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);

    }
    else
    if (minutes < 100)
    {
      // Steady colon when showing minutes and seconds
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);

    }
    else
    {
      // Make the colon blink each second
      digitalWrite(12, seconds & 1);
      digitalWrite(13, seconds & 1);
    }

    // Turn on the digit briefly
    digitalWrite(Digits[i], HIGH);  // Select one digit
    delay(3);
    digitalWrite(Digits[i], LOW);
  }
}
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6614
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

First, connect all 3 of the 'a' segments together, all 3 of the 'b' segments together, and so on. Each of the 7 (or 8 if using the decimal point) bundles of 3 segments is connected to an Arduino output pin via a current limiting resistor. Total 7 pins and 7 resistors so far (8 of each if using the d.p.).

How you connect the 3 digit connections depends on what current you want to drive them at. If you are happy choosing the current limiting resistors to give 5mA per segment, then you can connect each digit connection direct to an Arduino pin. However, they won't be very bright at 5mA. Otherwise, you need to drive each digit pin from a transistor. Use PNP transistors for common anode displays (emitter to +5v, collector to digit), or NPN transistors for common cathode displays (emitter to ground, collector to digit). Either way, connect a series resistor (1k will do) from each transistor base to an Arduino pin.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, here's a schematic showing 4 segment displays. These would be common cathode type.
This is one of the easiest ways to do it.
If you have common anode, then everythings gets reversed.
The 4 anode get switched thru PNP transistors, and the cathodes are pulled low by the arduino.


* 4x7segment_display.jpg (84.68 KB, 960x720 - viewed 56 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And the Common Anode version...


* 4x7segment_display_PNP.jpg (93.01 KB, 960x720 - viewed 83 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

States
Offline Offline
Newbie
*
Karma: 0
Posts: 2
If its safe to tinker use an Arduino.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What cad software is that?
Logged

Arduino-King

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

expresspcb.com, great for drawing up stuff like this for discussions, or building something that doesn't need a PCB made.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: