Arduino Assignment: LED resistor finder

For my the arduino assignment in class, we first worked on creating a simple blink circuit. This was accomplished by connecting an LED to a digital pin, and ground (but through a resistor of course). This allowed us to set the pin we chose to HIGH to send 5v to the LED, and set it to LOW to send 0v (turn it off). By doing this in the loop portion of the arduino sketch and adding a delay, we were able to get the LED to blink at whatever frequency we wanted. From there we worked on a touch sensor. This was done by taking advantage of the resistance of the human body. We used essentially the same setup as above, but added a resistor between to additional digital (PWM) pins with an alligator clip off one of the legs going to some aluminum foil. The code was then changed to poll the “sensor” and get a value back from the sensor. From here we would set our threshold by examining the serial monitor to see what value the sensor was returning when we were or were not touching the foil. Once we set our threshold, we could turn the LED on and off by touching the foil.

For the take-home project portion, I initially wanted to use the ultrasonic sensor to create an ultrasonic tape measure. However, I was unable to get the sensor to detect any distance other than 1cm (or a raw sensor read of 64). This told me I may have had a faulty ultrasonic sensor in my kit (kit 6). I tried with different wires, and even a different arduino, and nothing helped. From here I decided to dive into my own personal spare parts bin. While I do not do much sensing in my personal projects, I did have some INA219 high-side current sensors I had purchased from adafruit a while back for a project.


I decided to use these along with the LCD display to create an LED resistor finder. The idea was I would use the current sensor to measure the current flowing through the LED-resistor pair, and display that on the LCD display and warn when it was in a dangerous range (> 20mA) and then would scold when in an absurd range (>100mA).

The reason behind this was due to when we look for what resistor values to use for LED circuits, we usually calculate it based on theoretical values. This tends to work well when you have a theoretical value to reach, such as 20mA. However, if what you are instead looking for is a specific brightness or a specific look, seeing is believing. So being able to see and hotswap resistors until you get the look you need is sometimes more ideal. Furthermore, since electrical components are not perfect, they have a specific tolerance that means the theoretical values doesn’t all match up, although they are usually good enough. However, if for whatever reason, you have stringent limits or tolerances for current draw of a circuit, a tool like this could help you custom match LED’s to resistors to get the exact real-world current draw you need instead of a theoretical draw that would be within a percentage of the actual draw.

With that, the first course of action was to prototype it on the breadboard to make sure all components worked as expected:

It seemed a rousing success! For further testing as well as to make it so I did not have to source and swap resistors, I connected two terminals of a potentiometer to have it function like a variable resistor. The code was mainly based from the Adafruit INA219 library examples as getting the INA219 setup is about the most involved part since you can (and I did) set a different calibration point to make the readings more precise. That is really just an extra line of code though. From there, the next thing to interface with was the LCD display. This one proved to be a bit more involved since all examples found for how to use the library did not seem to work. I suspected this had to do with the I2C addressing. I liked the fact that both my input and output talked over an I2C bus as this makes hooking up components much easier and was also something I had experience with already. What I had noticed was that all online examples of the I2C 16×2 LCD used the same I2C bus address (0x27). However, I knew by working with the INA219’s before that the address is not fixed, and a lot of devices let you change the address so you can avoid conflicts with other devices.  So I first had to use the I2C bus scanner sketch for arduinos:

I2C bus scanner code
Full sketch code for LED Resistor Finder
















Once I found the right bus address for the LCD display, the rest worked out fairly easily.

From there, I decided that since I had a spare arduino ProtoShield I had never used, I would use this as an opportunity to challenge myself. So I laid out my original design on the new ProtoShield then soldered everything in. Where possible, I used headers so I did not have to commit my INA219 to a life of living on this protoshield (until I needed it again and de-soldered it).


This worked quite the treat. it cleaned up the tangle of wires as now the only wires needed were the wires going to the LCD display. I show an extra 2 wires just because I designed it to either use the arduino’s 5v rails to power the LED, or you can instead provide your own power source. So those wires are just jumpers so that it can use the arduino 5v supply.

And just like that, I created my own shield for an arduino! I suppose the only thing I could do to improve it would be to actually create a case for it, or add some functionality like being able to change precision without needing to reflash the arduino. Here is a video of it in operation, my potentiometer is very cheap and janky so it is hard to slowly rise the brightness, it just kinda goes from nothing to BAM!