To control a powerful load through Anduino or any other microcontroller, in one of the articles I used relay modules built on an electromechanical relay.
If mechanical contacts are activated very frequently, they can wear out, thereby affecting the operation of the device in which this relay is used. To get rid of this drawback, you can use a solid-state relay, which does not have mechanical contacts.
In practice, such factory relays are expensive, so we’ll try to assemble a homemade solid-state relay based on a triac, which we will control a powerful load through Arduino.
- In addition to the absence of mechanical contacts, solid-state relays have a number of other advantages: - They have smaller dimensions; - High switching speed; - Silence - since there are no moving mechanical contacts, the relay does not create audible noise; - When switching, there is no voltage surge and no radio interference;
- — The absence of a spark between the contacts allows this type of relay to be used in explosion and fire hazardous environments.
A factory-made solid-state relay is more expensive than an electromechanical one, which makes it difficult to use in amateur radio designs. For example, the Songle SRD-05VDC-SL-C electromechanical relay costs about $0.7 and can switch a load of up to 10A. The Omron G3MB-202P solid-state relay costs about $2 and can switch a load of up to 2A.
Since solid-state relays are based on semiconductor technologies, in which the load is switched using a triac or field-effect transistor, nothing prevents us from building such a homemade relay. In the example below, we will try to assemble solid-state relays based on a triac.
A triac is a semiconductor device that allows you to control a powerful load in alternating current circuits. Typically used for switching electric motors, incandescent lamps and heating elements. Another name for this device is triac or symmetrical triode thyristor. In my sign, I will use a 220V light bulb as a powerful load.
Any triac is suitable, designed for a voltage of more than 220V and the required load switching current.
I had at my disposal triacs produced by STM (STMicroelectronics): BTA12-600 , which can switch a load with a current of up to 12A and a more powerful BTA41-600B (current of up to 40A).
The first digit in the marking of triacs from this manufacturer indicates the current, and the second the switching voltage.
It is also worth noting that for some triacs the central terminal and the radiator substrate will be connected, which means there will be a high voltage on the substrate, which will also be on the cooling radiator. Such triacs are marked BTB . For triacs marked BTA, the substrate is insulated from high voltage.
Appearance of BTA12-600 and BTA41-600B, as well as general schematic designation.
Controlled terminals T1 and T2 (may also be designated as A1 and A2 ) can conduct current in both directions. In the closed state there is no conductivity between the terminals. For conductivity to occur, it is necessary to apply a control current to the control electrode G (gate).
To protect the microcontroller (in this case Arduino) from high load voltage, you need to organize galvanic isolation.
For these purposes, optosimistors are used that can withstand voltages up to 7.5 kV between the microcontroller and the load. Any optosimistor with a zero detector circuit will do.
The zero detector circuit allows the triac to open and close when the sine wave passes through zero.
The use of optosimistors with a zero detector circuit is convenient to use if you only need to turn on or turn off the load.
The following models will fit: MOC3031 - MOC3033, MOC3041 - MOC3043, MOC3061 - MOC3063 and MOC3081 - MOC3083.
If a phase regulator is needed, for example, to change the speed of an electric motor or control the brightness of a lamp, it is better to use an optosimistor without a zero detector circuit, such as MOC3020 - MOC3023.
In my examples I use the MOC3041, its appearance and pin designation.
The triac solid state relay circuit is a typical wiring diagram taken from the MOC3041 datasheet.
To limit the current flowing through the LED of the optosimistor, it is necessary to select a resistor R1, which is calculated by the formula: R1 = (Upit - Uled)/IF
Upit is the voltage that will be used to power the LED. Since I will control the circuit from a 5-volt Arduino, there will be a logic one with a voltage of 5 volts at its output. In my case, Upit = 5 volts.
Uled - voltage drop across the optosimistor LED. The drop is 1.5 V IF - LED operating current (taken from the datasheet, IFT value), for MOC3041 - 15 mAR1 = (5 - 1.5) / 0.015 = 233 Ohm.
We take the nearest denomination, rounded up, it comes out to 240 Ohms.
In order to somehow monitor the presence of a logical unit, you can add an indicator LED. In this case, you need to recalculate R1 by summing the voltage drop across both LEDs: R1 = (5 - (1.5 + 2)) / 0.015 = 100 Ohms.
If you will use an Arduino or other microcontroller with 3.3 V logic levels, recalculate the R1 value for your case.
The R4-C1 connection reduces the rate of voltage rise across the triac. Capacitor C1 at 0.01 uF should be a 400V film capacitor. Resistor R4 is 1W. Power R2, R3 from 0.5 W.
A solid-state relay based on a triac, assembled by hand. The board provided the option of installing a more powerful triac BTA41-600B and a radiator. Instead of a jumper, a fuse will be installed on the board.
The radiator was used from an old satellite receiver.
The output that is connected to the first leg of the optosimistor via R1 is connected to any digital pin of Anduino. In my example it will be 7 pins.
- We connect the output from the 2nd leg of the optosimistor (mine is connected via an indicator LED) to the GND pin of the Arduino.
- To work with this module, the same sketches that were used in the article about the electromechanical relay are suitable.
- Sketch flasher
int relayPin = 7; void setup() { pinMode(relayPin, OUTPUT);} void loop() { digitalWrite(relayPin, LOW); delay(5000); digitalWrite(relayPin, HIGH); delay(5000);} |
Connecting a tact button.
The clock button is connected with a 10k pull-up resistor. One contact of the button is connected to the 5V pin, the second to any digital pin of the Arduino, for me it is 14 pin, which can be either analog (A0) or digital.
A sketch with a tact button; when you press it, the light will light up, and when you release it, it will go out.
int relayPin = 7; void setup() { pinMode(relayPin, OUTPUT);} void loop() { if(digitalRead(14)==HIGH) { digitalWrite(relayPin, HIGH); delay(300); } else { digitalWrite(relayPin, LOW); delay(300); }} |
Tact button as a switch.
This sketch allows you to press a button to light a light bulb, and when you release the button, the light bulb will continue to light. In order to turn it off, you need to press the button again.
int relayPin = 7;int flag=0; void setup() { pinMode(relayPin, OUTPUT); } void loop() { if(digitalRead(14)==HIGH&&flag==0) { digitalWrite(relayPin,!digitalRead(relayPin)); flag=1; } if(digitalRead(14)==LOW&&flag==1) { flag=0; } } |
- The result of the sketch in the video.
- Unlike an electromechanical relay, it will not be possible to use a cheap Chinese light bulb as a load; when turned off, it will glow dimly.
A few words about varieties
Electronic timers for setting delays for turning on and off are used in microwave ovens, washing machines, heating systems, for arranging a smart home, etc. The principle of operation of a time relay is based on setting a time interval for a delay in the operation of the electrical network. In practice, such a device can have different modes of deceleration:
- electromagnetic;
Rice. 1: electromagnetic time relays
- pneumatic;
- with clock mechanism;
Rice. 2. With clock mechanism
- motor;
- electronic.
Due to the complexity of setup and the shortage of certain elements, not all time relays can be assembled with your own hands. The simplest option for manufacturing and consideration are electronic models, since today you can get components for them both from old equipment and from any radio parts store.
Electromechanical relays and other options are available if specific components are available, which are not always available for sale.
DIY solid state relay
For many power electronics circuits, a solid-state relay has become not only desirable but also necessary. Their advantage is that the number of operations is disproportionately greater compared to electromechanical ones, by an order of magnitude (and in practice even more).
Before making solid-state relays, I usually made circuits from a triac and a control circuit with galvanic isolation such as a MOC30*** simultaneous optocoupler. For example, we will use the following (basic) components:
- Triac optocoupler MOC3083 (VD1)
- Triac with insulated anode brand BT139-800 16A (V1 from Philips)
- Resistor for current limiting via LED MOC3083 (R1 750Ω 0.5W)
- LED indication AL307A (LD1)
- Resistor for the control electrode of the triac 160 Ohm (R2, 0.125W)
Fig 1
A solid-state relay is like an encapsulation of such a chain. To manufacture a solid-state relay, we will use the recommendations proposed in the collection [1].
What will be needed for production?
Depending on the chosen model, the process can be either simple or quite labor-intensive. Therefore, it is better to stock up on everything you need in advance, so as not to stop at half the work done.
To assemble a time relay you will need:
- a set of radio components - in each specific example of a homemade relay, their list will be different, but the basic nomenclature will remain unchanged (resistors, capacitors, transistors, microcircuits, intermediate relays or switches, power supplies or step-down transformers, coils, etc.);
- the basis for a set of elements - a printed circuit board, dielectric surface or frame, are also selected based on local conditions;
Rice. 3. Printed circuit board
- soldering iron, solder and other devices for connecting circuit elements.
- housing – to protect relay elements from various mechanical influences, dust, moisture and debris;
- control or programming unit - if you plan to make an adjustable delay.
In some situations, the above parts can be borrowed from old electronic devices if they suit you, otherwise you will need to purchase them. You can decide on a specific list after you choose the specific model you want to make.
Advantages of TTP
The advantages of the relay include:
- the ability to switch relatively powerful loads;
- high performance;
- work in conditions of galvanic isolation;
- ability to withstand short-term overloads.
Not a single sample of mechanical or electromechanical products is able to compete with electronic switches. Therefore, new structures based on semiconductors have completely replaced the old mechanical samples.
The unique operational characteristics of TSRs allow them to be used without any restrictions while simultaneously increasing the operating life. All of the listed advantages of these devices are an excellent reason to try to assemble a solid-state relay with your own hands. The disadvantages of these products include the need for additional power, as well as the need to remove excess heat generated when working with heavy loads.
We create a time relay for 12 and 220 Volts
Depending on the magnitude of the supply voltage to which the load is connected, the potential level under which the time relay elements will be located is also determined. In practice, to create time delays, both those operating from a 220V network and from a safe low 12V are used.
The first option is considered simpler, since the work is carried out directly from the network. Also, a 220 V circuit is relevant for powering particularly powerful loads - engines or household appliances.
Relay control via direct http (GET) requests
Device control via HTTP GET requests is performed by accessing specific files located on the device domain. All files for relay control are by default located in the protected zone “https://protect/...”, access to which requires authorization.
But by unchecking the “Secure management” field in the “Relay config” settings, the user can open access to files for managing relays located outside the secure area, for access to which authorization is not required.
Relay numbering when accessed via http GET requests starts from zero.
Example of control via the Windows command line and the wget.exe application
Fig. 10 – Controlling the RODOS-8 relay via the Windows command line and the wget.exe application
Source code of the RelayControl.exe executable file
echo off cd %~dp0 wget.exe -q -O- “https://admin: [email protected] /protect/rb0n.cgi” pause>nul
Example of control via Linux terminal
Fig. 11 – Controlling the RODOS-8 relay via the Linux curl terminal https://admin: [email protected] /protect/rb0n.cgi
Idea 1. On diodes
Let's consider a version of the simplest logical element for operation in a 220V circuit.
Rice. 4. 220V time relay circuit
Here, switching on occurs when button S1 is pressed, after which voltage is supplied to the diode bridge. From the bridge, the potential passes to a timing element consisting of resistors and a capacitor. During the process of accumulating charge, the thyristor VS1 will open and current will flow through the lighting lamp L1. When the capacitor is fully charged, the thyristor will go into the closed state, after which the relay will operate and the lamp will stop burning.
The maximum shutter speed here can be set to several tens of seconds, since its value will be set by the resistor resistance and capacitance. A significant drawback is that this scheme poses a threat to human life in case of electric shock. Therefore, next we will consider an example of manufacturing a 12V time relay.
Getting a list of connected devices
In order to receive a list of RODOS-8 devices operating on the network, you must send the character “R” (without quotes) to the network broadcast address on port 30303. In response, the device will return the “Device Name” specified in the web interface, as well as IP and MAC addresses.
An example of getting a list of connected devices on Linux
Fig. 16 – Receiving a list of connected RODOS-8 devices via UDP echo -n “R” | socat - UDP-DATAGRAM:172.16.0.255:30303,broadcast
Example of obtaining a list of devices via PowerShell Windows
Fig. 17 – Obtaining a list of connected RODOS-8 devices via UDP
PowerShell executable file “Send-UDPMessage.ps1”:
$Hostname = "172.16.0.255" $Port = 30303 $GET_IP = "R" $endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Any,$Port) $udpclient=new-Object System.Net. Sockets.UdpClient $udpclient.Client.ReceiveTimeout = 1000 $b=[Text.Encoding]::ASCII.GetBytes($GET_IP) $bytesSent=$udpclient.Send($b,$b.length,$Hostname, $Port) try { while ($true) { $content = $udpclient.Receive([ref]$endpoint) echo ([Text.Encoding]::ASCII.GetString($content)) } } catch {} $udpclient.Close()
Running a PowerShell script from the Windows command line. Executable file "UDPstart.cmd"
@echo off powershell -executionpolicy bypass -File %~dp0Send-UDPMessage.ps1 pause>nul
Getting a list of devices through the Windows terminal program
Fig. 18 – Obtaining a list of RODOS-8 devices through the Windows terminal program
Idea 2. On transistors
The operating principle of such a time relay is based on the use of semiconductor devices for the task of a time interval. In practice, circuits with either one transistor or a large number can be used. The most relevant for self-manufacturing are time relays with two transistors - they are characterized by better stability and controllability.
An example of such an electronic device is shown in the figure below:
Rice. 5. On transistors
For its practical implementation, you will need to acquire the following elements:
- resistors - one for 100 kOhm and three for 1 kOhm;
- two KT3102B transistors or identical ones;
- a capacitor to create a turn-off/on delay;
- button to start the time relay;
- intermediate relay or switch;
- LED for status signaling;
- printed circuit board for assembling all the parts.
The operating principle of such a time relay is to supply a voltage of 12 V to the capacitive element C1. After which the capacitor is charged to a certain potential, the value of which will be sufficient to open the transistor VT1.
The charge current for a capacitive element is determined by the resistance of the branch C1 - R1 - the higher the resistance, the lower the current, and the longer the charge accumulation time. Accordingly, to increase or decrease the load on or off time, you can use a variable resistor for R1.
Rice. 6. Install a variable resistor
After the capacitance is discharged, an opening signal will be sent to the base of transistor VT1, and electric current will begin to flow through the emitter and collector, resistors R2 and R3. These resistor values are selected to open the second transistor VT2, which operates in electronic switch mode to turn on the main load.
Open VT2 supplies voltage to the coil of relay K1, the core in it is attracted and performs operations with the load. One of the pairs of contacts of the electromagnetic relay acts with its contacts on the power circuit of the LED, which indicates the state of the device.
The SB1 button in the circuit allows you to reset the capacitor charge - this is a mandatory procedure before each subsequent start-up, which poses certain difficulties that can be solved by installing microcircuits.
Do-it-yourself solid state relay | Everything with your own hands
A Solid State Relay (SSR) or Solid State Relay (SSR) is an electronic device that performs the same functions as an electromechanical relay, but contains no moving parts. Commercial solid state relays use semiconductor device technologies such as thyristors and transistors.
That is, instead of moving contacts, TSRs use electronic semiconductor switches, in which the control circuits are galvanically isolated from the power switched circuits. Fortunately, now there are no problems purchasing switching field-effect transistors.
Thus, to build a solid-state relay, we need a MOSFET (Metal-Oxide-Semiconductor Field-Effect Transistor) transistor, the Russian equivalent of the term is MOS transistor or insulated gate field-effect transistor, and an optocoupler.
On the pages of the site there are articles devoted to transistor switches with optical isolation - “AC transistor switch”
This article discusses a key for switching alternating current. Using SMD components according to this scheme, it is possible to produce an alternating current SSR.
Some of the parts are mounted on a printed circuit board, which is attached to an aluminum support. Transistors are mounted on the substrate through mica spacers. It is better to take capacitor C1 either tantalum or ceramic.
Its capacity can be reduced. Another article - “Transistor switch with optical isolation”
- In this circuit, bipolar transistors of different structures are used as switching transistors.
- There is another circuit of a galvanically isolated switch on a mos-transistor with protection against the maximum load current. It was discussed in the article “Powerful DC switch on a field-effect transistor”
All this is good if the voltages with which SSRs implemented on MOSFETs operate allow these field-effect transistors to be controlled. But what about voltage switching, for example 3.3 volts. This voltage is clearly not enough to open the field effect transistor.
We need some kind of converter capable of raising the control voltage to at least five volts. Using a classic pulse converter for relays is too cumbersome. But there are other converters - optical, for example - TLP590B .
TLP590B Datasheet Pdf
Such converters provide an output voltage of about 9 volts, which is quite enough to control MOSFETs. From the documentation for these converters it is clear that they are very low-power and capable of delivering an output current of only about 12 μA. MOS transistors have this parameter - Gate charge - Qg.
Until the gate of this transistor receives the necessary charge, the transistor will not begin to open. The charging speed depends on the current that the control circuit can provide; the greater the control current, the faster the gate receives the required charge, the faster the transistor opens.
The shorter the time the switching transistor will be in the active zone of the output characteristic, the less heat will be generated on it. But in our case, when the transistor does not operate in a converter, at relatively high frequencies, but as a relay, on - off, a current of 12 μA will be sufficient.
The truth is, of course, it is better to choose key transistors with a low gate charge. For example.
Idea 3. Based on microcircuits
This is a more complex option than using transistors, but digital relays do not require a button to be pressed to start a new cycle and are more stable. The cyclic relay allows you to perform several operations in automatic mode; due to the presence of the microcircuit, there is an internal reference power source, you can significantly increase the time delay limits.
Rice. 7. Based on the KR512PS10 microcircuit
Look at the figure, the circuit shown here is designed to operate in a 220 V circuit. To implement it, you will need resistors of different values indicated in the diagram, a diode bridge, a pair of transistors, semiconductor elements, capacitors, an intermediate relay, and a microcircuit.
Its principle of operation is identical to the previously described version on two transistors, with the difference that a microcircuit appears in the time delay control circuit. With the help of which the charge of the capacitor can accumulate tens of times longer, accordingly, it is possible to increase the delay time.
The assembly process does not present any particular difficulties for experienced radio amateurs with soldering and circuit reading skills. However, for beginners, such a time relay can be somewhat difficult, so they should be careful about the process.
Alternating current
Triac as on/off
A triac is a radio element similar to a transistor, but can operate on alternating current. High voltage is a dangerous thing, so an optocoupler with a triac output is used to control the triac. The simplest connection diagram looks like this:
To control the load only in on/off mode, it is advisable to install an optocoupler with a zero detector (for example
MOC306x ), it will automatically turn off and turn on the load only when the voltage in the network passes through 0, which greatly reduces interference in the network. There are also resistors here: 220 Ohm - to limit the current to the optocoupler LED (see the characteristics of the optocoupler, I wrote above how to select a resistor). And a resistor between the optocoupler and the triac: 220-470 Ohm with a power of 1-2 W (it will heat up). The triac should be taken with a good current reserve so that it heats up less. Also, triacs come in the BTA and BTB ; the BTA case (metal part) is insulated and it is recommended to take them so as not to be shocked by current from the radiator. Pinout of components: The Chinese have ready-made modules with a triac and all the wiring. By the way, yes, the triac heats up under load! The presence of a radiator is mandatory, starting from 200 Watt.
Triac as a dimmer
To smoothly control an AC load, the task becomes much more complicated: you need to catch the moment the voltage switches, measure the time and turn off the triac, cutting off part of the sinusoid; this is called phase control.
This circuit requires an optocoupler without a zero detector, such as the MOC302x series . The diagram of such a craft might look like this:
51k resistors are necessarily powerful, since 1 Watt will be allocated to them: we extinguish the excess voltage so as not to burn out the LED of the optocoupler of the zero detector. You can also buy a ready-made module on Ali. It looks like this and has power pins, a triac control pin and a zero detector output. How to work with all this - watch the video below:
Somewhere there is a Chinese library for managing such a module, but I didn’t really like it. I give two examples for manual control of such a dimmer based on the GyverTimers library: single-channel and multi-channel. In multi-channel mode, it is enough to connect the zero detector output from only one module to the Arduino, but indicate the control pins in the sketch. The examples discussed below can be slightly optimized by replacing digitalWrite() with a fast analogue.
Source
Idea 4. Based on the NE555 timer
This option also applies to electronic relays where the time delay is set using the popular NE555 timer. With its help, you can assemble a timer that operates with switching processes, both on and off.
Rice. 8. Based on NE555 timer
As you can see in the diagram, the timer acts as a control key that allows the issuance of an electrical signal either directly to the device or through the operating element - a relay coil. When the timing chain of two resistors and a capacitor reaches saturation, the timer will output a control signal to the output of the time relay, which will attract the core to the device coil and close the contacts. An LED is connected in parallel to the output coil, signaling the state of the relay.
The practical implementation of this scheme also requires certain skills and knowledge in soldering radio components and manufacturing printed circuit boards.
It should be noted that the timer and microcircuit, although they provide more stable operation, cannot boast of programming ability. Modern cyclic timers on microcontrollers provide unlimited functions in forming the logic of operation, but assembling them at home is quite difficult.
Device management via UDP
Relay control
RODOS-8 supports control of the built-in relay via the UDP protocol. Command structure for controlling a relay (square brackets are not placed in the command):
[login] | [space] | [password] | [space] | k[N]=[action] |
Legend:
- [login] – login from the protected zone, set in the network settings section of the Web interface;
- [password] – password for the protected zone, set in the network settings section of the Web interface;
- [space] – space;
- [N] – number of the relay on which the operation is performed; numbering starts from “1”;
- [action] – action that is performed on the relay: 0 – turn off the relay (closing the normally closed and common contacts (NC and COM);
- 1 – turn on the relay (closing the normally open and common contacts (NO and COM);
- 2 – send a pulse of a given duration to the relay.
Example commands:
admin admin k1=0 | Turn off the built-in relay. Login and password for the protected zone “admin” |
admin admin k2=1 | Turn on the relay. Login and password for the protected zone “admin” |
Example of relay control from the Linux console
Fig. 13 – Controlling the RODOS-8 relay via UDP via commands from the Linux console echo -n “admin admin k1=1” > /dev/udp/172.16.0.150/8283
An example of controlling a relay from the Windows command line via PowerShell
Fig. 14 – Controlling the RODOS-8 relay via UDP via commands from the Windows command line
Example of PowerShell code (turn on the relay, then turn it off after 500 ms; device IP address 172.16.0.150, port 8283). The script text is saved in a separate file with the extension “.ps1”.
File "Send-UDPMessage.ps1":
[String]$Hostname = "172.16.0.150" [Int]$Port = 8283 [String]$Relay_1_ON = "admin admin k1=1" [String]$Relay_1_OFF = "admin admin k1=0" $udpclient=new-Object System.Net.Sockets.UdpClient $b=[Text.Encoding]::ASCII.GetBytes($Relay_1_ON) $bytesSent=$udpclient.Send($b,$b.length,$Hostname, $Port) Start-Sleep - Milliseconds 500 $b=[Text.Encoding]::ASCII.GetBytes($Relay_1_OFF) $bytesSent=$udpclient.Send($b,$b.length,$Hostname, $Port) $udpclient.Close()
Run the generated PowerShell script from the command line
@echo off powershell -executionpolicy bypass -File %~dp0Send-UDPMessage.ps1 pause>nul
Relay control via Hercules SETUP terminal program
Fig. 15 – Control of the RODOS-8 relay via UDP via the Hercules SETUP terminal program