Python Forum
Basic DC Electronics- Resistors
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic DC Electronics- Resistors
#2
In Part I we learned how to use Ohms Law to find various measurements related to resistors connected in series.

In this segment, Part II, we will again use Ohms Law and how it relates to resistors connected in parallel. In the series circuit, we saw that there is a voltage drop across each resistor and the current was unchanged. In a parallel circuit, the voltage across each resistor is the same, while the current changes.

#! /usr/bin/env/ python3

# Circuit with 3 resistors connected in parallel with 9vdc source
# Voltage is constant thru all resistors in parallel.
#
#        ___________________________
#       |                __________|__________
#       |               |          |          |
#       +               |          |          |
# <9 vdc source>    <R1, 3k>   <R2, 10k>  <R3, 5k>
#       -               |          |          |
#       |               |__________|__________|
#       |__________________________|
#
# In a parallel circuit, RT = 1 / (1 / R1 + 1 / R2 + 1 / R3 ....n)
# From Ohms Law, I = V / R
# IT = 9 / 3000 + 9 / 10000 + 9 / 5000 = .003 + .0009 + .0018 = .0057 Amps
# To test, convert parallel resistors to 1 resistor using above formula
# RT = 1 / ((1 / 3000) + (1 / 10000) + (1 / 5000)) = 1578.94736 Ohms
# I = 9 / 1578.94736 = .005700 Amps


def parallel_res(number, source):
   """ Find total value of parallel resistors or coils or series capacitors """
   current_total = 0
   power_total = 0
   count = 0
   sub_parallel = 0
   res_values = []

   while count < number:
       try:
           val = float(input("Enter the resistor values (in Ohms): "))
           res_values.append(val)
           count += 1
       except ValueError as e:
           print("Not a number", e)
           continue

   for r in res_values:
       sub_parallel += 1 / r

   res_total = 1 / sub_parallel

   print("\nTotal of parallel resistors = {:.6f} Ohms".format(res_total))
   current = source / res_total
   print("Total current through circuit = {:.6f} Amps\n".format(current))

   for c in res_values:
       print("Current through {} Ohm resistor = {} Amps".format(c, source / c))
       print("...Power dissipated = {:.6f} Watts".format(current**2 * c))    # Use which ever power formula you prefer
       current_total += current * c
       power_total += current**2 * c
   print("Total power dissipated = {:.4f} Watts".format(power_total))    # Let's limit this to 4 decimal places

   return


source_voltage = float(input("Enter source voltage: "))
no_of_resistors = int(input("Enter the number of resistors in parallel: "))
parallel_res(no_of_resistors, source_voltage)
Output:
Enter source voltage: 9 Enter the number of resistors in parallel: 3 Enter the resistor values (in Ohms): 3000 Enter the resistor values (in Ohms): 10000 Enter the resistor values (in Ohms): 5000 Total of parallel resistors = 1578.947368 Ohms Total current through circuit = 0.005700 Amps Current through 3000.0 Ohm resistor = 0.003 Amps ...Power dissipated = 0.097470 Watts Current through 10000.0 Ohm resistor = 0.0009 Amps ...Power dissipated = 0.324900 Watts Current through 5000.0 Ohm resistor = 0.0018 Amps ...Power dissipated = 0.162450 Watts Total power dissipated = 0.5848 Watts Process finished with exit code 0
You will also run across more "complex" circuits involving both parallel and series resistors.  In that case, solve for the parallel resistors (in essence creating one resistor (RT) then use that value in the series calculations.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Messages In This Thread
Basic DC Electronics- Resistors - by sparkz_alot - May-25-2017, 07:52 PM
Basic DC Electronics- Resistors Part II - by sparkz_alot - May-29-2017, 11:23 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020