Installation of alarm systems on your own. Using RF Modules

March 17, 2012 at 6:30 pm

Using RF Modules

  • Electronics for Beginners

Sometimes, between devices you need to install wireless connection. IN Lately For this purpose, Bluetooth and Wi-Fi modules. But it’s one thing to transfer videos and hefty files, and another thing to control a machine or robot with 10 commands. On the other hand, radio amateurs often build, adjust and remake receivers and transmitters to work with ready-made command encoders/decoders. In both cases, you can use fairly cheap RF modules. Features of their work and use under the cut.

Module types

RF modules for data transmission operate in the VHF range and use standard frequencies 433MHz, 868MHz or 2.4GHz (less commonly 315MHz, 450MHz, 490MHz, 915MHz, etc.) The higher the carrier frequency, the higher the speed information can be transmitted.
As a rule, manufactured RF modules are designed to work with some data transmission protocol. Most often this is UART (RS-232) or SPI. Typically, UART modules are cheaper and also allow the use of non-standard (custom) transmission protocols. At first I thought of riveting something like this, but remembering my bitter experience in making radio control equipment, I chose the fairly cheap HM-T868 and HM-R868 (60 UAH = less than $8 a set). There are also models HM-*315 and HM-*433, which differ from those described below only in the carrier frequency (315 MHz and 433 MHz, respectively). In addition, there are many other modules similar in the way they work, so the information may be useful to owners of other modules.

Transmitter

Almost all RF modules are a small printed circuit board with contacts for connecting power, transmitting data and control signals. Consider the transmitter HM-T868
It has a three-pin connector: GND (common), DATA (data), VCC (+ power), as well as a patch for soldering the antenna (I used a stub of MGTF wire 8.5 cm - 1/4 wavelength).

Receiver

The HM-R868 receiver, in appearance, is very similar to its corresponding transmitter

but there is a fourth contact on its connector - ENABLE; when power is applied to it, the receiver starts working.

Job

Judging by the documentation, the operating voltage is 2.5-5V, the higher the voltage, the greater the operating range. In essence, it is a radio extender: when voltage is applied to the DATA input of the transmitter, voltage will also appear at the DATA output of the receiver (provided that voltage is also applied to ENABLE). BUT, there are several nuances. Firstly: the data transmission frequency (in our case it is 600-4800 bps). Secondly: if there is no signal at the DATA input for more than 70ms, then the transmitter goes into sleep mode (essentially turns off). Thirdly: if there is no working transmitter in the receiving area of ​​the receiver, all sorts of noise appears at its output.

Let's conduct a small experiment: connect power to the GND and VCC contacts of the transmitter. The DATA pin is connected to VCC via a button or jumper. We also connect power to the GND and VCC contacts of the receiver, and connect ENABLE and VCC to each other. We connect an LED to the DATA output (preferably through a resistor). As antennas we use any suitable wire 1/4 wavelength long. You should get a diagram like this:


Immediately after turning on the receiver and/or applying voltage to ENABLE, the LED should light up and burn continuously (or almost continuously). After pressing the button on the transmitter, nothing happens to the LED - it continues to light. When you release the button, the LED will blink (goes off and lights up again) and continues to light. When you press and release the button again, everything should repeat. What was happening there? When the receiver was turned on, the transmitter was in a sleeping state, the receiver did not find a normal signal and began to receive all sorts of noise, and accordingly, all kinds of noise appeared at the output. It is impossible to distinguish a continuous signal from noise by eye, and it seems that the LED is shining continuously. After pressing the button, the transmitter comes out of hibernation and starts transmitting, a logical “1” appears at the receiver output and the LED shines truly continuously. After releasing the button, the transmitter transmits a logical “0”, which is received by the receiver and “0” also appears at its output - the LED finally goes out. But after 70ms, the transmitter sees that there is still the same “0” at its input and goes to sleep, the carrier frequency generator turns off and the receiver begins to receive all sorts of noise, noise at the output - the LED lights up again.

From the above it follows that if the signal at the transmitter input is absent for less than 70 ms and is in the correct frequency range, then the modules will behave like a regular wire (we do not pay attention to interference and other signals for now).

Package format

