Paul Sutton

Voltage

Voltage Dividers

This is a repost, with some python code for a very basic, (as in it worked when I last ran it) voltage divider calculator.

A voltage divider is a simple circuit which turns a large voltage into a smaller one. Using just two series resistors and an input voltage, we can create an output voltage that is a fraction of the input. 

Voltage dividers are one of the most fundamental circuits in electronics. If learning Ohm's law was like being introduced to the ABC's, learning about voltage dividers would be like learning how to spell cat. [1]

Circuit diagram

The formula for a voltage divider is

$$Vout_1 ={ R1\over{R1+R2} } \times Vsup $$

and

$$Vout_2 ={ R2\over{R1+R2} } \times Vsup $$

At the next STEM group meeting, I plan to have some of my boards available. These can be connected together with either dupont cables or with crocodile clip cables. Then voltages can be measured with a multimeter.

boards

Links

  1. Sparkfun voltage dividers

Code

I wrote this a while back, so including the code 'as is' below.

#!/usr/bin/env python3
#voltage divider calculator
# http://www.ohmslawcalculator.com/voltage-divider-calculator

print("Voltage Divider Calculator")
print("Version 1.0")
print("By Paul Sutton")
print("zleap@disroot.org")
print("http://www.zleap.net")
print
print("Formula = Vout = Vin * R2 / R1 + R2")
print
print("Enter values")
supvol = int(input('Enter Supply Voltage (v): '))
#str(supvol)
r1 = int(input( 'Enter R1 value (Ohms) : ' ))
r2 = int(input( 'Enter R2 value (Ohms) : ' ))
print ( 'Supply Voltage(V):', supvol )
print ( 'R1(Ohms : ', r1 )
print ( 'R2(Ohms : ', r2 )
#print(r2 / (r1 + r2))
mainsum = (r2 / (r1 + r2))
outvolt = (supvol * mainsum)
print ( 'Output Voltage = :', outvolt )

This is an improved version by Mark on IRC

#!/usr/bin/env python3
msg = """Voltage Divider Calculator (v1.1)
Formula: Voltage out is "Voltage in * Resistor 2 / Resistor 1 + Resistor 2"
You entered:
    Voltage in {voltage}
    Resistor 1 {resistor1}
    Resistor 2 {resistor2}
Which equals:
    {output}
Output voltage is: "{output}", rounded (nearest 10) is "{rounded}"!
"""
error = """Usage: python3 {script} <voltage in> <resistor 1> <resister 2>.
Example: python3 {script} 5000 2000 4000
Seeing an Error?
ValueError: You enter an invalid value (or left it empty).
"""
def main(args):
    script = args.pop(0)
    try:
        voltage, resistor1, resistor2 = list(map(int, args))
        output = voltage * (resistor2 / (resistor1 + resistor2))
    except ValueError:
        print(error.format(script=script))
        raise
    print(msg.format(voltage=voltage, resistor1=resistor1,
                     resistor2=resistor2, output=output,
                     rounded=round(output)))
if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))


MastodonPeertubeQoto sign up

Donate using Liberapay

Transistor Amplifier

I have finished building a transistor Amplifier. This is in preparation for the next STEM group meeting, on April 9th.

trans amp

As this contains a voltage divider, I have also built a few more resistor boards, with the view of presenting an activity around this.

resistor board

Links

TAGS

#Technology,#STEM,#Amplifier,#Voltage,#Divider,#STEMGroup.

Donate using Liberapay

Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License


MastodonPeertubeQoto sign up

Donate using Liberapay