Break STEM

Arduino: Building your own dimmer at home

This mini-project is to get a lamp to dim or brighten on command. In this case, we’ll hook up a regular LED to a potentiometer module, which when turned clockwise will increase the brightness of the LED lamp, or dim it (and all the way to “off”) when turned counter-clockwise.

This is exactly how the dimmer in our homes work. The circuitry is the same. Since we’re using a 20mA LED, with a 5V power source, we’ll need a resistor. Since green LED can take more power than a red LED, I can get away with using a lower resistor, even 100 ohm in this case.

In addition to the circuitry, I also wanted to actually visualize the voltage coming out at each setting of the potentiometer’s turning knob. This is optional. We don’t need it for it to work, but to monitor the voltage, I have to write some code in Arduino IDE using C/C++ code and its controller library. So, I’ll be using an analog pin for reading the output and plot it real-time (images and real-time captured animations are shown below).

NOTE: I’ve seen various videos that hook up the potentiometer differently and I’m sure why as those set up are quite messy on a breadboard. Since the 3rd pin on the potentiometer is the total output, I figured that’d be the right place to hook up the resistor, and then the lamp to it. So, here’s my cleaner setup…

On the code side, I used analogRead(pin#) where pin# is A3 in the picture above. However, analogRead returns a value from 0-1023 (inclusive)…which is a total of 1024 values…which happens to be 2^10. We need to convert this to another scale of 0-5 for voltage. Which is done by a simple formula: (5.0 / 1023.0) * readVal;

where 5 is the maximum Voltage out of the controller, and readVal is the value returned by analogRead().

Once the controller is hooked up via USB A->B cable and code is downloaded, we can see the output in real-time as I turned the knob:

We can clearly see as I turn the knob to right, the voltage increases, therefore brightening the LED and as I turn to left it dims.

Brightness at 2.1V
Brightness at 5V

We can also use the same setup to control volume of a speaker or buzzer. I have some of those projects done that I’m hoping to share in the future as well. Hope you enjoyed it, or at least it tickled your curiosity. In the future, I will post some of my easy, fun projects with Arduino and you can always get to them by visiting http://flyingsalmon.net/?tag=Arduino

Interested in creating programmable, cool electronic gadgets? Give my newest book on Arduino a try: Hello Arduino!


Interested in creating programmable, cool electronic gadgets? Give my newest book on Arduino a try: Hello Arduino!

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top