RF modules of this type can be connected directly to a hardware UART or computer via MAX232, but given the peculiarities of their operation, I would advise using special protocols described in software. For my purposes, I use packets of the following type: start bits, bytes with information, a control byte (or several) and a stop bit. It is advisable to make the first start bit longer, this will give time for the transmitter to wake up, the receiver to tune in to it, and the receiving microcontroller (or whatever you have) to start receiving. Then something like “01010”, if this is the output of the receiver, then it is most likely not noise. Then you can put an identification byte - it will help you understand which device the packet is addressed to and is even more likely to reject noise. Until this moment, it is advisable to read and check the information in separate bits; if at least one of them is incorrect, we complete the reception and start listening to the broadcast again. Further transmitted information can be read at once byte by byte, writing to the appropriate registers/variables. At the end of the reception, we execute the control expression; if its result is equal to the control byte, we perform the required actions with the received information, otherwise we listen to the broadcast again. As control expression can be considered any checksum, If transmitted information a little, or you are not strong in programming - you can just calculate some arithmetic expression, in which the variables will be the transmitted bytes. But it is necessary to take into account that the result must be an integer and it must fit into the number of control bytes. Therefore it is better instead arithmetic operations use bitwise logic: AND, OR, NOT and, especially, XOR. If possible, it is necessary to make a control byte, since radio broadcasting is a very polluted thing, especially now, in the world of electronic devices. Sometimes, the device itself can cause interference. For example, I had a track on the board with 46 kHz PWM 10 cm from the receiver that greatly interfered with reception. And this is not to mention the fact that RF modules use standard frequencies, at which other devices can operate at this moment: walkie-talkies, alarms, radio control, telemetry, etc.

Modules are designed for wireless transmission data over long (up to 1 km) distances under direct visibility conditions. Maximum speed flow when modulated by master oscillator data is about 3 kbit/sec.
If higher transmission rates are required, a buffer stage before the power amplifier should be modulated with data. The receiving part after the detector should be changed slightly, as .
(resistor in the low-pass filter 10 k - short-circuit, remove the capacitance at the input of the comparator 1000p and reduce the “slowing down” capacitance of 1 microfarad to 0.01 microfarad). Then " throughput"Receiver/transmitter pairs will increase significantly (up to 100 - 150 kbit/s). A piezoceramic filter (10.7 MHz), in the case of high-speed exchange, should be used with a bandwidth of at least 300 kHz.
Below is a diagram of the receiving part.

The receiver is a superheterodyne with single frequency conversion (IF - 10.7 MHz).
Intermediate frequency is the difference between the transmitter frequency and the receiver local oscillator frequency. The transmitter emits at a frequency of 418 MHz. Receiver local oscillator frequency is 407.3 MHz (SAW resonators in the receiver and transmitter can be swapped).
The HF part is without any special features - all its components are standard.
It has been tested many times various devices and has proven itself well.
The RF signal, having passed the necessary stages of conversion and amplification, is detected and its envelope, passing through the low-pass filter, is fed to the input of the comparator, connected according to a “floating threshold” circuit, which ensures its maximum sensitivity.
The receiver has a sensitivity of 1 - 2 µV, which is not inferior to industrial microassemblies. The circuit is optimized for a supply voltage of 2.5 - 3 volts.
The current consumed by the receiver is about 15 mA.
At the output of the comparator, the data is displayed in inverse form (oscillogram below).

Data transmitter.

The transmitter is a circuit without any special features. It is also optimized for a supply voltage of 2.5 - 3 volts.
Power at a supply voltage of 3 volts, 50 - 70 milliwatts. Current consumption is about 60 mA. The power can be increased by turning on the transmitter from 5 volts, it can reach 120 - 150 milliwatts. The current will rise to 120 mA, which can be dangerous for the final stage. Transistor in the final stage, with increased voltage power supply, it is more advisable to use 2SC3357 without any changes in the circuit.

Today, gadgets that work with a microcontroller using radio frequency circuits (modules) are becoming increasingly popular. In the article we will try to figure out how it is still possible to work with two modules - the XY-MK-5V receiver and the XY-FST (FS1000A) transmitter (this is the marking on the module boards). Externally, such modules look like this:

These modules operate at a frequency of 433 MHz, but as can be seen from the photo, configurations of the same modules operating at frequencies of 315 MHz and 330 MHz are possible. And as far as I know, the number of frequency configurations is not limited to these three. It is important to note that both modules must be set to the same frequency, otherwise they will not work with each other. You never know who gets it into their head. :)

These modules represent a simple circuit design super-regenerative receivers of a given frequency, designed to receive (transmit) a digital signal. Everything works extremely simply. The transmitter has three pins - two for power and one for data. The receiver also has two power pins and two pins for receiving data from the microcontroller, these two data pins are actually one pin, just soldered in parallel to each other. Thus, if a logical one is applied to the transmitter data output, a logical one will also appear at the receiver data output. Roughly speaking, such modules are radio frequency extensions of one microcontroller pin, replacing a wire. Everything is simple and cheerful, besides, the cost of a set of receiver and transmitter is extremely small and amounts to approximately 1 conventional unit depending on the seller’s thirst for profit.

