Everyone knows how proud arduinschiki blink lights
Since it is not interesting to blink LEDs, it will be about controlling a 220 volt incandescent lamp, including controlling its brightness. However, the material applies to some other types of load. This topic is rather beaten, but the information about the features that need to be taken into account is scattered across articles and topics on the forums. I tried to put it together and describe the differences between the schemes and justify the choice of the necessary components.
Choice of controlled load
There are many different types of lamps. Not all of them are amenable to brightness adjustment. And, depending on the type of lamp, different control methods are required. There is a good
article about lamp types. I will consider only lamps powered by AC. For such lamps, there are three basic ways to control the brightness (dimming on the leading edge, on the falling edge and sine-dimming).

SVG format, may not be displayed in older browsers and, especially, in IE
They differ in what part of the AC period is passed through the lamp. About the applicability of these methods can be found
here . This article will deal only with dimming on the anterior front, as this is the easiest and most common method. It is suitable for controlling the brightness of incandescent lamps (including halogen), including those connected via a ferromagnetic (non-electronic) transformer. The same scheme can be used to control the power of heating elements and, to some extent, electric motors, as well as to turn on / off other electrical appliances (without power control).
Select element base
There are many different variants of load management schemes on the Internet. They differ in the following parameters: The first two points are determined by the element base. Very often, for controlling the load, the relay is used as an element that has been proven by many years of experience. But, if you want to control the brightness of the lamp, you must turn it on and off 100 times per second. Relays are not designed for such a load and will quickly fail, even if they can switch so often. If the scheme uses a MOSFET, then it can be opened and closed at any time. We can build it and RL, and RC, and sine dimer. But since it conducts current only in one direction, you need two transistors per channel. In addition, high-voltage MOSFETs are relatively expensive. The simplest and cheapest way is to use a triac. It conducts current in both directions and closes itself when current stops flowing through it. About how it works you can read in the
article DiHalt'a . Next I will rely on what you know.
')
Phase modulation
To control the brightness of the lamp, we need to apply current pulses to the triac's gate at the moments when the current through the triac reaches a certain value. In circuits without a microcontroller, an adjustable voltage divider and a dynistor are used for this. When the voltage on the triac exceeds the threshold at which the dinistor opens, the current flows to the triac gate and opens it.
If control is carried out from the microcontroller, then two options are possible:
- The impulses are equal at the moment of time when necessary. To do this, you will have to bring a signal from the zero-voltage detector to the microcontroller.
- Connect a comparator to the gate of the triac, to which to start the signal from the voltage divider and from the analog output of the microcontroller
The first method is good because it allows you to easily organize the galvanic isolation of the high-voltage part and the microcontroller. Its importance will be discussed later. But lovers of arduino will be upset: to paw burned smoothly, not flashing and not extinguishing, the pulses must be given on time. To do this, you need to control the output from the timer interrupt, and the moments of voltage crossing through zero should be fixed using input capture. These are “undocumented” functions. The problem is solved by the rejection of the arduino libraries and careful reading of the datasheet on avr processors. It is not as difficult as it seems.
The second way to control the triac is extremely simple in software, but due to the lack of galvanic isolation, I would not use it.
Galvanic isolation
The easiest way to control the triac is to connect the microcontroller's leg to the gate. There is even a special series of simistors BTA-600SW controlled by small currents. But then the controller and the entire low-voltage part will not be protected from interference walking on a household network. Some of them can be powerful enough to burn a microcontroller, others will cause failures. In addition, problems immediately arise when the microcontroller communicates with a computer or other microcontrollers: it will be necessary to isolate the communication lines or use differential lines, because to control the triac directly from the microcontroller's foot, the zero potential for it must match the potential of zero in the home network. A computer or another microcontroller that is connected at a different point in the network will almost certainly have no potential. The result will be disastrous.
A simple way to provide galvanic isolation: use the driver for the triac MOC30XX. These chips are different:
- Rated voltage. If for 110 volt networks, there is for 220
- Availability of zero detector
- Driver opening current
The driver with the zero detector (MOC306X) switches only at the beginning of the period. This ensures that there is no interference in the electrical network from the triac. Therefore, if there is no need to control the output power or a controlled device has a large inertia (for example, it is a heating element in a hot plate), a driver with a zero detector will be the optimal choice. But, if you want to control the brightness of the illumination lamp, you need to use a driver without a zero detector (MOC305X) and open it yourself at the right time.
The current required to open is important if you want to control several loads simultaneously. In MOC3051 it is 15 mA, in MOC3052 it is 10 mA. In this case, stm microcontrollers can pass through themselves up to 80-120 mA, and avr up to 200 mA. Exact numbers should be viewed in the appropriate datasheets.
Interference Resistance / Inductive Load Switching Capability
There may be interference in the power grid causing spontaneous opening of the triac or its damage. The source of interference may be:
- Triac load (motor winding)
- Filter (snubber), located next to the triac and designed to protect it
- External disturbance (lightning discharge)
Interference can be both in voltage and current, and the rates of change of the corresponding values are more critical than their amplitudes. In datasheet, the corresponding values are given as:
V - the maximum voltage at which the triac can work. The maximum peak voltage is not much more.
I - The maximum current that the triac can pass through. The maximum peak current is usually much larger.
dV / dt - The maximum rate of change of voltage on a closed triac. If this value is exceeded, it will open spontaneously.
dI / dt - The maximum rate of current change when opening a triac. If this value is exceeded, it will
burn because it does not have time to fully open.
(dV / dt) c - The maximum rate of change of voltage at the close of the triac. Significantly less dV / dt. If exceeded, the triac will continue to conduct current.
(dI / dt) c - The maximum rate of current change at the time of the closing of the triac. Significantly less dI / dt. If exceeded, the triac will continue to conduct current.
Details on the nature of these restrictions and how to make a filter that protects against exceeding these values are described in
Application Note AN-3008 . It is only possible to add to Nemo that there are 3Q triacs in which the dV / dt and dI / dt values are higher than that of ordinary ones due to the inability to work in the 4th quadrant (which is usually not required).
Selection of a triac
Maximum switching current
The maximum switching current is limited by two parameters: the maximum current that the triac can skip and the amount of heat you can take from it. With the first parameter, everything is simple, it is listed in the datasheet. But if you look closely, at a current of 16 amps on the BTA16-600BW about 20 watts are allocated. This heater is no longer possible to shove in the switch box without ventilation.
Minimum switching current
Triac retains conductivity as long as current flows through it. The minimum current required is listed in the datasheet under the name latching current. Accordingly, too powerful a triac will not be able to turn on a low-power light bulb as it will turn off as soon as the control signal disappears from the shutter. But since we independently form this signal with a microcontroller, we can hold the control signal almost to the very end of the half-period, thereby removing the restriction on the minimum load. However, if you do not have time to remove the signal, the triac will not close and the lamp will not go out. With poorly selected constants, the lamps operating at incomplete brightness periodically flash.
Insulation
Triacs in the TO-220 package can be insulated or non-insulated. I first made a mistake and bought the BT137, as a result the cooling radiators were energized, which is undesirable in my case. Triacs with BTA markings are insulated, with BTB markings not.
Overload protection
Do not rely on circuit breakers. Look at the
specification , with an overload of 1.4 times the machine must shut down
no earlier than in an hour. A quick disconnection occurs only when overloaded by 5 times (for machines of type C). This is done so that the machine does not turn off when you turn on devices that require much more energy at start-up than during continuous operation. An example of such a device is a refrigerator.
The triac must be protected with a separate fuse, or the current through it must be monitored and disconnected when overloaded, allowing it to cool.
Short circuit protection
If the incandescent lamp burns out, a spark discharge may occur that has a very low resistance. As a result, the circuit is actually short-circuited, which leads to a triac burnout.
Triac can fade due to two reasons:
- Excess dI / dt. The triac does not have time to open completely, the current does not flow through the entire crystal, local hot regions are formed that burn the crystal.
- The excess of the joule integral I ^ 2t. Sets the amount of heat, the accumulation of which in the crystal will lead to the destruction of the crystal.
dI / dt is limited by the inductance of the wiring and the internal capacitance of the triac. Since dI / dt is large enough (50 A / s for BTA16), the inductance of the supply wiring can suffice if it is long enough. You can insure and add a small inductance in the form of several turns of wire around the core.
If the Joule integral is exceeded, it is possible to fight either by reducing the time for the current to pass through the triac or by limiting the current. Since the triac does not close until the current passes through zero, it is not possible to make a current passage time of less than one half-period without introducing additional breakers. As such a breaker you can use:
- High-speed fuse. A conventional fuse will not work since the triac will burn before it works. But these fuses are more expensive than new triacs.
- Reed switch / relay. If you can find one that can withstand short-term large currents.
You can go the other way. BTA16-600 can withstand a current of 160 Amer for one period. If the resistance of the closed circuit is about 1.5 ohms, then it will withstand a half period. Resistance to wiring will give 0.5 ohms. It remains to add to the circuit resistance of 1 ohm. The circuit will become less efficient and one more heating pad will appear, emitting up to 16 W of heat during normal operation (0.45 W when operating a 100-watt lamp), but the triac will not burn if you have time to turn it off and take care of good cooling so that short circuit time.
Additional benefit can be derived from this resistance: by measuring the voltage drop across it, one can recognize the current flowing through the triac. The resulting value can be used to determine the short circuit or overload and disconnect the triac.
Conclusion
I do not pretend to absolute fidelity to all written. The article was written in order to streamline the knowledge read on the Internet and see if I forgot what. In particular, I have not tried the section on overload protection in practice. If I am somewhere wrong, I would be interested to learn about errors.
There are no schemes in the article: those familiar with the topic already know them by heart, and the beginner will have to look into the datasheet of the MOC3052 or the AN-3008, and he may also learn something else and will not mindlessly implement the finished scheme.