Portal about bathroom renovation. Useful tips

Circuit for controlling two relays using one microcontroller pin. One pin of the microcontroller controls two relays Calculation of the control transistor

To indicate the signal level or constant voltage, current, polycomparator microcircuits like AN6884, KA2284, BA6124 or many other similar ones are often used. Such a microcircuit is a set of comparators, with outputs to LEDs, as well as a measuring circuit and a pre-amplification circuit, detector.

Figure 1 shows a typical connection diagram for the AN6884, KA2284, BA6124 microcircuits. There are a minimum of details, and we get a five-threshold level indicator. LEDs work on the “thermometer” principle, that is, if they are placed sequentially in a line and recognize it all as a continuous line, then the larger the signal, the longer the line (the more LEDs are lit).

But, there are cases when it is necessary not only to visually determine the signal level, but also to take some measures if the signal level has reached a certain level. For example, when the HL5 LED lights up, the electromagnetic relay needs to turn on and turn on a certain load or device with its contacts.

Relay connection diagram

Figure 2 shows how you can connect the relay coil. But first, pay attention to Figure 1 - all the LEDs are connected to the outputs of the microcircuit directly, without any current-limiting resistors. Although, in the literature there are circuits with current-limiting resistors.

In fact, there is no need for current-limiting resistors regarding the AN6884, KA2284, BA6124 microcircuits and their analogues, because inside the microcircuit, there is a current limiting circuit at each output. Therefore, the voltage between the output and the positive power rail is never greater than the forward voltage drop across the LED.

Rice. 1. Typical circuit diagram for connecting microcircuits AN6884, KA2284, BA6124.

Rice. 2. Diagram of connecting the relay to the signal indicator channel.

But such a small voltage is not enough to wind a relay, and often even to open a transistor switch. However, you can increase the voltage between the output and the power bus simply by turning on an additional current-limiting resistor (R2 in Figure 2). Thanks to it, the voltage between the output of the microcircuit and the power bus increases. By changing the resistance of this resistor you can set the required voltage.

Figure 2 shows a control circuit for the relay winding - turning it on when the HL5 LED is turned on. When HL5 is turned on, the voltage at pin 1 drops relative to the common minus, but increases relative to the power bus. Reaches a level sufficient to open transistor VT1. It opens, and after it the more powerful transistor VT2 opens. And in its collector circuit the relay winding K1 is turned on.

The relay supply voltage may differ from the microcircuit supply voltage. In exactly the same way, you can connect the relay to any other output of a microcircuit such as AN6884, KA2284, BA6124, and even make five relays according to the number of outputs.

Then is this necessary? There can be many reasons. For example, if the volume level is exceeded, you need to turn off the sound source or turn on the alarm.

Or you need to react to excess current in the load. Or you can make a switch consisting of a variable resistor and this circuit. When you rotate the variable resistor knob, the voltage at the input of the microcircuit will change, and the relays will turn on at its outputs.

Removing the signal from the indicator

If you need to control not a relay, but some kind of digital device, for example, when a certain signal level is exceeded, apply a logical one to the input of a microcontroller or alarm device, you can assemble the circuit shown in Figure 3. Here, as an example, we also take the option with the HL5 LED, although, Of course, it is possible from any other output of the microcircuit.

Fig.3. Circuit for receiving a logical signal from an indicator segment.

When HL5 is ignited, the voltage at the base of VT1 relative to its own emitter increases, the transistor opens and the voltage at its collector increases to the level of a logical one, corresponding to the supply voltage of the microcircuit.

Rice. 4. Connection with opto-isolation.

Well, the last option is to use an optocoupler. You can use any optocoupler, either with a powerful triac to control some kind of heater (the so-called “solid-state relay”), or a low-power transistor to transmit a command to another circuit.

In any case, there are two options: either connect the optocoupler LED in series with the indicator LED, as shown in Figure 4, or instead of it, as is not shown in the figure, but you can guess, but only if there is no need for indication.

Karavkin V. RK-2016-04.

Gunther Kraut, Germany

Logic "1", logic "0" and high impedance. Three output states correspond to three engine states: “forward”, “reverse” and “stop”

To control two independent loads, such as, say, a relay, two microcontroller I/O ports are usually required. In this case, you have the opportunity to turn on two relays, turn on one and turn off the other, or turn off both. If you do not need to turn on two relays at the same time, you can control the remaining three states using one pin of the microcontroller. This uses a high impedance output state.

This circuit can be used, for example, in controlling electric motors. The direction of rotation of the motor depends on which of its two phases is selected. For phase switching, you can use both classic electromechanical and solid-state MOS relays. In any of the options, when both relays open, the engine stops.

