The goal of the project was to create a digital microcontroller dimmer that can power LEDs without any external power source. The approach used a transistor with a pull-up resistor connected to the microcontroller's input, which would turn off when it reaches zero crossing point. This allowed the creation of a zero-crossing indicator from whose occurrence could be used as a timing signal. The timing signal was then used to delay the ignition of the track according to the set potentiometer value and get the desired phase angle.
The next step involved using an output of the microcontroller hooked up to an optocoupler track driver, which activated the first TRIAC and also the second TRIAC. As soon as the ignition point was reached, the microcontroller lit up the LED for small time inputs, activating the first TRIAC and thus also the second TRIAC.
However, there was a need to supply five volts power for the circuits. Initially, it was thought of using a capacitive dropper circuit, but then realized that there's a risk of having a voltage potential of 230 volts across the potentiometer to earth. Instead, a small Hi-Link five volts mains power supply was used, which could deliver more than enough current for the circuits.
The suitable SMD components were searched for and calculated according to their datasheet specifications. This resulted in a confusing hand-drawn schematic that was later edited into a more pleasant one using easy EDA software. The PCB was then designed using an EDA tool and ordered from JLCPCB, which arrived within less than a week.
The components were then added to the PCB in less than an hour, with only one minor package size problem encountered during soldering. The microcontroller was programmed using an ISP-header connected to an Arduino Uno, following a tutorial on programming the ATtiny microcontroller. The code for the project was written and uploaded to the microcontroller.
After powering the circuits, no explosions occurred, indicating that safety measures had been taken. An E27 socket with a halogen light bulb was added for testing, and it successfully dimmed its brightness. However, some other LED light bulbs did not work at all due to complex reasons.
WEBVTTKind: captionsLanguage: enWarning this circuit showcased in this video uses mains voltage.Mishandling of such a high voltage can lead to fatal injuries.Replicate the circuit at your own risk.A while ago a friend of mine gave me this LED light bulbwhich emits quite an interesting to look at screen lightsand he asked me whether I could create a circuits to dim brightness.And since the packaging of the LED bulb stated that it is dimmable.I said: - Yes, that should be possible.What I didn't expect thoughWas that dimming AC LED lights can be a very confusing and complicated topicBut let's postpone this problem for now.Instead let's start with analyzing how common AC dimmer worksand how we can easily create our own.Improved version by coming up with a custom PCB design controlled by a small ATtiny microcontroller.So that at the end of this DIY or Buy episodewe can determine whether it makes sense to create a DIY AC light dimmer.Or whether we should stick to the commercial solutions instead.Let's get started!* Intro music *This video is sponsored by JLCPCB whose new full automatic PCB batch production factoryis being used since AprilThey produce 600,000 square meter of PCBs per monthand you can get your own 2 layer prototype PCB for as low as two dollars.The AC dimmer I got online was a pretty generic one.That uses Phasenanschnitt in German or face anger control in English.To dimmer, 3 to 35 watt LEDs and 7 to 110 watt halogen lamps.So I hooked it up to mains voltage and in E27 socketsaccording to the wiring diagram offers instruction manual.As the first simple test subject, I will be using this 42 watts halogen light bulb.After securing it inside the sockets.It was a breeze to dim the brightness of its the main potentiometer of the dimmer.But let's think a bit deeper by removing a couple of screwsand lifting up the dimmer slits in order to have a closer look at the circuits.I have to say that these circuits is a lot simpler than what I anticipatedand the solder quality is certainly not the best.But I guess this is what you get at a price point of twenty four euro.If we reduce the component counts to only the mandatory bonds,then the schematic for the circuits would look something like this.With a resistor, potentiometer, capacitor, DIAC and TRIAC.To understand how it works, let's imagine, we got our AC sine wave voltage appliedafter the zero crossing point the voltage slowly increasesWhich charges up the capacitor through the resistor and potentiometer?The capacitor voltage increases up to value of, for example, 32 volts-- which is the break over voltage of our DIAC.At this voltage the DIAC becomes conductiveand thus the capacitor discharges through its and through the gate of the TRIACWhich turns it on and thus lets current flow through the light bulb for the remainder of this half waveAs soon as the next zero crossing point comes however the TRIAC turns off.Since the current value fell beneath the holding current.But feel free to watch my basics video about TRIAC's to understand they're working behavior better.anyway, for the next reversed polarity half wave, the process almost tastes the sameand thus only part of the half wave gets once again applied to the light bulbNow by increasing the resistance of the potentiometer,the charge up time of the capacitor increasesand thus the ignition point of the track gets delayed.Which means less average voltage less current and thus less brightness for the light bulbNow, of course, the commercial dimmer got a couple more components.Two, for example: suppressed noise and voltage spikes.But, in a nutshell, this is how such an analog face anger control dimmer functions.And after hooking up these circuits to the oscilloscope.We can see that the waveform of the mains voltage applied to our light bulb,pretty much looks like the theory we just talked about.Awesome!For such a halogen light bulb which can be modeled as a resistor such dimmer circuit is definitely suitableBut for an LED light bulb which comes with capacitors inductors and LED driverssuch circuits is oftentimes not suitable.Because the current path goes through the light bulband thus and more complex loads can lead to the malfunction of the analog dimmer.That is why from our own designI wanted to teach this old analog light bulb serious conceptsand instead go the digital way here with this SMD ATtiny 85 microcontroller.First off, I needed a potentiometer to set the desired phase angle of the AC voltageThe other mandatory input for the microcontroller needs to get connected to phototransistor Optocouplerlike it's shown here.When the mains voltage is high enough the LEDs inside the optocoupler get powered properlyand thus connect the input of the microcontroller on to groundBut as soon as the mains voltage reaches its zero crossing point, the voltage is too low to power the LEDsThe transistor turns offand thus the microcontroller inputs connects to five volts through its internal pull-up resistorThis way we have a zero crossing point indicatorFrom whose occurrence we can use the timer to delay the ignition of the trackaccording to the set potentiometer valueand thus get our desired phase angle.And speaking of ignition for that I use an output of the microcontrollerhooked up to an optocoupler track driverand finally a TRIAC like it shown here.As soon as the ignition point is reached the microcontroller lights up the LED for small inputs timewhich activates the first TRIAC and thus also the second TRIAC.And just like that, we should be able to create a digital microcontroller dimmer.But what I forgot was how to supply five volts power for the circuitsWell, initially, I wanted to use a capacitive dropper circuits-- which I showed you how to build in a previous video.But then I realized that there's a risk of having a voltage potential of 230 voltsacross the potentiometer to earth.And thus I decided that this was not the best idea.Instead I got myself this pretty small Hi-Link five volts mains power supply.That can deliver more than enough current for our circuits.So what I did next was searching for suitable SMD components.And then calculating the complimentary passive components for themaccording to the datasheet specifications.This resulted in this a bit confusing to look at hand-drawn schematicwhich through the help of easy EDA.I turned into a more pleasant to look at schematicto which I also edit an ISP-header to later easily program the microcontroller.So next I clicked the converter PCB button installed arranging the components in a logical orderAfter then connecting the components with copper tracesAdding the outline of the boards and creating a ground copper layer on the top and bottom sitesI think the PCB did not look half bad.So I clicked the generate Gerber files buttonand ordered my PCB from JLCPCB for only two dollars -- plus shipping, of course.After not even a week.I did not only receive my PCBs which looked even better in real life than on a computer screenbut also all of the SMD components.And through the help of a lot of flux. I'll find soldering tip as well as thin sodaI added all of the SMD components to the PCB in less than an hourAfter then also soldering in all of the THT componentsthis circuit was finally completes.And only came with one minor package size problemTo program the microcontroller, I connected the ISP-header to on Arduino Unoaccording to pretty much any Arduino Uno ISP programmer tutorial everand started writing the code for the ATtiny.Now, I will not go through the code line by line and explain it.Since I commented the function of each line in the final codes.And I already told you the functional concepts of a microcontroller dimmer a couple of minutes ago.But if you're still confusedthen make sure to watch my Arduino 101, 102, 103 and microcontroller timer videos.Nevertheless though, the code is pretty simple and easily customizablewhich is always a plus point when it comes to microcontroller designs.And after burning the bootloader to the ATtiny and uploading the codesit was time to connect the mains voltage wiresFor which I also added a fuse in series for safety reasonsAnd luckily after powering the circuits nothing exploded.That is why I added the E27 socket with halogen light bulb to the circuitsin a very unsafe way.And tested whether I could dim its brightness which was certainly possibleAnd after connecting the voltage of the light bulb to the oscilloscopewe can see that the waveform is pretty much what we hoped for.Awesome!Even dimming the LED light bulb from my friend was partly possible with a bit of flickerOther LED light bulbs, however, work perfectly fine with my DIY dimmerwhile others did not work at all.The reason for that is pretty complex, which is why I will save this topic for future videoFor now, though, we can say that my DIY dimmer costs around the same as the buy version.Is easily customizable and reaches a lower face angle than the buy versionHowever, the safety aspects of my circuits are quite honestly terribleWhile the buy version obviously had to follow safety standardsSo if we consider that we can get better working commercial dimmers for slightly higher price points,which I might test in the future, I have to say that mostly due to safety reasons,the buy option is this time the winner for me.And with that being said, I hope you enjoyed this video and learned something new.If so, don't forget to like share and subscribeStay creative and I will see you next time.