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

In this segment, Part III, we will again use Ohms Law to compute the values for a basic building block in electronics, the voltage divider.  The voltage divider does exacly what the name implies, it takes the source voltage and divides it for a lesser output voltage and depends on the voltage drop across the resistors connected. The circuit itself can consist of as little as 2 resistors connected in series to multiple resistors. Resistor 1 can also be replaced with a group of resistors in parallel in order to supply a certain current (a current divider). One or more of the resistors may also be replaced by potentiometers (adjustable resistors) in order to 'tweak' the resistance.

An example usage would be to consider the UART serial connections between the Raspberry Pi and the Arduino. The Raspberry Pi uses CMOS level logic (0 vdc for a low or 0, and 3.3 vdc for a high or 1) while the Arduino uses TTL level logic (0 vdc for a low or 0 and 5 vdc for a high or 1). The voltage divider isn't applicable when communicating from the Raspberry Pi to the Arduino since the output is always less then the source but due to the 'fudge' factor of the respective levels, it may or may not work, or work intermittently. Communicating in the other direction, from the Arduino to the Raspberry Pi will almost certainly overload and ruin the Raspberry Pi. Part of the solution is the voltage divder, dropping the source voltage of 5 vdc to 3.3 vdc. I say part of the solution, because we still have to consider the current and power dissipation in both directions. We can of course use our scripts in Parts I and II to ensure we stay within the parameters.  In todays world, we could also simply use a (Bidirectional) Logic Level Converter...but that would be cheating.

Here is our script for the voltage divider using two resistor in series:

#! /usr/bin/env/ python3

import os

# Simple Voltage Divider
#      V(out) = V(in) * (R2 / (R1 + R2))
#      or R1 = R2 * ((V(in) / V(out)) - 1)
#      or R2 = R1 * (1 / ((V(in) / V(out)) - 1)
#
#      V(in) _______
#                 <R1>
#                  |------------ V(out)
#      GRND  _____<R2>
#
# Ohms Law (A reminder)
#     V = I * R; I = V / R; R = V / I
#     P = V * I; P = I**2 * R; P = V**2 / R


def find_volt_out(v_in, res_1, res_2):
   v_out = v_in * (res_2 / (res_1 + res_2))
   print("Output of voltage divider = {:.4f} VDC".format(v_out))

   return


def find_res_1(v_in, v_out, res_2):
   res_1 = res_2 * ((v_in / v_out) - 1)
   print("Value of resistor 1 = {:.0f} Ohms".format(res_1))

   return


def find_res_2(v_in, v_out, res_1):
   res_2 = res_1 * (1 / ((v_in / v_out) - 1))
   print("Value of resistor 2 = {:.0f} Ohms".format(res_2))

   return


def main():
   # output ratio 3.3/5
   # volt_in = 5.0     TTL High or 1
   # volt_out = 3.33   CMOS High or 1
   # resist_1 = 25
   # resist_2 = 50
   volt_in = float(input("What is the supply voltage in Volts: "))
   volt_out = float(input("What is the desired output in Volts or '0' if unknown: "))
   resist_1 = float(input("What is the value of resistor 1 in Ohms or '0' if unknown: "))
   resist_2 = float(input("What is the value of resistor 2 in Ohms or '0' if unknown: "))

   if volt_out == 0:
       find_volt_out(volt_in, resist_1, resist_2)
   elif resist_1 == 0:
       find_res_1(volt_in, volt_out, resist_2)
   elif resist_2 ==0:
       find_res_2(volt_in, volt_out, resist_1)


if __name__ == "__main__":
   os.system('cls' if os.name == 'nt' else 'clear')

   main()
Output:
What is the supply voltage in Volts: 5 What is the desired output in Volts or '0' if unknown: 0 What is the value of resistor 1 in Ohms or '0' if unknown: 25 What is the value of resistor 2 in Ohms or '0' if unknown: 50 Output of voltage divider = 3.3333 VDC
Output:
What is the supply voltage in Volts: 5 What is the desired output in Volts or '0' if unknown: 3.33 What is the value of resistor 1 in Ohms or '0' if unknown: 0 What is the value of resistor 2 in Ohms or '0' if unknown: 50 Value of resistor 1 = 25 Ohms
Output:
What is the supply voltage in Volts: 5 What is the desired output in Volts or '0' if unknown: 3.33 What is the value of resistor 1 in Ohms or '0' if unknown: 25 What is the value of resistor 2 in Ohms or '0' if unknown: 0 Value of resistor 2 = 50 Ohms
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 III - by sparkz_alot - May-31-2017, 03:36 PM

Forum Jump:

User Panel Messages

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