Subscribe to Arduino Academy and start learning today for FREE!

Simple Seven Segment LED Displays

Seven Segment LED’s are a common method of displaying data. With 8 datapins, they are also complicated to wire up, as each LED needs a Arduino pin and a resistor. With a library, we can simplify the wiring, and the data display. Typical displays look like the following:

To reduce the number of Arduino connections if we want to use multiple digits, we will connect all the a segments together, all the b segments together, all the c segments, and so on. We will have a data line for each common so we can light up each segment with different data.

Become the Maker you were born to be. Try Arduino Academy for FREE!

So here goes, connect a 330 ohm resistor to Arduino pin 2. then connect the other end of that resistor to segment a on each module. Follow the chart for the other pins.
Arduino pin 2 -> 330 ohm resistor -> all segment a’s
Arduino pin 3 -> 330 ohm resistor -> all segment b’s
Arduino pin 4 -> 330 ohm resistor -> all segment c’s
Arduino pin 5 -> 330 ohm resistor -> all segment d’s
Arduino pin 6 -> 330 ohm resistor -> all segment e’s
Arduino pin 7 -> 330 ohm resistor -> all segment f’s
Arduino pin 8 -> 330 ohm resistor -> all segment g’s
Arduino pin 9 -> 330 ohm resistor -> all segment p’s (decimal Point)
1st module com to Arduino pin 10
2nd module com to Arduino pin 11
etc.
You will need to download and install the library from https://github.com/DeanIsMe/SevSeg
Now the code:

 

#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object

void setup() {
Serial.begin(9600);

byte numDigits = 2; // number of modules
byte digitPins[] = {10,11}; // where your common pins are connected
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; //where your segments pins are connected

sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins); //Use COMMON_CATHODE if your modules use gnd on the common, or COMMON_ANODE if they take positive on the common.
sevseg.setBrightness(90);
}

void loop() {

int d1 = 12; // number you want displayed, usually from a sensor
sevseg.setNumber(d1, 1); //display number, with optional decimal point (1 place)

sevseg.refreshDisplay(); // Must run repeatedly
}

/// END ///

Become the Maker you were born to be. Try Arduino Academy for FREE!


More info at http://playground.arduino.cc/Main/SevenSegmentLibrary
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Archives

0
Would love your thoughts, please comment.x
()
x