Summary
Highlights
Seven-segment displays are simple and effective for displaying numbers from an Arduino. Each segment is an LED, arranged to form numbers. Most displays include a decimal point, making it eight segments. Displays come in single, two, or four-digit versions and various LED colors and sizes.
Seven-segment displays consist of LEDs arranged in the shape of the number eight. Turning on specific LEDs forms different numbers. There are two main types: common anode and common cathode. In common anode displays, LEDs are turned on by switching digital pins low. In common cathode displays, LEDs are turned on by switching digital pins high. Segments are typically labeled A through G for digits and DP for the decimal point.
Using a common cathode, single-digit 5161AS display, connect both common pins to ground via a 1 kOhm current limiting resistor. Segment A connects to pin 6, B to pin 5, C to pin 2, D to pin 3, E to pin 4, F to pin 7, G to pin 8, and DP to pin 9.
To program a seven-segment display, use the 'sseg' library. Include the library, create an 'sseg' object, and initialize the display in the setup section. Define 'num_digits' (e.g., 1 for single digit), 'digit_pins' (empty for single digit), 'segment_pins' (connecting A-G and DP to Arduino pins), and set 'resistors_on_segments' to true. Set 'hardware_config' to 'COMMON_CATHODE' or 'COMMON_ANODE'. Use the 'begin' function to initialize and 'setBrightness' as needed. In the loop, use 'setNumber' to display a value, and 'refreshDisplay'.
Multi-digit displays differ from single-digit ones as a single pin controls the same segment across all digits. They also have 'digit pins' (D1-D4) which are common terminals for each digit's LEDs. By switching power to these digit pins, individual digits can be turned on or off.
To build a circuit using a four-digit seven-segment display to show thermistor readings: connect one side of a 100 kOhm thermistor to 5V, the other side to a 100 kOhm resistor forming a voltage divider, and the resistor to ground. Connect the voltage divider's midpoint to analog pin A0. For a 5461AS display, each digit pin needs its own 1 kOhm current limiting resistor in series with the Arduino pin.
Initialize the display in the setup section by setting 'num_digits' to 4 and defining the 'digit_pins' array with associated Arduino pins (D1-D4). Define 'segment_pins' for A-G segments and DP, set 'resistors_on_segments' to true, and 'hardware_config' to 'COMMON_CATHODE' or 'COMMON_ANODE'. Use the 'begin' function. In the loop, read the thermistor, convert it to Celsius, and store it in a variable (e.g., TC). Use 'setNumber(TC, 2)' to print the temperature with a decimal point two digits from the right. To avoid flickering, update the display every few hundred milliseconds using a 'millis()' based timer.