LED Controller Using an Arduino and MOSFET
Over the semester, I was interested in building an LED controller to control the intensity of lights and I figured I would share a very basic way of doing it. I couldn’t find any guides that were exactly what I wanted but this might be useful to some. The plan was to run 12v LEDs for a project with an arduino to control it and a MOSFET to make the transition. The exact details don’t matter as much as you’ll have to refer to your spec sheet for your model of MOSFET and project
One post I found useful is this one: https://electronics.stackexchange.com/questions/196344/led-strip-dimming
Since this is just the beginning of my project, I will show my current setup but the last (or second to last if you want a capacitor) diagram is a good representation of how to achieve that in terms of wiring.
In terms of code, I only used analogWrite() for the time being you can find here with a full explanation of how it works: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
Using this line: value
: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int
.
You can control whether your LED is on, of and values in between the 0 to 255 range will essentially ‘dim’ your LED. If you include delays in terms of time, you can also create various effects like fade or a breathing mode.
I will post more on this project as it evolves!