Inspiration

I'm a computer engineering major at Virginia Tech, and many of my classes have had me designing and analyzing circuits for lab assignments. All electrical and computer engineering majors are required to buy a lab kit with a lot of electronic components and equipment, including 76 different resistors ranging from 1 Ohm to 1 million Ohms. 76 is quite a few, but unless you're lucky there will probably not be an exact match for a given resistor. For those who are unfamiliar, resistors can be combined in series (current flows through one after the other) or parallel (current splits and flows through both at the same time). The former makes the overall resistance larger, while the latter makes it smaller. It's usually easy to use a few resistors to get a +/- 10 or 20 percent approximation, but It always bothered me that I might be missing a resistor combination that could get me closer or use less resistors.

What it does

Enter: Resistor Assister. If you say what your target resistance is and how many resistors you are willing to combine to get it, this program will show you the best combination of resistors for your needs.

How I built it

I made a Resistor class with a resistance value and a string representation to represent each resistor from the text file. I then used used a recursive function to define new resistor objects as combinations of other ones. That's where the string representation of each resistor is useful, because it keeps track of what other resistors were combined to achieve each resistor's resistance.

Challenges I ran into

At first, I tried to represent resistors as integers and separately keep track of what resistors were combined to get the final result. This implementation quickly became more complicated than it needed to be, so I had the idea to use a recursive function that could keep track of resistor combinations as it went. The first way I linked the resistances to the string was through a 2 dimensional array. This could work in theory, but the reason I abandoned it in favor of the Resistor class was that using the Resistor class made bugs easier to track down and made the code a lot easier to read. Everything else went smoothly, except that my computer wouldn't record audio from any input device. As a result, I had to record a silent demo video of me running some test cases.

Accomplishments that I'm proud of

I'm proud that I finished a product that I will use in the future in the time I had to finish it. On top of the time limit for the hackathon, I had a concert from 7:00 - 9:00 and a dress rehearsal for that concert from 4:30 - 5:30. I was also a solo participant in this hackathon, so I couldn't rely on any teammates to pick up the slack when I was unavailable.

What I learned

I had previously used Python exclusively with numpy for simple mathematical scripts like matrix solvers and function plotters. I wanted to be more comfortable with Python itself, so I made a point of using as few imports as possible. The only thing I imported in the final project is the sys module, which allowed me to use command line arguments as input. After this project, I'm much more comfortable with the base Python library. In the future, I can be quicker to whip up a Python script if I find myself in need of one.

What's next for Resistor Assister

I plan to use this project for my future electronics labs. It works for my applications, but it is not without its problems. Firstly and most importantly, it's a bit slow and it only gets slower as you raise the resistor limit or add more values to your resistor file. I couldn't come up with a more efficient algorithm to find the desired value, but I have a feeling that there is a way. Another potential issue is the number of resistors available. If you're trying to get a very specific resistance that requires a lot of resistors, the program could ask you for more of a particular resistor than you have available and there's no way to get it to use less of that resistor without removing that value from your text file entirely. There are also some features that would be nice to have, like being able to pick a tolerance. Resistors themselves have tolerances that are often about 5 or 10 percent, so it can feel a little bit silly to try to combine resistors with more accuracy than the resistors themselves.

Another more general thing I would like to improve on is UI. I personally don't mind running my own scripts from the command line, but I don't have any experience delivering my scripts to other people in a format that's easy for them to run.

Built With

Share this project:

Updates