Post Top Ad

Thursday, June 13, 2024

How to regulate 230V AC bulb light with BT136, diy idea


 How to regulate 230V AC bulb light with BT136, diy idea

Switching an AC load with an Arduino is rather simple: either a mechanical relay or a solid state relay with an optically isolated Triac. (I say Arduino, but if you use an 8051 or PIC16F877A microcontroller, there is stuff for you too here.)


It becomes a bit more tricky if one wants to dim a mains AC lamp with an arduino: just limiting the current through e.g. A transistor is not really possible due to the large power of the transistor then will need to dissipate, resulting in a lot of heat and it is also not efficient from an energy use point of view.


Phase cutting

During a part of the sinus AC wave. This is called leading edge cutting.

One could let an Arduino just open the Triac for a number of microseconds, but that has the problem that it is unpredictable during what part of the sinus wave the triac opens and therefore the dimming level is unpredictable. One needs a reference point in the sinus wave.

For that a zero crossing detector is necessary. This is a circuit that tells the Arduino (or another micro controller) when the sinus-wave goes through zero and therefore gives a defined point on that sinus wave.

Opening the Triac after a number of microseconds delay starting from the zero crossing therefore gives a predictable level of dimming.

Pulse Skip Modulation

Another way of doing this is by Pulse Skip Modulation. With PSM, one or more full cycles (sinus waves) are transferred to the load and then one or more cycles are not. Although effective, it is not a good way to dim lights as there is a chance for flickering. Though it might be tempting, in PSM one should always allow a full sinus wave to be passed to the load, not a half sinus as in that case the load will be fed actually from DC which is not a good thing for most AC loads. The difference between leading edge cutting and PSM is mainly in the software: in both cases one will need a circuit that detects the zero crossing and that can control a triac.

A circuit that can do this is easy to build: The zero crossing is directly derived from the rectified mains AC lines – via an optocoupler of course – and gives a signal every time the wave goes through zero. Because the sine wave first goes through double phased rectification, the zero-crossing signal is given regardless whether the sinus wave goes up through zero or down through zero. This signal then can be used to trigger an interrupt in the Arduino.


PWM dimming

PWM dimming, as in LEDs is not done frequently with AC loads for a number of reasons. It is possible though. Check this instructable to see how.


It goes without saying that there needs to be a galvanic separation between the Arduino side of things and anything connected to the mains. For those who do not understand 'galvanic separation' it means 'no metal connections' thus ---> opto-couplers. BUT, if you do not understand 'galvanic separation', maybe you should not build this.

The circuit pictured here does just that. The mains 220Volt voltage is led through two 30k resistors to a bridge rectifier that gives a double phased rectified signal to a 4N25 opto-coupler. The LED in this opto-coupler thus goes low with a frequency of 100Hz and the signal on the collector is going high with a frequency of 100Hz, in line with the sinusoid wave on the mains net. The signal of the 4N25 is fed to an interrupt pin in the Arduino (or other microprocessor). The interrupt routine feeds a signal of a specific length to one of the I/O pins. The I/O pin signal goes back to our circuit and opens the LED and a MOC3021, that triggers the Opto-Thyristor briefly. The LED in series with the MOC3021 indicates if there is any current going through the MOC3021. Mind you though that in dimming operation that light will not be very visible because it is very short lasting. Should you choose to use the triac switch for continuous use, the LED will light up clearly.

Mind you that only regular incandescent lamps are truly suitable for dimming. It will work with a halogen lamp as well, but it will shorten the life span of the halogen lamp. It will not work with any CFL lamps, unless they are specifically stated to be suitable for a dimmer. The same goes for LED lamps


NOTE! It is possible that depending on the LED that is used, the steering signal just does not cut it and you may end up with a lamp that just flickers rather than being smoothly regulated. Replacing the LED with a wire bridge will cure that. The LED is not really necessary. Increase the 220 ohm resistor to 470 then

You will find two pictures for the PCB: my first one, that I leave here for documentation purposes and a slightly altered new one. The difference is that I left out the zenerdiode as it is not really necessary and I gave the LED itÅ› own (1k) resistor: it is no longer in series with the Optocoupler, that now has a 470 Ohm resistor. I made the PCB via direct toner transfer and then etched it in a hydrochloric acid/Hydrogenperoxide bath. There are of instructables telling how to do that. You can use the attached print design to do the same. Populating the print is quite straightforward. I used IC feet for the opto-couplers and the bridge rectifier.

Download the print here.

Note: You need Fritzing for this. For the direct toner transfer, the printed side of the printed pdf file, goes directly against the copper layer for transfer. Once it is transferred, you will be looking at the ink from the other side and thus see the text normal again. I made slight alterations in the PCB: I removed the zenerdiode and the LED is no longer in series with the optocoupler.

I used a TIC206. That can deliver 4 amps. Keep in mind though that the copper tracks of the PCB will not be able to withstand 4 Amperes. For any serious load, solder a piece of copper installation wire on the tracks leading from the TRIAC to the connectors and on the track between the two connectors.


In case it is not clear what the inputs are: from top to bottom on the second picture:

+5Volts

Interrupt signal (going to D2 on arduino)

Triac signal (coming from D3 on Arduino)

Ground


NOTE:

If you have an H11AA1 or IL 250, 251 or 252 opto-coupler then you do not need the bridge rectifier. These have two anti-parellel diodes and thus can handle AC. It is pin compatible with the 4N25, just pop it in and solder 2 wire-bridges between R5 and + and R7 and -. The LTV814 is not pincompatibleShould you want to use it for inductive loads, then a snubber circuit is necessary. The figure shows the modifications for use with inductive loads. Mind you, this is not something I tried as I just wanted to dim lamps, but it is based on examples and theory available on the internet. You would have to adapt the provided PCB

The top figure shows the circuit as is, for dimming a lamp. It is in all its simplicity just a resistor to trigger the gate via the diac in the optocoupler. The value of 1k may be changed as discussed in the text before.

The bottom figure gives an omnipresent circuit for use in inductive loads.


It consists of an additional resistor and capacitor. The gate current is below 15mA. If you are using a less sensitive triac to control the inductive load, reduce the resistor from 2.4kΩ to 1.2kΩ, providing more current to drive the triac and increase the capacitor to 200nF. This snubber circuit is there to protect the triac from the high voltage generated from an inductive load. The feedback may cause some problem for non-inductive load. The small leakage can be significant enough to turn on a small load (for example a lamp).

If you could care less about the theory, but just want the software, go to the next step


The way to use an AC dimmer/fader is quite simple once you understand the basics:


In AC the power fed to the lamp is directly related to the total surface of the sinus wave, the lamp can be regulated by only allowing a predictable portion of that sinus wave to flow through the lamp.


As such we need a reference point on that sinus from where we calculate when the lamp has to be switched on.


The easiest reference point to use is the so called 'zero crossing': the moment that the light goes through zero.

After each zero crossing there is one full half of the sinus wave available to send through the lamp.

So what the software needs to do is to detect the zerocrossing, and then wait for a set amount of time on that sinuswave to switch on the TRIAC.


There are2 major grid frequencies


In the world: 50 Hz in Europe and most of Asia and Africa and 60 Hz in America's (and parts of the Caribbean). There are 2 major voltages in the world: 110-120V and 220-240V but they are not important for the mathematics here


For ease of use I will take the 50Hz frequency as an example:

50Hz is 50 waves per second.

Each sinuswave thus takes 1000ms/50=20ms (miliseconds)

As there are 2 sinuspeaks in a wave that means that after every zero detection there is a 10ms period that we can regulate.

Should we ignite the lamp directly at the beginning of that period, the lamp will receive full power, should we do it at the end of that 10ms period, the lamp will receive no ower and we should do it halfway, the lamp will receive half power .

As we are using TRIACs, what the software needs to do is to wait for the zero point at the sinuscurve, take note of that and then wait a specified amount of time within that 10ms period to send a pulse to the TRIAC.

If it sends that pulse at 5ms, the lamp will only burn at half power.


In the Circuit, the zero detection is done by the biphase optocoupler and is available as the X-signal on the board.

There are basically 2 ways for a microcontroller to detect that signal:

1-a continuous 'polling' of the Zero Crossing pin2-using an interrupt to tell the program that there was a zero crossing

The main difference between the two is that in 'polling' every time the computer goes through it's main loop it needs to check the pin. If your program is busy doing a lot of other things, it might be too late in checking the zero crossing pin, while when using an interrupt, it does not matter what the program is busy with. The interrupt is sort of 'tapping it on the shoulder' saying "Hey look, something came up that you need to attend to NOW".


After the zero crossing is detected the program needs to wait for a specified amount of time and then switch on the TRIAC.

Also here, that waiting can be done in two different ways

1- By issuing a 'wait' command

2-by using a timer interrupt

Again, both these methods have their pro's and con's. The 'wait' command ('delay' in Arduino language) literally let's the computer wait for the required time and it can't do anything else in the mean time. if the lamp is burning at low power by letting the computer wait say 9ms, that means that every 10ms the computer is told to wait 9ms: ergo it will be idle 90% of the time. That is fine if your controller is only used to control the lamp, but if it needs to do other stuff then little time is left.

Using a timer interrupt solves that. Basically what that does is that the program tells the timer: ¨Hey, I just heard we have a zero crossing, I got to do something else, but you just wait 4.5ms and then switch on the Triac" So the program goes on it's merry way and 4.5ms (as an example) after it was given notice there was a 0-crossing, the timer switches on the TRIAC.


 How to regulate 230V AC bulb light with BT136, diy idea

Switching an AC load with an Arduino is rather simple: either a mechanical relay or a solid state relay with an optically isolated Triac. (I say Arduino, but if you use an 8051 or PIC16F877A microcontroller, there is stuff for you too here.)


It becomes a bit more tricky if one wants to dim a mains AC lamp with an arduino: just limiting the current through e.g. A transistor is not really possible due to the large power of the transistor then will need to dissipate, resulting in a lot of heat and it is also not efficient from an energy use point of view.


Phase cutting

During a part of the sinus AC wave. This is called leading edge cutting.

One could let an Arduino just open the Triac for a number of microseconds, but that has the problem that it is unpredictable during what part of the sinus wave the triac opens and therefore the dimming level is unpredictable. One needs a reference point in the sinus wave.

For that a zero crossing detector is necessary. This is a circuit that tells the Arduino (or another micro controller) when the sinus-wave goes through zero and therefore gives a defined point on that sinus wave.

Opening the Triac after a number of microseconds delay starting from the zero crossing therefore gives a predictable level of dimming.

Pulse Skip Modulation

Another way of doing this is by Pulse Skip Modulation. With PSM, one or more full cycles (sinus waves) are transferred to the load and then one or more cycles are not. Although effective, it is not a good way to dim lights as there is a chance for flickering. Though it might be tempting, in PSM one should always allow a full sinus wave to be passed to the load, not a half sinus as in that case the load will be fed actually from DC which is not a good thing for most AC loads. The difference between leading edge cutting and PSM is mainly in the software: in both cases one will need a circuit that detects the zero crossing and that can control a triac.

A circuit that can do this is easy to build: The zero crossing is directly derived from the rectified mains AC lines – via an optocoupler of course – and gives a signal every time the wave goes through zero. Because the sine wave first goes through double phased rectification, the zero-crossing signal is given regardless whether the sinus wave goes up through zero or down through zero. This signal then can be used to trigger an interrupt in the Arduino.


PWM dimming

PWM dimming, as in LEDs is not done frequently with AC loads for a number of reasons. It is possible though. Check this instructable to see how.


It goes without saying that there needs to be a galvanic separation between the Arduino side of things and anything connected to the mains. For those who do not understand 'galvanic separation' it means 'no metal connections' thus ---> opto-couplers. BUT, if you do not understand 'galvanic separation', maybe you should not build this.

The circuit pictured here does just that. The mains 220Volt voltage is led through two 30k resistors to a bridge rectifier that gives a double phased rectified signal to a 4N25 opto-coupler. The LED in this opto-coupler thus goes low with a frequency of 100Hz and the signal on the collector is going high with a frequency of 100Hz, in line with the sinusoid wave on the mains net. The signal of the 4N25 is fed to an interrupt pin in the Arduino (or other microprocessor). The interrupt routine feeds a signal of a specific length to one of the I/O pins. The I/O pin signal goes back to our circuit and opens the LED and a MOC3021, that triggers the Opto-Thyristor briefly. The LED in series with the MOC3021 indicates if there is any current going through the MOC3021. Mind you though that in dimming operation that light will not be very visible because it is very short lasting. Should you choose to use the triac switch for continuous use, the LED will light up clearly.

Mind you that only regular incandescent lamps are truly suitable for dimming. It will work with a halogen lamp as well, but it will shorten the life span of the halogen lamp. It will not work with any CFL lamps, unless they are specifically stated to be suitable for a dimmer. The same goes for LED lamps


NOTE! It is possible that depending on the LED that is used, the steering signal just does not cut it and you may end up with a lamp that just flickers rather than being smoothly regulated. Replacing the LED with a wire bridge will cure that. The LED is not really necessary. Increase the 220 ohm resistor to 470 then

You will find two pictures for the PCB: my first one, that I leave here for documentation purposes and a slightly altered new one. The difference is that I left out the zenerdiode as it is not really necessary and I gave the LED itÅ› own (1k) resistor: it is no longer in series with the Optocoupler, that now has a 470 Ohm resistor. I made the PCB via direct toner transfer and then etched it in a hydrochloric acid/Hydrogenperoxide bath. There are of instructables telling how to do that. You can use the attached print design to do the same. Populating the print is quite straightforward. I used IC feet for the opto-couplers and the bridge rectifier.

Download the print here.

Note: You need Fritzing for this. For the direct toner transfer, the printed side of the printed pdf file, goes directly against the copper layer for transfer. Once it is transferred, you will be looking at the ink from the other side and thus see the text normal again. I made slight alterations in the PCB: I removed the zenerdiode and the LED is no longer in series with the optocoupler.

I used a TIC206. That can deliver 4 amps. Keep in mind though that the copper tracks of the PCB will not be able to withstand 4 Amperes. For any serious load, solder a piece of copper installation wire on the tracks leading from the TRIAC to the connectors and on the track between the two connectors.


In case it is not clear what the inputs are: from top to bottom on the second picture:

+5Volts

Interrupt signal (going to D2 on arduino)

Triac signal (coming from D3 on Arduino)

Ground


NOTE:

If you have an H11AA1 or IL 250, 251 or 252 opto-coupler then you do not need the bridge rectifier. These have two anti-parellel diodes and thus can handle AC. It is pin compatible with the 4N25, just pop it in and solder 2 wire-bridges between R5 and + and R7 and -. The LTV814 is not pincompatibleShould you want to use it for inductive loads, then a snubber circuit is necessary. The figure shows the modifications for use with inductive loads. Mind you, this is not something I tried as I just wanted to dim lamps, but it is based on examples and theory available on the internet. You would have to adapt the provided PCB

The top figure shows the circuit as is, for dimming a lamp. It is in all its simplicity just a resistor to trigger the gate via the diac in the optocoupler. The value of 1k may be changed as discussed in the text before.

The bottom figure gives an omnipresent circuit for use in inductive loads.


It consists of an additional resistor and capacitor. The gate current is below 15mA. If you are using a less sensitive triac to control the inductive load, reduce the resistor from 2.4kΩ to 1.2kΩ, providing more current to drive the triac and increase the capacitor to 200nF. This snubber circuit is there to protect the triac from the high voltage generated from an inductive load. The feedback may cause some problem for non-inductive load. The small leakage can be significant enough to turn on a small load (for example a lamp).

If you could care less about the theory, but just want the software, go to the next step


The way to use an AC dimmer/fader is quite simple once you understand the basics:


In AC the power fed to the lamp is directly related to the total surface of the sinus wave, the lamp can be regulated by only allowing a predictable portion of that sinus wave to flow through the lamp.


As such we need a reference point on that sinus from where we calculate when the lamp has to be switched on.


The easiest reference point to use is the so called 'zero crossing': the moment that the light goes through zero.

After each zero crossing there is one full half of the sinus wave available to send through the lamp.

So what the software needs to do is to detect the zerocrossing, and then wait for a set amount of time on that sinuswave to switch on the TRIAC.


There are2 major grid frequencies


In the world: 50 Hz in Europe and most of Asia and Africa and 60 Hz in America's (and parts of the Caribbean). There are 2 major voltages in the world: 110-120V and 220-240V but they are not important for the mathematics here


For ease of use I will take the 50Hz frequency as an example:

50Hz is 50 waves per second.

Each sinuswave thus takes 1000ms/50=20ms (miliseconds)

As there are 2 sinuspeaks in a wave that means that after every zero detection there is a 10ms period that we can regulate.

Should we ignite the lamp directly at the beginning of that period, the lamp will receive full power, should we do it at the end of that 10ms period, the lamp will receive no ower and we should do it halfway, the lamp will receive half power .

As we are using TRIACs, what the software needs to do is to wait for the zero point at the sinuscurve, take note of that and then wait a specified amount of time within that 10ms period to send a pulse to the TRIAC.

If it sends that pulse at 5ms, the lamp will only burn at half power.


In the Circuit, the zero detection is done by the biphase optocoupler and is available as the X-signal on the board.

There are basically 2 ways for a microcontroller to detect that signal:

1-a continuous 'polling' of the Zero Crossing pin2-using an interrupt to tell the program that there was a zero crossing

The main difference between the two is that in 'polling' every time the computer goes through it's main loop it needs to check the pin. If your program is busy doing a lot of other things, it might be too late in checking the zero crossing pin, while when using an interrupt, it does not matter what the program is busy with. The interrupt is sort of 'tapping it on the shoulder' saying "Hey look, something came up that you need to attend to NOW".


After the zero crossing is detected the program needs to wait for a specified amount of time and then switch on the TRIAC.

Also here, that waiting can be done in two different ways

1- By issuing a 'wait' command

2-by using a timer interrupt

Again, both these methods have their pro's and con's. The 'wait' command ('delay' in Arduino language) literally let's the computer wait for the required time and it can't do anything else in the mean time. if the lamp is burning at low power by letting the computer wait say 9ms, that means that every 10ms the computer is told to wait 9ms: ergo it will be idle 90% of the time. That is fine if your controller is only used to control the lamp, but if it needs to do other stuff then little time is left.

Using a timer interrupt solves that. Basically what that does is that the program tells the timer: ¨Hey, I just heard we have a zero crossing, I got to do something else, but you just wait 4.5ms and then switch on the Triac" So the program goes on it's merry way and 4.5ms (as an example) after it was given notice there was a 0-crossing, the timer switches on the TRIAC.

No comments:

Post a Comment

Post Top Ad

Pages