Jump to content

A free, portable LED resistor calculator.


Werne

Recommended Posts

So, since my 3 years long quest to find a portable LED resistor calculator (as in one that doesn't require me to go online, Google it and then use it while online) has been a failure, I made my own. I found one but it didn't have resistor wattage, only resistance. First one I made was in form of a VBScript but since that just gave me nightmares (doesn't accept floats, need to write a whole fairy tale for it to work even nearly as good as I wanted it to) now it's written in Python.

 

And since there might be others who might want to use something like this, I decided to release it. Here are the download links for English and Croatian versions:

 

English - download link

Croatian - download link

 

It's designed to calculate resistor's resistance value and wattage for a single LED and multiple LEDs in serial/parallel connection. Usage is simple, pick an option from the main menu by executing the option's number (1 for single, 2 for serial, etc.), it has a help option that explains input/output values and a list of common LED voltages for 5mm diodes. Also, it's only 5kb in size so it doesn't take up much space.

 

Formulas used are:

 

Single diode: (Vs - Vl) / I

Serial connection: (Vs - (Vl * X)) / I

Parallel connection: (Vs - Vl) / (I * X)

 

X represents the number of diodes in a serial or parallel connection. There are also other variations of those same formulas for calculating resistor wattage.

 

It requires Python 2, not tested in Python 3 so I'm not sure if it will work in it. :confused: Tried it in Python 2.6.6 on Windows 7 Ultimate x64 and Python 2.7.3 on both Windows 7 and Ubuntu Linux 12.04 LTS x64.

 

To start it in Windows you just need to double-click it, to start it in Ubuntu's Terminal you need to execute the following commands depending on which one you use:

 

sudo python /*file path*/Werne_LED_Calculator_ENG.py
sudo python /*file path*/Werne_LED_Calculator_CRO.py

 

Pics of this thing running:

 

In Python 2.6.6 on Windows 7:

 

 

Werne%2527s%2520LED%2520Calculator%2520%

 

 

 

In Python 2.7.3 on Ubuntu 12.04:

 

 

Werne%2527s%2520LED%2520Calculator%2520%

 

 

 

And the source code:

 

English:

 

 

#Definition convertString for using in the formula.

def convertString(str):

    try:

        returnValue = float(str)

    except ValueError:

        returnValue = bool(str)

    return returnValue

 

#Definitions and formulas for different circuits.

#X represents the number of diodes in a circuit.

 

#Single diode formula (Vs - Vl) / I. Single diode output script

def single(a, b, c, e):

    print "    -Resistor Value: ", (convertString(a) - convertString(b)) / convertString(c)

    print "    -Resistor wattage: ", (convertString(a) - convertString(b)) * convertString(c)

    print "    -Safe-to-use resistor wattage: ", ((convertString(a) - convertString(b)) * convertString(c)) * convertString(e)

    print "\n"

 

#Formula for calculating values in a serial connection (Vs - (Vl * X)) / I. Serial connection output script.

def serial(a, b, c, d, e):

    print "    -Resistor Value: ", (convertString(a) - (convertString(b) * convertString(d))) / convertString(c)

    print "    -Resistor wattage: ", (convertString(a) - (convertString(b) * convertString(d))) * convertString(c)

    print "    -Safe-to-use resistor wattage: ", ((convertString(a) - (convertString(b) * convertString(d))) * convertString(c)) * convertString(e)

    print "\n"

     

#Formula for calculating values in a parallel connection (Vs - Vl) / (I * X). Parallel connection output script.

def parallel(a, b, c, d, e):

    print "    -Resistor Value: ", (convertString(a) - convertString(b)) / (convertString(c) * convertString(d))

    print "    -Resistor wattage: ", (convertString(a) - convertString(b)) * (convertString(c) * convertString(d))

    print "    -Safe-to-use resistor wattage: ", ((convertString(a) - convertString(b)) * (convertString(c) * convertString(d))) * convertString(e)

    print "\n"

 

keepProgramRunning = True

 

#Main menu with choices.

print "--Welcome to Werne's LED Calculator--"

 

while keepProgramRunning:

 

    print """

--Select type of connection--

 

    -1: Single Diode

    -2: Serial connection

    -3: Paralell connection

    -4: Common LED voltages

    -5: Help

    -0: Close Program"""

 

    #Main menu choice script.

    choice = raw_input()

 

    #Single diode input script.

    if choice == "1":

        numberA = raw_input("    -Enter source voltage: ")

        numberB = raw_input("    -Enter diode voltage: ")

        numberC = raw_input("    -Enter diode current in ampers: ")

        numberE = float(1.6)

        print " "

        print single(numberA, numberB, numberC, numberE)

        print "\n"

         

        #Serial connection input script.

    elif choice == "2":

        numberA = raw_input("    -Enter source voltage: ")

        numberB = raw_input("    -Enter diode voltage: ")

        numberC = raw_input("    -Enter diode current in ampers: ")

        numberD = raw_input("    -Enter number of diodes: ")

        numberE = float(1.6)

        print " "

        print serial(numberA, numberB, numberC, numberD, numberE)

        print "\n"

         

        #Parallel connection input script.

    elif choice == "3":

        numberA = raw_input("    -Enter source voltage: ")

        numberB = raw_input("    -Enter diode voltage: ")

        numberC = raw_input("    -Enter diode current in ampers: ")

        numberD = raw_input("    -Enter number of diodes: ")

        numberE = float(1.6)

        print " "

        print parallel(numberA, numberB, numberC, numberD, numberE)

        print "\n"

         

        #Help.

    elif choice == "5":

        print """--Main Menu--

    -Single diode calculates the resistor values for only one diode.

    -Serial connection calculates resistor values for multiple diodes connected in a serial connection.

    -Parallel connection calculates resistor values for multiple diodes connected in a parallel connection.

 

--Input Values--

    -Source voltage is the voltage of a power source that will power your diodes.

    -Diode voltage is a desired voltage you want a diode to work on.

    -Diode current is the current a diode works on.

    -Number of diodes is how many diodes you want to connect into a serial or parallel connection.

 

--Output Values--

    -Resistor value is the minumum number of Ohms the resistor must have in order to lower the voltage to desired one.

    -Resistor wattage is the power of your diode assembly the resistor must withstand.

    -Safe-to-use resistor wattage is how much power the resistor should be able to withstand so you can use it effectively."""

         

        #Common LED voltages.

    elif choice == "4":

        print """

--Common LED voltages--

 

    -Infra-Red LED - 1.5V

    -Red LED - 2.0V

    -Orange LED - 2.0V

    -Yellow LED - 2.1V

    -Green LED - 2.2V

    -Real Green LED - 3.3V

    -Blue LED - 3.3V

    -White LED - 3.3V

    -Ultra-Violet LED - 3.3V

    -Blue (430 nm) LED - 4.6V"""

 

        #Exit script.

    elif choice == "0":

        print "--Goodbye and thank you for using Werne's LED Calculator--"

        keepProgramRunning = False

         

        #For idiots.

    else:

        print "--Please choose one of the options given--"

        print "\n"

 

 

 

Croatian:

 

 

#Definicija convertString za koristenje u formuli.

def convertString(str):

    try:

        returnValue = float(str)

    except ValueError:

        returnValue = bool(str)

    return returnValue

 

#Definicije i formule za razlicite spojeve.

#X je broj dioda u spoju.

 

#Osnovna formula (Vs - Vl) / I

def single(a, b, c, e):

    print "    -Vrijednost otpornika: ", (convertString(a) - convertString(b)) / convertString(c)

    print "    -Minimalna snaga otpornika: ", (convertString(a) - convertString(b)) * convertString(c)

    print "    -Sigurna snaga otpornika: ", ((convertString(a) - convertString(b)) * convertString(c)) * convertString(e)

    print "\n"

 

#Formula za racunanje serijskog spoja (Vs - (Vl * X)) / I

def serial(a, b, c, d, e):

    print "    -Vrijednost otpornika: ", (convertString(a) - (convertString(b) * convertString(d))) / convertString(c)

    print "    -Minimalna snaga otpornika: ", (convertString(a) - (convertString(b) * convertString(d))) * convertString(c)

    print "    -Sigurna snaga otpornika: ", ((convertString(a) - (convertString(b) * convertString(d))) * convertString(c)) * convertString(e)

    print "\n"

     

#Formula za racunanje paralelnog spoja (Vs - Vl) / (I * X)

def parallel(a, b, c, d, e):

    print "    -Vrijednost otpornika: ", (convertString(a) - convertString(b)) / (convertString(c) * convertString(d))

    print "    -Minimalna snaga otpornika: ", (convertString(a) - convertString(b)) * (convertString(c) * convertString(d))

    print "    -Sigurna snaga otpornika: ", ((convertString(a) - convertString(b)) * (convertString(c) * convertString(d))) * convertString(e)

    print "\n"

 

keepProgramRunning = True

 

#Izbornik sa spojevima i voltazama dioda.

print "--Dobrodosli u Werne-ov LED Kalkulator--"

 

while keepProgramRunning:

 

    print """

--Odaberite opciju--

 

    -1: Jedna dioda

    -2: Serijski spoj

    -3: Paralelan spoj

    -4: Ceste LED voltaze

    -5: Pomoc

    -0: Zatvori program"""

 

    #Skripta izbornika.

    choice = raw_input()

 

    #Jedna dioda.

    if choice == "1":

        numberA = raw_input("    -Unesite voltazu izvora: ")

        numberB = raw_input("    -Unesite voltazu diode: ")

        numberC = raw_input("    -Unesite struju diode u amperima: ")

        numberE = float(1.6)

        print " "

        print single(numberA, numberB, numberC, numberE)

        print "\n"

         

        #Serijski spoj.

    elif choice == "2":

        numberA = raw_input("    -Unesite voltazu izvora: ")

        numberB = raw_input("    -Unesite voltazu diode: ")

        numberC = raw_input("    -Unesite struju diode u amperima: ")

        numberD = raw_input("    -Unesite broj dioda: ")

        numberE = float(1.6)

        print " "

        print serial(numberA, numberB, numberC, numberD, numberE)

        print "\n"

         

        #Paralelan spoj.

    elif choice == "3":

        numberA = raw_input("    -Unesite voltazu izvora: ")

        numberB = raw_input("    -Unesite voltazu diode: ")

        numberC = raw_input("    -Unesite struju diode u amperima: ")

        numberD = raw_input("    -Unesite broj dioda: ")

        numberE = float(1.6)

        print " "

        print parallel(numberA, numberB, numberC, numberD, numberE)

        print "\n"

         

        #Pomoc

    elif choice == "5":

        print """--Glavni izbornik--

    -Jedna dioda racuna vrijednost otpornika za samo jednu diodu.

    -Serijski spoj racuna vrijednost otpornika za vise dioda spojenih u seriju.

    -Paralelan spoj racuna vrijednost otpornika za vise dioda spojenih u paralelu.

 

--Ulazne vrijednosti--

    -Voltaza izvora je vrijednost voltaze koja dolazi sa izvora na diodu.

    -Voltaza diode je zeljena voltaza koju zelite dobiti na diodi.

    -Struja diode je vrijednost struje koju dioda vuce.

    -Broj dioda je koliko dioda zelite spojiti u serijski ili paralelan spoj.

 

--Izlazne vrijednosti--

    -Vrijednost otpornika je vrijednost otpora koji otpornik pruza u Om-ima.

    -Minimalna snaga otpornika je minimum snage koju otpornik mora izdrzati.

    -Sigurna snaga otpornika je snaga visa od snage spoja da bi spoj radio optimalno."""

         

        #Ceste voltaze dioda

    elif choice == "4":

        print """

--Ceste LED voltaze--

 

    -Infra-crvena LED dioda - 1.5V

    -Crvena LED dioda - 2.0V

    -Narancasta LED dioda - 2.0V

    -Zuta LED dioda - 2.1V

    -Zelena LED dioda - 2.2V

    -Prava zelena LED dioda - 3.3V

    -Plava LED dioda - 3.3V

    -Bijela LED dioda - 3.3V

    -Ultra-ljubicasta LED dioda - 3.3V

    -Plava (430 nm) LED dioda - 4.6V"""

 

        #Izlaz.

    elif choice == "0":

        print "--Dovidenja i hvala sto ste koristili Werne-ov LED Kalkulator--"

        keepProgramRunning = False

         

        #Za kretene.

    else:

        print "--Molim odaberite jednu od opcija--"

        print "\n"

 

 

 

Feel free to use this and edit it in any way you see fit, I release all my work freely so this can be edited and/or distributed without my permission. :smile:

 

Also, thank you Mark Hammond, whoever you might be. :thumbsup: Without him I'd still be sitting with a thumb in my arse and type LED voltage multiplied by 10 into a VBScript. :yucky:

 

Thought I might thank him too since Python installer has a big thank you message after it's finished installing.

Edited by Werne
Link to comment
Share on other sites

Free stuff is cool, but in all i agree with gaminggriffin :confused: also muffins is cool to, have nothing against them at all, especially the chocolate kind :teehee:


now i have craving for a muffin :blink:

 

 

Edited by Thor.
Link to comment
Share on other sites

Okay, I'm gonna be honest here, I have no clue of what you just said.

Then I guess you and Thor don't play with electronics, or diodes much. Here's a lesson:

 

When the source voltage is higher than the voltage an LED needs to work on, the LED will burn out. LED's current rises by a lot when voltage is raised a bit over the max it can take. That's why you use resistors, to drop the voltage to a value the diode needs so it doesn't burn out. :yes:

 

Since the voltage drop depends on how much current is drawn by the circuit and on how high the source and diode voltages are, you have a formula (Vs - Vl) / I where "Vs" is source voltage, "Vl" is desired diode voltage you want to get and "I" is current drawn by the diode. Resistor wattage depends on the power the circuit draws from the source, safe-to-use resistor wattage is the circuit's power increased by 60% (a simple way to put it is, if you have a single diode that draws 1W, you use a 1.6W resistor).

 

This thing incorporates 9 different variations of the formula I mentioned above in 3 different connection types to calculate resistance, minimum wattage and safe-to-use wattage of a resistor needed in order to lower the voltage down to a value required for the LED to function correctly without burning out.

 

Sure, you can do it in your head or on a calculator, I do. But when you have several circuits with different voltages, different numbers of LEDs and different connection types, this thing comes in handy. :thumbsup:

Link to comment
Share on other sites

 

        #For idiots.

 

Should be "For morons" or "For cretins" if you directly want to translate from your Croatian version :teehee:

 

I also recommend you upload to Mediafire instead of 4Shared, I can't download from that site for some reason.

 

Sadly this is of no use for me atm (Still, good job on making it), but I remember I loved playing with LED's and circuits in elementary school. The first thing I did was a LED that blinks :D lol I wish I had more time to get back to electronical engineering all over again, it always did interest me a bit, how stuff works and electricity, the way it's used etc. But I barely got time for programming, this'll have to wait a bit. Maybe it will be a hobby of mine in a few years :)

 

I'll make a double LED that blinks, f yes.

Link to comment
Share on other sites

I'll make a double LED that blinks, f yes.

Or you can make this...

 

 

I have this thing, but much bigger. 24 blue 5mm LEDs per channel, connected 6 diodes in series and then connected those 4 rows in parallel, made a transistor amp for them, repeated that for left channel and hooked them up on an old 18.7V 2A laptop charger. Gotta say, that thing can glow. :yes:

 

And I forgot I have a MediaFire account, otherwise I would've uploaded this there, 4shared tends to screw with me sometimes. Anyway, done now, uploaded to MediaFire, changed links in the OP. :smile:

Link to comment
Share on other sites

Unlike some of the electronically challenged who have no clue. I do know exactly what this does and why someone would want it.

I did something similar years ago using a spreadsheet - calculating voltage drop through a resistor based on a set of variables (I looked but can no longer find it :confused: ) This looks useful to me. :thumbsup:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...