To control electromechanical relays, the circuit shown in Figure 1 is used. With a logical “1” at the output of the microcontroller, transistor Q 1 turns on relay REL 1, which allows the motor to rotate in the forward direction. When the output switches to “0”, transistor Q 3 is turned off. This leads to the closure of the REL 2 contacts, and the motor begins to rotate in the opposite direction. If the microcontroller port is in a high impedance state, transistors Q 1, Q 2 and Q 3 turn off, since the 1 V voltage at the base of Q 2 is less than the sum of the threshold voltages of the base-emitter junctions Q 1 and Q 2 and the voltage drop across the diode D 1. Both relays turn off and the motor stops. A voltage of 1 V can be obtained using a voltage divider or emitter follower. Diodes D 2 and D 3 serve to protect the collectors Q 1 and Q 2 from voltage surges that occur when the relay is turned off. Almost any low-power NPN and PNP transistors can be used in the circuit. The choice of D 1 is also unimportant.

The circuit for controlling the MOS relay is simpler, since the LEDs can be connected directly to the output of almost any microcontroller (Figure 2). Logical “1” turns on the relay LED S 1, and logical “0” turns on S 2, opening the corresponding output triacs. When the port enters a high-impedance state, both LEDs turn off because the 1.2V DC voltage is less than the sum of the threshold voltages of the two LEDs. Varistors R 3, R 5 and damping circuit C 1, R 4, C 2, R 6 serve to protect the MOS relay. The parameters of these elements are selected in accordance with the load.

For connecting the load to the microcontroller you will need the following things:

  • myself microcontroller
  • bipolar transistor NPN type
  • two resistors R1 (500 Ohm) and R2 (5 kOhm)

Drawing up a load connection diagram

So. Maximum current per pin microcontroller is 20mA, the output voltage is 5V. For example, we want connect to microcontroller DC stepper motor with control voltage 12V, current 200mA. The connection diagram is as follows:

Connecting the load to the microcontroller

Calculation of the control transistor

Times output current microcontroller can be a maximum of 20mA, but you need to get 200mA, then you need to select an NPN transistor with a minimum gain

hFE = 200mA / 20mA = 10

Generally speaking, it is considered bad form to output a maximum of 20mA from the mic, so let's count on an output of 10mA. So, set up for a decline loads to our microcontroller twice, now we will select a transistor with a minimum coefficient

hFE = 200mA / 10mA = 20

In this case, the maximum collector current, and accordingly the load current, will be

Ic=Ib*hFE=0.01A*20=0.2A=200mA

So, let's choose any transistor that suits us, for example, a bourgeois one BC337.

The characteristics of the bipolar NPN transistor BC337 are as follows:

  • Vcb max = 50V
  • Vce max = 45V
  • Veb max = 5V
  • Ic max = 0.8A
  • hFE = 100

Oh my God! hFE=100! This means that the load current will be equal to Ic=0.01*100=1A?

No! In this case, the transistor will open wide open, he'll be ready produce the maximum permissible current for it 0.8A (see characteristics above), but in fact the current in the collector-emitter circuit will be the current consumption of the motor (in our case, the motor “eats” 200mA).

Limiting resistor calculation

First of all, we need to select resistor R1 so that it limits the current coming out of microcontroller. The calculation is simple: you need to divide the supply voltage of 5V by the maximum base current of 10mA

R1 = 5V / 0.01A = 500Ohm

Resistor R2 is not load, it is needed so that after removing the voltage from the base, the remaining current between microcontroller and the transistor base was vented to ground. Otherwise, it is possible that the transistor will remain open after the control pulse is removed. The recommended value of resistor R2 is 10 times greater than R1

Hello Geektimes!

Controlling powerful loads is a fairly popular topic among people who are in one way or another concerned with home automation, and in general, regardless of the platform: be it Arduino, Rapsberry Pi, Unwired One or another platform, turn it on and off some kind of heater, boiler or a duct fan will have to be used sooner or later.

The traditional dilemma here is what to actually commute with. As many have learned from their sad experience, Chinese relays do not have the proper reliability - when switching a powerful inductive load, the contacts spark strongly, and at one point they may simply stick. You have to install two relays - the second one to protect against opening.

Instead of a relay, you can install a triac or solid-state relay (essentially the same thyristor or field-effect device with a logical signal control circuit and an optocoupler in one package), but they have another disadvantage - they heat up. Accordingly, a radiator is needed, which increases the dimensions of the structure.

I want to tell you about a simple and quite obvious, but at the same time rarely seen scheme that can do this:

  • Galvanic isolation of input and load
  • Switching of inductive loads without current and voltage surges
  • No significant heat generation even at maximum power

But first, a few illustrations. In all cases, TTI relays of the TRJ and TRIL series were used, and a 650 W vacuum cleaner was used as the load.

Classic scheme - we connect the vacuum cleaner through a regular relay. Then we connect an oscilloscope to the vacuum cleaner (Caution! Either the oscilloscope or the vacuum cleaner - or better yet, both - must be galvanically isolated from the ground! Don’t put your fingers or eggs in the salt shaker! They don’t joke with 220 V!) and take a look.

