This project was born for two reason:
- to improve my knowledge about the Object-oriented programming in C++;
- to construct a personal LED Controller with control knobs, specifically one for intensity and three for selecting various colors (red, green and blue), for my desk.
Furthermore, I want to share this project and a little guide on how to build it.
What do you need
Firstly, you’ll need of some component. Every one in the list has the link where to buy cheaply:
The size of microSD is not important because each file will be 1 kb. In the SD there will be four files, that is the three profile and the manual configuration to load on every power up.
This lists are merely indicative, but the size and the type of component are correct.
In addition, if you want to realized the PCB at home, consider to use these other materials:
Consider the external diameter of rivet and in this case modify the files of PCBs. Currently, the diameter is 1mm.
I don’t suggest you the type and the color of filament for the case. My chose has been the black color on PLA filament; same material for the buttons but in grey color.
Realizing the PCB
There are two ways to realize the PCB:
- by taking advantage with some company that realize it cheaply;
- by you with several techniques.
In my case I decided to realize the circuit board at home. The first idea was to use a stripboard, but the realization of the tracks would be little elegant for the final result, considering the number of the components and its connections.
I decided to draw the tracks and holes on the circuit board with my 3D printer (like a plotter), immersing it in ferric chloride solution and then cleaning it with 99% isopropyl alcohol.
The only flaw is the interruption of some track. I don’t know if is due from the permanent maker, in this case the Sharpie Ultra Fine Point. Next time I will be allowed to try with another maker, like the Lumocolor as suggested from some friend. To solve it, I soldered a piece of copper wire.
After the realization of the holes with a drill press, applying the rivets and solded the components, the result is realy good. The only precaution has been the the distance between the hole track and the rivet, where was not guaranteed the contact. To solve it, I soldered a bit of tin.
Being an homemade circuit board, I did not marked the names of the connections. To help you, see the files that I share later in this chapter.
Probably you’ll wonder how I used a 3D printer like plotter and how I used a ferric chloride solution. I suggest you to follow this two little guides, customizing the tool for the permanent maker:
Here the files about the PCB. If you want, you will be able to modify them.
Realizing the case
After the construction of circuit board, you will need a case. Foreword, I’m not a 3D modeling designer but I have realized one. I decided to print it with PLA filament: black color for the base, front and top panel; grey color for the buttons; transparent color for the LED covers. The first print has been the base. For spacing the SD card reader from the base I used four M2x15mm spacers; instead, for the main circuit board I used four M2x3mm spacers.
The second print has been the front panel. For each rotary encoder I used two M3x6mm screws. Instead, for spacing the the LED indicators board from the front panel I used two Dist M2x8mm spacers.
To mount the front panel at the base, I used two M2x5mm screws at the bottom of the base.
The third print has been the top panel, the three buttons and the two LED covers. Here too I used two M2x5mm spacers.
Finally, to mount the top panel at the base I used three M2x10mm screws and one M2x7mm screw.
Here the files about the case. If you want, you will be able to modify them.
|Front panel||.stl||167 kB|
|Top panel||.stl||65,8 kB|
|LED cover||.stl||31,9 kB|
Installing the software
Finally, the last chapter about the realitazion of this project. Actually, this was the first thing that I did, infact on the basis of this, I realized the circuit board (with a breadboard) and the case for it.
As you will see in this image, I used the potentiometers until a dear friend suggested me the rotary encoder. This component has simplified the code significantly.
For saving the files of profiles I used this disgusting 256 MB microSD card. “Disgusting” because I have been several hour to understand the reason of corruption of files.
For realizing the code of this project I used PlatformIO on Visual Studio Code. As I said in before, this project borns for two reason. Thanks to it, I have realized two main libraries available on official Library Manager of Arduino:
- Button-Arduino, to manage the button with short and long press;
- AnalogIO-Arduino, to manage the analog input/output.
Here the files about the software.
|LED Controller v1.0.0||.zip||86,7 kB|
I suggest you to use PlatformIO, importing the folder like a project and then writing the software on your microcontroller, that will has to be an Arduino Nano. If you want, you can change it with another microcontroller, considering to modify the circuit board, the case and the file config.h in src folder.
/* Setting the input and output pins about the encoders and the strip led, and the speeds for the encoders */ // Intensity const uint8_t pinAEncoderIntensity = A0; const uint8_t pinBEncoderIntensity = A1; const uint8_t speedIntensity = 1; // Red const uint8_t pinAEncoderRed = A2; const uint8_t pinBEncoderRed = A3; const uint8_t pinLedStripRed = 5; const uint8_t speedRed = 1; // Green const uint8_t pinAEncoderGreen = A4; const uint8_t pinBEncoderGreen = A5; const uint8_t pinLedStripGreen = 6; const uint8_t speedGreen = 1; // Blue const uint8_t pinAEncoderBlue = A6; const uint8_t pinBEncoderBlue = A7; const uint8_t pinLedStripBlue = 3; const uint8_t speedBlue = 1; /* Setting the output pins about the single led, the times and timeout for blink. */ const uint8_t pinLedSingleRed = 9; const uint8_t pinLedSingleGreen = 10; const uint8_t timesBlinkError = 1; const uint16_t timeoutBlinkError = 500; const uint8_t timesBlinkReadProfile = 1; const uint16_t timeoutBlinkReadProfile = 1000; const uint8_t timesBlinkSaveProfile = 3; const uint8_t timeoutBlinkSaveProfile = 200; /* Setting the input pins and the time for the long press about the buttons. */ const uint8_t pinButtonProfile1 = 2; const uint8_t pinButtonProfile2 = 4; const uint8_t pinButtonProfile3 = 7; const uint16_t timeLongPress = 3000; /* Setting the baudrate for Serial Monitor. */ const uint32_t baudRate = 9600; /* Setting the card reader and the namefiles. */ const uint8_t pinCS = 8; const String fileNameManual = "manual.dat"; const String fileNameProfile1 = "profile1.dat"; const String fileNameProfile2 = "profile2.dat"; const String fileNameProfile3 = "profile3.dat"; const uint16_t timeoutSaveManual = 5000; /* Setting the address where saving the number og last profile read/wrote. */ const uint8_t addressEEPROMNumProfile = 0;
My wish is the names of variable are documented themself.
With this image you can see the final result on my desktop.
In this project I have certainly learned the Object-oriented programming, but I have not followed one of the enginnering principles: the anticipation of change. Infact, few week later was born the necessity to manage the LED Controller with my smartphone. Do to this, the microcontroller will has to change with an ESP8266 or ESP32, that is a microcontroller with Wi-Fi. Infact, the next version will have this feature, with an OLED screen to view the values of the configuration and the profile loaded at the moment. This implies to change the PCB and the case.
Thank you for read this article and if you have some suggestion, please leave a comment below or write me at firstname.lastname@example.org.