electronics.resistor_color_code

Title : Calculating the resistance of a n band resistor using the color codes

Description :

Resistors resist the flow of electrical current.Each one has a value that tells how strongly it resists current flow.This value’s unit is the ohm, often noted with the Greek letter omega: Ω.

The colored bands on a resistor can tell you everything you need to know about its value and tolerance, as long as you understand how to read them. The order in which the colors are arranged is very important, and each value of resistor has its own unique combination.

The color coding for resistors is an international standard that is defined in IEC 60062.

The number of bands present in a resistor varies from three to six. These represent significant figures, multiplier, tolerance, reliability, and temperature coefficient Each color used for a type of band has a value assigned to it. It is read from left to right. All resistors will have significant figures and multiplier bands. In a three band resistor first two bands from the left represent significant figures and the third represents the multiplier band.

Significant figures - The number of significant figures band in a resistor can vary from two to three. Colors and values associated with significant figure bands - (Black = 0, Brown = 1, Red = 2, Orange = 3, Yellow = 4, Green = 5, Blue = 6, Violet = 7, Grey = 8, White = 9)

Multiplier - There will be one multiplier band in a resistor. It is multiplied with the significant figures obtained from previous bands. Colors and values associated with multiplier band - (Black = 100, Brown = 10^1, Red = 10^2, Orange = 10^3, Yellow = 10^4, Green = 10^5, Blue = 10^6, Violet = 10^7, Grey = 10^8, White = 10^9, Gold = 10^-1, Silver = 10^-2) Note that multiplier bands use Gold and Silver which are not used for significant figure bands.

Tolerance - The tolerance band is not always present. It can be seen in four band resistors and above. This is a percentage by which the resistor value can vary. Colors and values associated with tolerance band - (Brown = 1%, Red = 2%, Orange = 0.05%, Yellow = 0.02%, Green = 0.5%,Blue = 0.25%, Violet = 0.1%, Grey = 0.01%, Gold = 5%, Silver = 10%) If no color is mentioned then by default tolerance is 20% Note that tolerance band does not use Black and White colors.

Temperature Coeffecient - Indicates the change in resistance of the component as a function of ambient temperature in terms of ppm/K. It is present in six band resistors. Colors and values associated with Temperature coeffecient - (Black = 250 ppm/K, Brown = 100 ppm/K, Red = 50 ppm/K, Orange = 15 ppm/K, Yellow = 25 ppm/K, Green = 20 ppm/K, Blue = 10 ppm/K, Violet = 5 ppm/K, Grey = 1 ppm/K) Note that temperature coeffecient band does not use White, Gold, Silver colors.

Sources :

https://www.calculator.net/resistor-calculator.html https://learn.parallax.com/support/reference/resistor-color-codes https://byjus.com/physics/resistor-colour-codes/

Attributes

band_types

multiplier_color_values

significant_figures_color_values

temperature_coeffecient_color_values

tolerance_color_values

valid_colors

Functions

calculate_resistance(→ dict)

Function calculates the total resistance of the resistor using the color codes.

check_validity(→ bool)

Function checks if the input provided is valid or not.

get_band_type_count(→ int)

Function returns the number of bands of a given type in a resistor with n bands

get_multiplier(→ float)

Function returns the multiplier value associated with the color.

get_significant_digits(→ str)

Function returns the digit associated with the color. Function takes a

get_temperature_coeffecient(→ int)

Function returns the temperature coeffecient value associated with the color.

get_tolerance(→ float)

Function returns the tolerance value associated with the color.

Module Contents

electronics.resistor_color_code.calculate_resistance(number_of_bands: int, color_code_list: list) dict

Function calculates the total resistance of the resistor using the color codes. Function takes number_of_bands, color_code_list as input and returns resistance

>>> calculate_resistance(3, ["Black","Blue","Orange"])
{'resistance': '6000Ω ±20% '}
>>> calculate_resistance(4, ["Orange","Green","Blue","Gold"])
{'resistance': '35000000Ω ±5% '}
>>> calculate_resistance(5, ["Violet","Brown","Grey","Silver","Green"])
{'resistance': '7.18Ω ±0.5% '}
>>> calculate_resistance(6, ["Red","Green","Blue","Yellow","Orange","Grey"])
{'resistance': '2560000Ω ±0.05% 1 ppm/K'}
>>> calculate_resistance(0, ["Violet","Brown","Grey","Silver","Green"])
Traceback (most recent call last):
  ...
