Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
Diffused rectangular through-hole LEDs

Build a Custom LED Bargraph with Rectangular LEDs: Alignment, Scaling and Stable Readings

A row of rectangular LEDs can make a compact, readable level display without committing to the fixed spacing and colour arrangement of a packaged bargraph. Individual parts let you choose the number of segments, leave gaps between groups or mark selected ranges with different colours.

The PMD Way diffused rectangular LEDs are listed in several colours and two housing sizes. Choose the actual variant before drawing a PCB or front-panel opening. The outer dimensions, lead spacing and useful illuminated face are different measurements, and each affects the finished display.

Decide what each segment represents

Start with the quantity being displayed: position, temperature, charge estimate, percentage or another measured value. Write the units beside the display rather than expecting the LED arrangement to explain itself. A ten-segment row does not inherently mean ten per cent per segment.

Choose bar mode or dot mode deliberately. In bar mode, all positions up to the current level illuminate. In dot mode, one position indicates the level. A bar is often easier to read at a glance, while a dot can reduce normal power consumption. Include an explicit indication for a missing or invalid measurement so it cannot be confused with a valid minimum.

For a ten-segment percentage display, one possible definition lights the first segment at 10%, the second at 20% and the last at 100%. Another design might use the first segment to mean any non-zero value. Both are reasonable, but they differ near zero. Document the chosen rule before writing the conversion code.

Make a mechanical sample before a full board

Fit a few LEDs into a trial piece of board or panel material. Check body clearance, lead pitch, viewing angle and whether the face sits at the desired height. Do not use an illustration's apparent proportions as a substitute for measuring a supplied sample and checking its drawing.

Calculate the row length from the intended centre spacing. For example, ten bodies with a hypothetical 5 mm width and 1 mm gap occupy 10 × 5 + 9 × 1 = 59 mm. There are only nine internal gaps. Add the end clearances and any mounting border separately.

Use a jig to hold the faces at a consistent height while assembling the row. Kingbright's through-hole LED handling notes explain why leads should not transmit damaging forming forces into the package. Apply the actual component's mechanical and soldering guidance rather than borrowing another manufacturer's numerical limits.

If a single long front-panel slot makes light leak between positions, test dividers or separate apertures. Black internal surfaces can help distinguish unlit positions, but judge the result with the real panel material and ambient lighting.

Plan every current path

With a basic voltage-driven circuit, give each LED its own series resistor. A constant-current driver is another option when its output arrangement and voltage headroom suit the LEDs. Do not power a bare LED directly from a supply described as matching its forward voltage.

Calculate resistors using the selected colour's forward-voltage range at the intended current, the supply tolerance and the driver's output drop. A single catalogue voltage covering several colours is insufficient for a dependable design. Different colours can require different resistor values to achieve appropriate current and useful visual balance.

As a load-budget example, ten segments operating at 3 mA each require 30 mA when the full bar is on, before adding controller consumption. A dot display normally uses one branch, but startup tests or software faults may illuminate more. Ensure the driver, wiring and supply handle every permitted state.

If using microcontroller pins directly, check the exact board's source or sink ratings and combined pin limits. Arduino's digital-pin documentation introduces these output behaviours. A device's absolute maximum current is not an appropriate normal design target.

Separate measurement from display conversion

Keep raw acquisition, validity checks, calibration and segment selection as separate steps. This makes it possible to test the display with known artificial values before connecting a real sensor.

The official Arduino calibration example demonstrates using observed input limits to scale a reading. For an instrument, decide how those limits will be established and retained. Automatically treating the first few seconds after every startup as a valid calibration period may be wrong if the sensor never reaches its endpoints.

For a linear mapping, calculate a normalised fraction from the valid reading and the calibrated lower and upper values. Reject an invalid or zero calibration span before division, then constrain valid display values to the intended range. Use arithmetic types that will not overflow during intermediate multiplication.

Stop the boundary segment from chattering

A noisy reading near 50% can repeatedly switch the fifth segment on and off. Averaging can reduce fluctuations, but it also changes response time. Arduino's analogue smoothing example shows a running-average approach; select the sample rate and window for the actual signal rather than copying a sample count without considering time.

Hysteresis solves a different part of the problem. For an illustrative 50% boundary, turn the segment on when the value reaches 51%, then keep it on until the value falls below 49%. The displayed state now depends on both the measurement and its previous state. Choose a band that is wider than troublesome noise but small enough for the application's resolution.

Test slow upward and downward sweeps through every boundary. Also test a sudden jump from minimum to maximum, because code that changes only one segment per update can lag unnecessarily behind a large real change.

Verify the row as a complete instrument

Run a walking-segment pattern to catch wiring-order mistakes. Then display the minimum, midpoint, maximum and invalid-data states. Measure supply current and inspect the display from the intended distance with all segments illuminated.

Keep labels aligned with the correct thresholds and check that coloured sections remain understandable without relying entirely on colour. Save the scaling rule, hysteresis values and physical segment map with the project.

The rectangular LED collection offers alternative shapes for this kind of custom display. Changing the package or colour should trigger a fresh fit and electrical check. The goal is a bargraph whose mechanical layout, numerical scale and behaviour all tell the same story.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat