LED Controller v1.0.0

Introduction

This project was born for two reason:

  1. to improve my knowledge about the Object-oriented programming in C++;
  2. 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 these components:

Qty. Component
1 Arduino Nano
1 SD card reader
1 MicroSD
1 LED strip RGB 5050 SMD not addressable at 12V
1 Led strip connector 4 pin
1 Led strip extension
1 Positive Voltage Regulator L7805
3 Transistor TIP120
3 Resistor at 220Ω
6 Resistor at 10kΩ
3 Resistor at 1kΩ
1 Green LED diode at 5mm
1 Red LED diode at 5mm
3 Switch Tact at 6x6x5mm
1 Switch SPST at 15x10x10mm
4 Rotary encoder
1 Female base for Power supply
1 Power supply at 2A, 12V
undef. Wires both for 2A and 100mA of electrical current

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:

Qty. Component
2 Copper clad board double-sided
1 Copper clad board single-sided
undef. Rivet at 1x2.5mm

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:

  1. by taking advantage with some company that realize it cheaply;
  2. 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.

Image of stripboard

I decided to draw the tracks and holes on the circuit board with my 3D printer (like a plotter),

Image of PCB drawn

immersing it in ferric chloride solution,

Image of PCB immersed

and then cleaning it with 99% isopropyl alcohol.

Image of PCB cleaned

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.

Image of PCB interruption

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 distance between the hole track and the rivet, where was not guaranteed the contact. To solve it, I soldered a bit of tin.

Image of the soldering the GAP

Then, the final result of PCB.

Image of the result for the PCB

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.

Name Type Size
Mainboard .fzz 48,8 kB
LED indicators .fzz 4,8 kB
Profile buttons .fzz 9,4 kB

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.

Image of the main case

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.

Image of the front panel case

The third print has been the top panel, the three buttons and the two LED covers. Here too I used two M2x5mm spacers.

Image of the top panel case

Finally, to mount the top panel at the base I used three M2x10mm screws and one M2x7mm screw.

Image of the top panel case

Finally, to mount the top panel at the base I used three M2x10mm screws and one M2x7mm screw.

Image of the result for the case

Here the files about the case. If you want, you will be able to modify them.

Name Type Size
Base .stl 88,4 kB
Front panel .stl 167 kB
Top panel .stl 65,8 kB
Button .stl 1,4 kB
LED cover .stl 31,9 kB
Project .f3d 450 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.

Image of the prototype

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.

Image of the prototype

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.

Name Type Size
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* 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.

Conclusion

With this image you can see the final result on my desktop.

Image of the final result

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 reading this article and if you have some suggestion, write me at davidepalladino@hotmail.com.