How to compute voltage across resistor in Python using UliEngineering

You can easily compute the voltage dropped across a resistor using Ohm’s law with the UliEngineering Python library:

voltage_across_resistor.py
from UliEngineering.Electronics.Resistors import *
from UliEngineering.EngineerIO import *

# Compute voltage across 1kΩ resistor at 5mA
voltage = voltage_across_resistor("1k", "5mA")
print(f"Voltage across 1kΩ at 5mA: {format_value(voltage, 'V')}")

# Compute voltage across 100Ω resistor at 33mA
voltage = voltage_across_resistor("100Ω", "33mA")
print(f"Voltage across 100Ω at 33mA: {format_value(voltage, 'V')}")

Example output

voltage_across_resistor_output.txt
Voltage across 1kΩ at 5mA: 5.00 V
Voltage across 100Ω at 33mA: 3.30 V

The voltage is computed using Ohm’s law: $V = I \times R$


Check out similar posts by category: Electronics, Python