10-Segment LED kit Landing Page


Overview

These nifty bargraph modules consist of 10 individual LEDs in a convenient 20-pin DIP (Dual Inline Plastic) package. You get four modules, one of each color (red, yellow, green, and blue), and enough resistors to light up every last one of them.

Requirements

Along with what's provided in the kit, you will need the following for this guide:

How it Works

Each module contains 10 independent LEDs. The pins are arranged so that the anode (positive) pins are on one side of the module, and the cathode (negative) pins are directly opposite. Since the packages are 0.3" wide, just like standard DIP ICs, they're easy to place in the center of a breadboard with the legs straddling the center gap. Pin 1 is indicated by a slight bevel on that corner of the package. (TIP: there may be a thin plastic film protecting the top of the module that you can peel off for a more crisp appearance).

As with normal LEDs, each of the 10 LEDs in the bargraph requires a series resistor to limit the current flowing through the LED. The kit comes with fifty 330-Ohm resistors, enough to light all of the LEDs in the kit.

connection diagram

Pin layout and typical connection (only the first LED is shown)

How to Use it

Hardware

Wiring the bargraph to an Arduino, or any other microcontroller, is pretty straightforward. Using a breadboard and some jumper wires, connect each Arduino outputs (0-9) to the bargraph's anode pins (A-J in the schematic below). Then connect the cathode pins to ground with a 330Ohm resistor. Don't forget the resistor on any of the LEDs. Otherwise you may reduce the life of one or more of the LEDs, and no one wants a bargraph that is missing an segment.

Firmware

The below Arduino code shows a few ways to directly drive these bargraphs. Hook everything up, upload the sketch, and see what happens. (If nothing happens, make sure the bargraph module is in the correct orientation, and that ground is connected back to a ground pin on the Arduino). Later on when you need to drive these with your own code, you can reuse these functions.

 

// LED bargraph demo code
// ...in which we provide a few functions to drive a 10-segment LED bargraph
// Mike Grusin, SparkFun Electronics
// This code is completely free to use for your purposes

// Hardware setup
// connect Arduino digital pins 0-9 to LED bargraph pins 1-10
// connect LED pins 11-20 via 330-Ohm resistors to ground

void setup() 
{
  int pin;
  
  // set pins 0 to 9 as outputs
  for (pin = 0; pin <= 9; pin++)
  {
    pinMode(pin,OUTPUT);
  }
}

void loop()
{
  int number;
  
// exercise lightOne() up and down

  for (number = 1; number <= 10; number++)
  {
    lightOne(number);
    delay(250);
  }
  
  for (number = 10; number >= 1; number--)
  {
    lightOne(number);
    delay(250);
  }

// exercise barGraph() up and down

  for (number = 1; number <= 10; number++)
  {
    barGraph(number);
    delay(250);
  }
  
  for (number = 10; number >= 1; number--)
  {
    barGraph(number);
    delay(250);
  }

// exercise binary() up and down

  for (number = 0; number <= 1023; number++)
  {
    binary(number);
    delay(10);
  }
  
  for (number = 1023; number >= 0; number--)
  {
    binary(number);
    delay(10);
  }
}

void lightOne(int number)
// input is a number from 0 to 10
// lights only that LED on the bargraph
// (0 lights no LEDs)
{
  int pin;

  for (pin = 0; pin <= 9; pin++)
  {
    if (number-1 == pin)
    {
      digitalWrite(pin,HIGH);
    }
    else
    {
      digitalWrite(pin,LOW);
    }
  }
}

void barGraph(int number)
// input is a number from 0 to 10
// lights that LED and below on the bargraph
// (0 lights no LEDs)
{
  int pin;

  for (pin = 0; pin <= 9; pin++)
  {
    if (number-1 >= pin)
    {
      digitalWrite(pin,HIGH);
    }
    else
    {
      digitalWrite(pin,LOW);
    }
  }
}

void binary(int number)
// input is a number from 0 to 1023 (10 bits)
// if a bit is '1' in that number, the corresponding LED is lit, otherwise it is off
{
  int pin;

  for (pin = 0; pin <= 9; pin++)
  {
    if (number & (1 << pin)) // check if bit position 'pin' in 'number' is a 1 or not
    {
      digitalWrite(pin,HIGH); // it's a 1!
    }
    else
    {
      digitalWrite(pin,LOW); // it's a 0!
    }
  }
}

One thing you'll notice when driving these displays is that you can quickly run out of pins when each pin is dedicated to a single LED. To drive more LEDs with fewer pins, take a look at shift registers, which let you use the Arduino's Synchronous Serial Interface to control additional external output pins.

Resources

Conclusion

If you have any questions or suggestions, don't hesitate to contact us at techsupport@sparkfun.com. Have fun with your new displays!

Comments 0 comments