Include:

I had to reach almost the maximum mains voltage (trying to tie an electromagnetic relay to the zero crossing is a disastrous task: it is too slow). A short surge with almost vertical fronts boomed in both directions, and interference flew in all directions. Expected.

Turn off:

A sudden loss of voltage on an inductive load does not bode well - the surge will fly upward. In addition, do you see this noise on the sine wave milliseconds before the actual shutdown? This is the sparking of the relay contacts that have begun to open, which is why they will one day become stuck.

So, it is bad to switch an inductive load with a “naked” relay. What will we do? Let's try to add a snubber - an RC chain of a 120 Ohm resistor and a 0.15 µF capacitor.

Include:

Better, but not much. The ejection decreased in height, but was generally preserved.

Turn off:

Same picture. The debris remained, moreover, the sparking of the relay contacts remained, although greatly reduced.

Conclusion: with a snubber it is better than without a snubber, but it does not solve the problem globally. However, if you want to switch inductive loads with a regular relay, install a snubber. The ratings must be selected for a specific load, but a 1-W resistor at 100-120 Ohms and a capacitor at 0.1 µF seem to be a reasonable option for this case.

Related literature: Agilent - Application Note 1399, “Maximizing the Life Span of Your Relays.” When operating the relay on the worst type of load - a motor, which, in addition to inductance, also has a very low resistance at start - good authors recommend reducing the rating life of the relay five times.

Now let’s make a knight’s move - we will combine a triac, a triac driver with zero detection and a relay into one circuit.

What's in this diagram? On the left is the entrance. When “1” is applied to it, capacitor C2 is almost instantly charged through R1 and the lower half of D1; Optorelay VO1 turns on, waits for the nearest zero crossing (MOC3063 - with built-in zero detector circuit) and turns on triac D4. The load starts.

Capacitor C1 is charged through a chain of R1 and R2, which takes approximately t=RC ~ 100 ms. These are several periods of mains voltage, that is, during this time the triac will have time to turn on, guaranteed. Next, Q1 opens and relay K1 turns on (as well as LED D2, shining with a pleasant emerald light). The relay contacts bypass the triac, so then - until it turns off - it does not take part in the operation. And it doesn't heat up.

Switching off is in reverse order. As soon as “0” appears at the input, C1 is quickly discharged through the upper arm of D1 and R1, the relay turns off. But the triac remains on for about 100 ms, since C2 is discharged through the 100-kilo-ohm R3. Moreover, since the triac is held open by current, even after VO1 is turned off, it will remain open until the load current drops in the next half-cycle below the holding current of the triac.

Inclusion:

Shutdown:

Beautiful, isn't it? Moreover, when using modern triacs that are resistant to rapid changes in current and voltage (all major manufacturers have such models - NXP, ST, Onsemi, etc., names begin with “BTA”), a snubber is not needed at all, in any form.

Moreover, if you remember the smart people from Agilent and look at how the current consumed by the motor changes, you get this picture:

The starting current exceeds the operating current by more than four times. During the first five periods - the time by which the triac is ahead of the relay in our circuit - the current drops by approximately half, which also significantly softens the requirements for the relay and prolongs its life.

Yes, the circuit is more complex and more expensive than a regular relay or a regular triac. But often it's worth it.

The following articles will include devices that need to control external loads. By external load I mean everything that is attached to the legs of the microcontroller - LEDs, light bulbs, relays, motors, actuators... well, you get the idea. And no matter how hackneyed this topic may be, in order to avoid repetition in the following articles, I still risk not being original - you will forgive me :). I will briefly, in recommendatory form, show the most common ways to connect the load (if you want to add something, I will be only too glad).
Let’s immediately agree that we are talking about a digital signal (a microcontroller is still a digital device) and we will not deviate from the general logic: 1 - included, 0 -turned off. Let's begin.

DC loads include: LEDs, lamps, relays, DC motors, servos, various actuators, etc. Such a load is most simply (and most often) connected to a microcontroller.

1.1 Connection loads through a resistor.
The simplest and probably most often used method when it comes to LEDs.

A resistor is needed in order to limit the current flowing through the microcontroller leg to permissible 20mA. It is called ballast or damping. You can approximately calculate the resistor value by knowing the load resistance Rн.

Rquenching =(5v / 0.02A) – Rн = 250 – Rн

As you can see, even in the worst case, when the load resistance is zero, 250 Ohms is enough to ensure that the current does not exceed 20 mA. This means that if you don’t want to count something there, put 300 Ohm and you will protect the port from overload. The advantage of the method is obvious - simplicity.

1.2 Connection loads using a bipolar transistor.
If it so happens that your load consumes more than 20mA, then, of course, a resistor will not help here. You need to somehow increase (read strengthen) the current. What is used to amplify the signal? Right. Transistor!

