When we renovated our living room, we bought new lights for the walls that should make a nice, warm room-illumination and furthermore make any kind of ceiling light redundant. We bought these online, and had to realise that they looked good, but were way to bright. I told my dad, that I would fix this.
So I researched a little and spend hours looking for existing plug-n-play solutions. I found some, but not a single one was small enough to fit inside these lights, which indeed had very limited space. So I set out to solder my own circuit board, embedding a cheap PIC microcontroller which would pulse the LEDs through a transistor. You can see my very plain circuit design in the image.
So what the microcontroller does, is that it uses PWM (pulse width modulation) to turn the LEDs on an off 16.000 times per second. By changing the pulse width, i.e. how long in every cycle the LEDs are on respectively off, the perceived brightness can be changed. E.g. if the LED is turned on 10% (and 90% off) in each cycle, it is obviously darker than when it is turned on 50%.
As I was now dealing with some basic embedded programming anyway, I thought I could at least allow us to dim the light in 2 steps. This would bring the comfort of having a nicely dimmed illumination as a normal state, but still give the option of having more light when needed (we use the latter quite seldom, but then it is very appreciated). How this works: The microcontroller has a small non-volatile memory, the so-called EPROM. Now when the light is turned on, the microcontroller gets power and goes through some “start-code”, that is only executed once after power up, I set a certain bit in the memory to 1. After a countdown of three seconds, I reset the variable to 0. If, and only if, the light is turned off within these three seconds, the microcontroller turns off and cannot reset the variable. This in return means, that the next time the light is turned on, this bit is still set to 1 and not as usual to 0.
So, the first thing I do when the microcontroller starts, is to read that bit. Does it say 0, I activate a dimmed light. Is it set to 1 (because the light was switched on and then off within three seconds before), I light the room up a little more.
It reads easy, but it was a struggle. Furthermore, I had to do it for all three lamps…
The circuit board:
before:
After: (this is another lamp in the same room).