ValueError: Invalid number of bands. Resistor bands must be 3 to 6
>>> calculate_resistance(4, ["Violet","Brown","Grey","Silver","Green"])
Traceback (most recent call last):
  ...
ValueError: Expecting 4 colors, provided 5 colors
>>> calculate_resistance(4, ["Violet","Silver","Brown","Grey"])
Traceback (most recent call last):
  ...
ValueError: Silver is not a valid color for significant figure bands
>>> calculate_resistance(4, ["Violet","Blue","Lime","Grey"])
Traceback (most recent call last):
  ...
ValueError: Lime is not a valid color
electronics.resistor_color_code.check_validity(number_of_bands: int, colors: list) bool

Function checks if the input provided is valid or not. Function takes number_of_bands and colors as input and returns True if it is valid

>>> check_validity(3, ["Black","Blue","Orange"])
True
>>> check_validity(4, ["Black","Blue","Orange"])
Traceback (most recent call last):
  ...
ValueError: Expecting 4 colors, provided 3 colors
>>> check_validity(3, ["Cyan","Red","Yellow"])
Traceback (most recent call last):
  ...
ValueError: Cyan is not a valid color
electronics.resistor_color_code.get_band_type_count(total_number_of_bands: int, type_of_band: str) int

Function returns the number of bands of a given type in a resistor with n bands Function takes total_number_of_bands and type_of_band as input and returns number of bands belonging to that type in the given resistor

>>> get_band_type_count(3,'significant')
2
>>> get_band_type_count(2,'significant')
Traceback (most recent call last):
  ...
ValueError: 2 is not a valid number of bands
>>> get_band_type_count(3,'sign')
Traceback (most recent call last):
  ...
ValueError: sign is not valid for a 3 band resistor
>>> get_band_type_count(3,'tolerance')
Traceback (most recent call last):
  ...
ValueError: tolerance is not valid for a 3 band resistor
>>> get_band_type_count(5,'temp_coeffecient')
Traceback (most recent call last):
  ...
ValueError: temp_coeffecient is not valid for a 5 band resistor
electronics.resistor_color_code.get_multiplier(color: str) float

Function returns the multiplier value associated with the color. Function takes color as input and returns multiplier value

>>> get_multiplier('Gold')
0.1
>>> get_multiplier('Ivory')
Traceback (most recent call last):
  ...
ValueError: Ivory is not a valid color for multiplier band
electronics.resistor_color_code.get_significant_digits(colors: list) str

Function returns the digit associated with the color. Function takes a list containing colors as input and returns digits as string

>>> get_significant_digits(['Black','Blue'])
'06'
>>> get_significant_digits(['Aqua','Blue'])
Traceback (most recent call last):
  ...
ValueError: Aqua is not a valid color for significant figure bands
electronics.resistor_color_code.get_temperature_coeffecient(color: str) int

Function returns the temperature coeffecient value associated with the color. Function takes color as input and returns temperature coeffecient value.

>>> get_temperature_coeffecient('Yellow')
25
>>> get_temperature_coeffecient('Cyan')
Traceback (most recent call last):
  ...
ValueError: Cyan is not a valid color for temperature coeffecient band
electronics.resistor_color_code.get_tolerance(color: str) float

Function returns the tolerance value associated with the color. Function takes color as input and returns tolerance value.

>>> get_tolerance('Green')
0.5
>>> get_tolerance('Indigo')
Traceback (most recent call last):
  ...
ValueError: Indigo is not a valid color for tolerance band
electronics.resistor_color_code.band_types: dict[int, dict[str, int]]
electronics.resistor_color_code.multiplier_color_values: dict[str, float]
electronics.resistor_color_code.significant_figures_color_values: dict[str, int]
electronics.resistor_color_code.temperature_coeffecient_color_values: dict[str, int]
electronics.resistor_color_code.tolerance_color_values: dict[str, float]
electronics.resistor_color_code.valid_colors: list = ['Black', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Violet', 'Grey', 'White',...