It is more convenient to use for strengthening n-p-n transistor connected according to the circuit OE. With this method, you can connect a load with a higher supply voltage than the power supply to the microcontroller. The resistor on the base is limiting. It can vary within a wide range (1-10 kOhm), in any case the transistor will operate in saturation mode. The transistor can be anything n-p-n transistor. The gain is practically irrelevant. The transistor is selected based on the collector current (the current we need) and the collector-emitter voltage (the voltage that powers the load). Power dissipation also matters - so as not to overheat.

Of the common and easily accessible ones, you can use BC546, BC547, BC548, BC549 with any letters (100mA), and even the same KT315 will do (those who have leftovers from old stocks).
- Datasheet for bipolar transistor BC547

1.3 Connection loads using a field effect transistor.
Well, what if the current of our load is within ten amperes? It will not be possible to use a bipolar transistor, since the control currents of such a transistor are large and will most likely exceed 20 mA. The output can be either a composite transistor (read below) or a field-effect transistor (aka MOS, aka MOSFET). The field-effect transistor is simply a wonderful thing, since it is controlled not by current, but by potential at the gate. This makes it possible for microscopic gate current to control large load currents.

Any n-channel field-effect transistor is suitable for us. We choose, like bipolar, by current, voltage and power dissipation.

When turning on a field-effect transistor, you need to consider a number of points:
- since the gate is, in fact, a capacitor, when the transistor switches, large currents flow through it (short-term). In order to limit these currents, a limiting resistor is placed in the gate.
— the transistor is controlled by low currents and if the output of the microcontroller to which the gate is connected is in a high-impedance Z-state, the field switch will begin to open and close unpredictably, catching interference. To eliminate this behavior, the microcontroller leg must be “pressed” to the ground with a resistor of about 10 kOhm.
The field-effect transistor, against the background of all its positive qualities, has a drawback. The cost of controlling low current is the slowness of the transistor. Of course, it will handle PWM, but if the permissible frequency is exceeded, it will respond to you with overheating.

1.4 Connection loads using a compound Darlington transistor.
An alternative to using a field-effect transistor for high-current loads is to use a composite Darlington transistor. Externally, it is the same transistor as, say, a bipolar one, but internally a pre-amplifier circuit is used to control the powerful output transistor. This allows low currents to drive a powerful load. The use of a Darlington transistor is not as interesting as the use of an assembly of such transistors. There is such a wonderful microcircuit as ULN2003. It contains as many as 7 Darlington transistors, each of which can be loaded with a current of up to 500 mA, and they can be connected in parallel to increase the current.

The microcircuit is very easy to connect to the microcontroller (just pin to pin), has convenient wiring (input opposite output) and does not require additional wiring. As a result of this successful design, ULN2003 is widely used in amateur radio practice. Accordingly, it will not be difficult to get it.
- Datasheet for Darlington assembly ULN2003

If you need to control AC devices (most often 220v), then everything is more complicated, but not much.

2.1 Connection loads using a relay.
The simplest and probably most reliable connection is using a relay. The relay coil itself is a high-current load, so you cannot connect it directly to the microcontroller. The relay can be connected via a field-effect or bipolar transistor, or via the same ULN2003, if several channels are needed.

The advantages of this method are high switching current (depending on the selected relay), galvanic isolation. Disadvantages: limited speed/frequency of activation and mechanical wear of parts.
It makes no sense to recommend something for use - there are many relays, choose according to the required parameters and price.

2.2 Connection loads using a triac (triac).
If you need to control a powerful AC load, and especially if you need to control the power supplied to the load (dimers), then you simply cannot do without using a triac (or triac). The triac is opened by a short current pulse through the control electrode (for both negative and positive voltage half-waves). The triac closes itself when there is no voltage on it (when the voltage passes through zero). This is where the difficulties begin. The microcontroller must control the moment the voltage crosses zero and, at a precisely defined moment, send a pulse to open the triac - this is a constant controller occupancy. Another difficulty is the lack of galvanic isolation in the triac. You have to do it on separate elements, complicating the circuit.


Although modern triacs are controlled by a fairly low current and can be connected directly (via a limiting resistor) to the microcontroller, for safety reasons they have to be switched on through optical decoupling devices. Moreover, this applies not only to the triac control circuits, but also to the zero control circuits.

A rather ambiguous way to connect the load. Since, on the one hand, it requires the active participation of a microcontroller and a relatively complex circuit design. On the other hand, it allows you to manipulate the load very flexibly. Another disadvantage of using triacs is the large amount of digital noise created during their operation - suppression circuits are needed.

Triacs are quite widely used, and in some areas they are simply irreplaceable, so getting them is not a problem. Triacs of the BT138 type are very often used in amateur radio.