I would also like to note a few features of such modules regarding the above. If we take two modules, connect them to power, connect an LED to the receiver data output, and connect either the plus or minus power to the transmitter data output. As expected, the LED will either be on or off depending on where the transmitter data output is connected. But that was not the case! In both cases, we will simply have chaos at the receiver data output, and the most observant may notice during the initial period of connecting the transmitter data output to the positive that the LED briefly flashes brightly and again begins to chaotically change brightness. The thing is that there is a lot of interference on the radio, especially in urban environments. Now you may ask, why do we need such an “awil”? Don't panic! Remember, at the initial moment, the LED still worked for a split second as expected at the very beginning - on, off? So we take it and simply increase the pulse frequency at the transmitter data output. You can connect a generator there and use an oscilloscope to monitor the state of the receiver data output. We adjust the generator to the frequency rectangular pulses from 10 Hz to 10 kHz. And on the oscilloscope screen the miracle we expect happens - a rectangle similar to the one on the generator, maybe only slightly distorted.

Looking ahead a little, the oscillogram from the receiver transmits the value in binary 1110-1110:

And if the transmitter is at rest, no data is transmitted, the oscillogram from the receiver will simply have a chaotic set of pulses:

The data will still not be transmitted constantly, the transmitter data output will not always receive signals from the microcontroller, so protection against such a chaotic signal (noise) will be necessary.

So, let's look at the parameters of the receiver and transmitter modules:

Receiver:

  • supply voltage 5 V
  • current consumption 4 mA
  • frequency 433.92 MHz
  • sensitivity -105dB
  • antenna - 32 cm single-core wire

Transmitter:

  • transmission distance from 20 to 200 meters depending on supply voltage and conditions environment
  • supply voltage from 3.5 to 12 V
  • transmission speed up to 4 kb/s
  • transmitter power 10 mW
  • frequency 433 MHz
  • antenna length 25 cm

Thus, we have examined the radio frequency modules themselves, their operation and parameters, all that remains is to connect them to the microcontroller and transmit data, which is what we will do next.

Let's draw a basic electrical diagram:

The diagram demonstrates communication between two microcontrollers via a radio channel using the XY-MK-5V and XY-FST (FS1000A) modules. Firmware and source for both microcontrollers are attached below.

The operating logic is as follows - the Attiny13 microcontroller dynamically changes the variable and constantly transmits its value via radio channel to the Atmega8 microcontroller. In the second microcontroller, data is received and the value of the variable is displayed on the LCD display. To be fair, it is worth noting that sometimes interference still creeps into useful data. It was stated above that noise needs to be filtered somehow. The filtering is organized in such a way that in order to receive useful data, the first byte of the transmission must be an address byte. As soon as the value of the first byte matches the one stored, the second byte can be safely accepted as useful data. Data is transmitted several times in a row to prevent data loss. Everything is quite simple. To increase noise immunity, the length of the address information can be increased to two or three bytes.

The signal for the transmitter is generated depending on the number that needs to be transmitted. A number in binary is a sequence of zeros and ones. Thus, depending on the state of each bit in the byte, a zero or a one is sent to the transmitter - this is how a rectangular (digital) signal is formed. The receiver receives this signal and also, depending on the state (zero or one), 8 bits of the byte are formed and we receive the transmitted number and then do with it (with the received information) whatever we need.

A liquid crystal display (LCD) is used for display. I used the 2004A display - 4 lines of 20 characters, but you can use a more familiar display - 2 lines of 16 characters. The LCD display is connected to the microcontroller in four bit system. Variable resistor R2 is needed to adjust the contrast of characters on the display. By rotating the slider of this resistor we achieve the clearest readings on the screen for us. The backlight of the LCD display is organized through pins “A” and “K” on the display board. The backlight is turned on through a current-limiting resistor - R1. The higher the value, the dimmer the display will be backlit. However, this resistor should not be neglected to avoid damage to the backlight. Buttons S1 and S2 are needed to reset the microcontrollers. Resistors are connected to the reset pins of both microcontrollers, pulling the plus power supply to the pin. This is necessary to prevent the microcontrollers from spontaneously restarting in the event of interference or noise.

