Resistor color codes and calculations as a Java Maven library

Next step in my book progress, is getting more into the details of hardware components. And as always starting with the smallest most-used ones: resistors!
To be able to fully document this for the book and create a demo application, I started again with creating and sharing a Java library.

Maven repository

A first version is now available on Maven .

Source code

Similar to my other shared libraries, the sources are available on GitHub .

How to use

Resistor color coding

Available as ColorCode.BLACK, ColorCode.BROWN… and includes all values listed in this table:

ColorCodeHEX colorValueMultiplierTolerance (%)Temp. coeff. (ppm/K)
BLACK#0000000250
BROWN#761d1d110Ω1.0100
RED#cc00002100Ω2.050
ORANGE#ffa50031KΩ15
YELLOW#ffff00410KΩ0.025
GREEN#0080005100KΩ0.520
BLUE#0000cc61MΩ0.2510
VIOLET#ee82ee710MΩ0.15
GREY#8080808100MΩ0.251
WHITE#ffffff91GΩ0.0
GOLD#ffd7000.1Ω5.0
SILVER#c0c0c00.01Ω10.0
NONE20.0

Calculate value of a resistor based on 3, 4, 5 or 6 ColorCodes

Example with 3 ColorCodes

ColorValue value3band = Calculate.resistorValue(
        Arrays.asList(ColorCode.ORANGE, ColorCode.ORANGE, ColorCode.BROWN)
);
System.out.println(Convert.toOhmString(value3band.getOhm()));           // Result: 330Ω
System.out.println(value3band.getTolerance() + "%");                    // Result: 20.0%

Example with 6 ColorCodes

ColorValue value6band = Calculate.resistorValue(
        Arrays.asList(
                ColorCode.ORANGE, ColorCode.WHITE, ColorCode.BLACK,
                ColorCode.SILVER, ColorCode.BROWN, ColorCode.RED
        )
);

System.out.println(Convert.toOhmString(value6band.getOhm()));           // Result: 3.9Ω
System.out.println(value6band.getTolerance() + "%");                    // Result: 1.0%
System.out.println(value6band.getTemperatureCoefficient() + "ppm/K");   // Result: 50ppm/K

Calculate required resistor value for a LED

// Calculate.resistorForLed(double sourceVoltage, double ledVoltage, double ledCurrent)
System.out.println(Calculate.resistorForLed(3.3, 2.2, 0.02));           // Result: 55Ω

Calculate total value for resistors in serial or parallel

// Calculate.serial(List<double> values) {
System.out.println(Calculate.serial(Arrays.asList(2D, 5D, 7D)));        // Result: 14Ω

// Calculate.parallel(List<double> values)
System.out.println(Calculate.parallel(Arrays.asList(10D, 2D, 1D)));     // Result: 0.625Ω