How to compute current through resistor in Python using UliEngineering

You can easily compute the current flowing through a resistor using Ohm’s law with the UliEngineering Python library:

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

# Compute current through 1kΩ resistor at 5V
current = current_through_resistor("5V", "1k")
print(f"Current through 1kΩ at 5V: {format_value(current, 'A')}")

# Compute current through 100Ω resistor at 3.3V
current = current_through_resistor("3.3V", "100Ω")
print(f"Current through 100Ω at 3.3V: {format_value(current, 'A')}")

Example output

current_through_resistor_output.txt
Current through 1kΩ at 5V: 5.00 mA
Current through 100Ω at 3.3V: 33.0 mA

The current is computed using Ohm’s law: $I = \frac{V}{R}$


Check out similar posts by category: Electronics, Python