The entire circuit is powered by simple module power supply on the power transformer. AC voltage rectified by four 1N4007 diodes VD1 - VD4, ripples are smoothed out by capacitors C1 and C2. Four rectifier diodes can be replaced with one diode bridge. The transformer used is brand BV EI 382 1189 - converts 220 volts alternating current at 9 volts AC. The power of the transformer is 4.5 W, which is quite enough and with some reserve. Such a transformer can be replaced with any other power transformer, suitable for you. Or replace this power module of the circuit with pulse source voltage, you can assemble a flyback converter circuit or use something similar ready block power supply from a telephone, for example, is all a matter of tastes and needs. The rectified voltage from the transformer is stabilized on the L7805 linear stabilizer chip; it can be replaced with a domestic analogue of the five-volt linear stabilizer KR142EN5A, or you can use another voltage stabilizer chip in accordance with its connection in the circuit (for example, LM317 or switching stabilizers LM2576, LM2596, MC34063, and so on ).

If the circuit is planned to be used for more than just an introduction to RF modules, then the second microcontroller will need a separate power supply.

The entire circuit was assembled and debugged on development boards for microcontrollers Atmega8 and Attiny13:

As you can see, the modules were used without antennas, of course on a short distance communication will be carried out, but the quality of communication will be worse. You shouldn’t follow my example in this regard - don’t be lazy, make antennas for the modules and solder them. The manufacturer specifies antenna lengths of 32 and 25 centimeters for the receiver and transmitter, respectively. However, the note says that it is important to use an antenna 17 cm long. Here I am a little confused about how long the antenna should be. The manufacturer also notes that the location of the antenna also affects the quality of signal reception. Here, the best location can be selected using a scientific method - in which position the signal is better, then place the antenna there. IN Chinese devices using similar modules, it is made in the form of a spiral and simply placed along the receiver.

A few words about the application - using such circuits, you can transmit and receive information about temperature or something else at points remote from the main microcontroller. Also, using the accepted code, you can manage any non- complex circuits remotely (type on/off). Well, in general, use it wherever you want.

For programming you need to know the fuse bit configurations of microcontrollers for Atmega8:

The article includes firmware for microcontrollers, sources in , as well as a video demonstrating the operation of the circuit and the transfer of information from microcontroller to microcontroller (tiny13 counts from 0 to 255 and constantly transmits the value to another microcontroller, on which this value is displayed on LCD screen display, on video the value will be transmitted up to 111 and at this moment we disconnect the data line from the transmitter module, the number will remain in the last transmitted state - 111).

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
IC1 MK AVR 8-bit

ATmega8

1 To notepad
IC2 MK AVR 8-bit

ATtiny13A

1 To notepad
VR1 Linear regulator

L7805AB

1 To notepad
VD1-VD4 Rectifier diode

1N4007

4 To notepad
RF1 RF receiverXY-MK-5V1 To notepad
RF2 RF transmitterFS1000A1 XY-FST To notepad
C1, C9 10 µF2 To notepad
C2, C4-C7, C10 Capacitor100 nF6 To notepad
C3 Electrolytic capacitor1000 µF1 To notepad
C8 Electrolytic capacitor220 µF1 To notepad
R1 Resistor

DIY RF modules

Sometimes a situation arises when SAW resonators are available for those frequencies for which the industry does not produce receiving modules. And it’s no secret that the cost of industrial microassemblies is about 7 euros (RX 5000) can discourage anyone from experimenting. Modern element base allows you to assemble both a transmitter and a receiver yourself with characteristics that are at least no worse than those of industrial modules.

Data transmitter.

A standard circuit tested by many radio amateurs. Consists of a controlled master oscillator and power amplifier. Power is about 10 mW, current consumption is 15 mA. The master oscillator current is about 2 mA. The current consumption and power of the final stage can be adjusted using bias resistors. It should be remembered that a final stage current of more than 50 mA can damage the transistor used in this design.

Data receiver.

The receiver is a super-regenerator with a sensitivity of about 1 µV. Remains operational from 3 to 6 volts without “going anywhere” in frequency. The connection between the superregenerator and the antenna is inductive, which avoids the harmful effects of interference and strong signals for the operation of the super-regenerative cascade.

The receiver is tuned by moving and moving apart the coil turns in the collector circuit. The use of capacitors parallel to the collector coil is undesirable as this degrades the quality factor of the circuit. At a frequency of 423.2 MHz, the circuit has 9 turns.

In numerous tests, it turned out that the use of UHF in conjunction with a correctly configured receiver of this type does not provide anything in terms of improving sensitivity, but only worsens the dynamics of the super-regenerator, allowing for some carelessness in its settings. The AM signal received by the receiver has a very small amplitude, so it is first amplified and then fed to the input of a comparator (threshold device). Log 1 appears at the output of the comparator if the voltage level at its input exceeds a certain level.

When setting up the receiver, it is convenient to control the signal emitted by the transmitter in analog form after the first amplifier (pin 1 of the LM 358) by connecting the input of a conventional ULF there.