Reading 433 MHz Arduino Remote Code

Hi all! I have a car park at work. Of course, the purpose of this article is not to brag, given the difficult situation on the roads with parking spaces, and not to PR for my management that they care about their employees (I won’t even mention my place of work!), that’s not the point. The point is, what is stopping anyone else who is not related to my place of work from parking in this parking lot? And this is a barrier that restricts entry and exit from this parking lot.

And like in many organizations, entry to my enterprise is carried out using ordinary passes in order to control me and everyone else. Well, they also made entrance to the parking lot using the same passes. That is, you drive up to the parking lot, present your pass to the reader, it works, the barrier opens (closes automatically), you drive in and that’s it. That's what they thought. But my passion for electronics and natural laziness (this means every time I drive up, open the window, pull out my hand, close the window, and if it’s raining, and if it’s cold) went against the system.

So, let's get to the point. First of all, I found out that the barrier turned out to be quite popular company Nice and started looking for information about him. However, despite the popularity of the manufacturer, there was very little information about its code formats. It turned out that there are 12-bit and 24-bit code formats. 12-bit is more ancient, 24-bit is more modern. Since I know that the barrier at work has been standing for a long time, I decided to start with 12-bit codes (later I got it right). And so the data packet consists of 12 bits. Before the 12-bit code there is a so-called “pilot period” and “starting impulse”. The “pilot period” consists of 36 low-level intervals, the “starting impulse” consists of 1 high-level interval. One data packet consists of a “pilot period”, followed by a “starting impulse” and followed by a 12-bit code (different for each barrier). The barrier remotes transmit 4 data packets at once, but I installed more, since many devices operate on this frequency (in particular, car alarms) and interference is possible. Pulse durations for Nice barriers:

  • Logical “1” – 1400 µs low (two intervals) and 700 µs high (one interval)
  • Logic "0" is 700 µs low (one interval) and 1400 µs high (one interval)
  • “Pilot period” – 25200 μs (36 intervals)
  • “Start pulse” – 700 µs (1 interval)
Since neither I nor anyone else has remote controls for this barrier (in such a case it would be possible to simply read the signal from the existing remote control), then you will have to guess the true code by searching through all possible options, and 4096.

How, in general, can all this be realized? My recent passion for Arduino platforms did not allow me to think about this issue for long.

List of components:

1. Arduino Uno,

2. Radio transmitter 433 MHz, homemade antenna to him,

3. The battery is 9 volts, popularly “Krona”.

These radio transmitters in known Chinese stores They are sold very cheaply (about 50 rubles), together with radio receivers. They are very simple, three pins: power, ground and signal pin. Power supply from 5 to 12 volts, the higher the supply voltage, the better the range. This is actually why a 9 volt battery was chosen. The recommended supply voltage for Arduino Uno is from 7 to 12 volts (Vin pin), so the “Krona” is quite suitable. Also, the range of the radio transmitter depends on the presence of an antenna (without it, the range will be about 1 meter). The whole set cost about 300 rubles.

Here, in fact, is the sketch for Arduino Uno:

Int send_code_pin = 13; //int send_code = 3061; this is the code determined by brute force for my barrier void setup() ( pinMode(send_code_pin, OUTPUT); ) void loop () ( for (int send_code = 0; send_code< 4096; send_code++) // этот цикл после того как код определен необходимо убрать { for (int j = 0; j <7; j++) // достаточно 4-х, но из-за помех поставил 7 { digitalWrite(send_code_pin, HIGH); // стартовый импульс delayMicroseconds(700); digitalWrite(send_code_pin, LOW); for (int i = 12; i >0; i--) ( boolean bit_code = bitRead(send_code, i - 1); if (bit_code) ( digitalWrite(send_code_pin, LOW); // unit delayMicroseconds(1400); digitalWrite(send_code_pin, HIGH); delayMicroseconds(700); ) else ( digitalWrite(send_code_pin, LOW); // zero delayMicroseconds(700); digitalWrite(send_code_pin, HIGH); delayMicroseconds(1400); ) ) digitalWrite(send_code_pin, LOW); // pilot period delayMicroseconds(25200); ) ) //delay(10000); after defining the code, set a delay)
Going through all possible options took about 1 week, taking into account one exit per day to the barrier. Methodology quick selection correct code was very simple. Using the command micros() determined the transmission time of one code. It was approximately 0.25 seconds. The total time to go through all the options is about 17 minutes. In front of the barrier, I launched the Arduino and noted the time. At about 12.5 minutes the barrier opened. Based on this, I immediately discarded the first 2800 options. And so on. When there were about 30 options left, after each data transfer I set a delay of 1 second. Since I installed the data transfer contact as 13th (with an LED), every moment of transmission was visible, I counted and determined the exact code.

That's all! As a demo - video of the autopsy.

The XD-RF-5V receiver and FS1000A/XD-FST 433 MHz radio frequency transmitter are used to transmit data between two devices. Very often used to connect several Arduino devices.

Characteristics of XD-RF-5V

Operating voltage: 3V~12V
Working current: 20mA~28mA
Backup current: 0mA
Operating frequency: 433MHz
Transmitter distance: >500m (sensitivity can be higher -103dBm if in wide field)
Output power: 16dBm (40mW)
Transmitter Speed: Modulation Mode: OOC (AM)

Size: 19 x 19 x 8 mm

For connection it has pins PIN1 DATA, PIN2 VCC, PIN3 GND. There is no built-in antenna, but there is a contact for connecting it. Often, wire antennas are made to increase the transmission range. The transmitter is used in devices smart home, automatic systems data collection. The main advantage is unpretentiousness, stable operation and low energy consumption. One of the minuses worth noting is its “analogue” nature. It is necessary to complicate the program code to encode the data stream, but this is also an advantage because There are no restrictions on the communication protocol.

Radio receiver FS1000A/XD-FST 433Mhz

Operating voltage: DC 5V
Working current: 4mA
Modulation mode: OOC (AM)
Operating temperature: -10°C~+70°C
Receiving sensitivity: -110dB
Operating frequency: 433MHz
Size: 30 x 14 x 7 mm

The receiver operates on the basis of an oscillating circuit with an amplifier. Connected using pins PIN1 VCC, PIN2/3 DATA, PIN5 GND. The output of the radio module is logical in level, but the signal receives an analog one. Therefore, the task of decoding the message falls on the shoulders of the device (usually Arduino) that receives the signal.


The connection diagram for 433 Mgz radio modules to Arduino is presented below. Outputs The receiver and transmitter outputs are connected to Digital Arduino ports, which are capable of processing a modulated signal.


To significantly increase the reception range, you can solder an antenna to the transmitting and receiving devices. The simplest option is a piece of wire 17 cm long with a resistance of 50 Ohms. This length will cut at a frequency of 433 Mgz because its length is equal to 1/4 wave.

To encode and decode the transmitted signal on Arduino, it is convenient to use the VirtualWire.h library
Let me give you a couple of examples of using the library to transfer digital data.

Transmitter:

#include "VirtualWire.h" const int led_pin = 13; // LED pin const int transmit_pin = 12; // Transmitter connection pin void setup() ( vw_set_tx_pin(transmit_pin); vw_setup(2000); // Transfer rate (Bits per second) pinMode(led_pin, OUTPUT); ) void loop() ( const char *msg = "Hello, Arduinomania"; // Transmitted message digitalWrite(led_pin, HIGH); // Light the LED at the beginning of the transmission vw_send((uint8_t *)msg, strlen(msg)); // Sending the message vw_wait_tx(); // Wait for the digitalWrite message to finish sending (led_pin, LOW); // Turn off the LED at the end of the transmission delay(1000); // Pause 1 second)

Receiver:

#include "VirtualWire.h" byte message; // Buffer for storing received data byte messageLength = VW_MAX_MESSAGE_LEN; // Message size const int led_pin = 13; // LED pin const int receiver_pin = 11; // Receiver connection pin void setup() ( Serial.begin(9600); // Data transfer speed Serial.println("Read 433mHz begin"); vw_set_rx_pin(receiver_pin); // Receiver connection pin vw_setup(2000); // Speed data transfer (bits per second) vw_rx_start(); // Activate the application ) void loop() ( if (vw_get_message(message, &messageLength)) // If there is data.. ( digitalWrite(led_pin, HIGH); // Light the LED in beginning of packet reception for (int i = 0; i< messageLength; i++) { Serial.write(message[i]); // выводим их в одной строке } Serial.println(); digitalWrite(led_pin, LOW); // Гасим светодиод в конце } }

Sooner or later, the projects being created will need remote control. One of the most budget-friendly solutions is to use a radio receiver and radio transmitter. The simplest example You will find their use in this article, and then everything depends only on your needs and imagination.

First of all we take 2 Arduino boards and connect the receiver and transmitter to them, as shown in the figure:

Components for repetition (buy in China):

Before starting work, you need to indicate that for full-fledged work, an antenna must be soldered to the modules. The recommended antenna length for 433 MHz transmitters is 17 cm.

Library required to work with the VirtualWire module

It must be unpacked and added to the "libraries" folder in the folder with Arduino IDE. Don't forget to reboot the environment if the IDE was open when you added it.

Example program code

#include void setup(void) ( vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(2000); // Set the transfer rate (bit/s)) void loop(void ) ( int number = 123; char symbol = "c" ; String strMsg = "z " ; strMsg += symbol; strMsg += " " ; strMsg += number; strMsg += " " ; char msg; strMsg. toCharArray(msg, 255); Serial.println(msg); vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); // Wait until the transfer is completed delay(200); )

Let's analyze this code for complete understanding.

First, we create the string strMsg. We use the String type because... it's easier to work with (you can concatenate it with numbers using the "+" operator).

Since all transmitters operate in the same frequency range, each receiver will receive information from each transmitter within range. In order to filter out unnecessary characters, in the simplest case you can simply precede commands with some special character. In our case, this is the symbol "z".

After that, we convert the String type to a standard character array using the toCharArray method and pass it to the vw_send command.

Our code will send the string "z c 123".

Let's move on to the receiver code:

Sample code

// Tested on Arduino IDE 1.0.1#include void setup () { Serial.begin(9600); vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(2000); // Set the reception speed vw_rx_start(); // Start broadcast monitoring) void loop() (uint8_t buf; // Buffer for message uint8_t buflen = VW_MAX_MESSAGE_LEN; // Buffer length if (vw_get_message(buf, &buflen)) // If the message is received { // Start parsing int i; // If the message is not addressed to us, exit if (buf != "z" ) ( return ; ) char command = buf; // The command is at index 2 // Numeric parameter starts at index 4 i = 4; int number = 0; // Since the transmission is character-by-character, we need to convert the set of characters into a number while (buf[i] != " " ) ( number *= 10; number += buf[i] - "0" ; i++; ) Serial.print(command); Serial.print(" "); Serial.println(number); ) )

The message will be read into the buf buffer, which needs to be parsed.

First of all, we check for the presence of the service character "z", then we read the command code and then convert the string representation of the parameter into a number.

The information has been received and analyzed; what to do next depends on the specific task.

This article discusses the simplest version of communication. Ideally, you should think about coding transmitted information, because Not only your receivers will receive it.

P.S. While working with these modules, we came across one unpleasant pitfall, namely a conflict, the inability to work with the "servo.h" library.

In this lesson we will solve the problem of transmitting a radio signal between two Arduino controllers using a popular 433 MHz transceiver. In fact, a data transmission device consists of two modules: a receiver and a transmitter. Data can only be transferred in one direction. This is important to understand when using these modules. For example, you can do remote control any electronic device, be it a mobile robot or, for example, a TV. In this case, data will be transferred from the control panel to the device. Another option is to transmit signals from wireless sensors to a data acquisition system. Here the route changes, now the transmitter is on the sensor side, and the receiver is on the collection system side. The modules may have different names: MX-05V, XD-RF-5V, XY-FST, XY-MK-5V, etc., but they all have approximately the same appearance and numbering of contacts. Also, two frequencies of radio modules are common: 433 MHz and 315 MHz.

1. Connection

The transmitter has only three pins: Gnd, Vcc and Data.
We connect them to the first Arduino board according to the following diagram: We assemble both devices on a breadboard and start writing programs.

2. Program for the transmitter

To work with radio modules, we will use the RCSwitch library. Let's write a program that will send two different messages every second in turn. #include RCSwitch mySwitch = RCSwitch(); void setup() ( mySwitch.enableTransmit(2); ) void loop() ( mySwitch.send(B0100, 4); delay(1000); mySwitch.send(B1000, 4); delay(1000); ) Let's analyze the program. The first thing we did was declare an object for working with the transmitter and called it mySwitch. RCSwitch mySwitch = RCSwitch(); Then, inside the standard function setup turned on the transmitter and specified the pin to which it is connected: mySwitch.enableTransmit(2); Finally, in the main loop of the program loop, we send first one message, and then the second using the function send : mySwitch.send(B1000, 4); Function send has two arguments. The first is a sent message, which will be sent over the air in the form of a burst of impulses. The second argument is the size of the packet to be sent. In our program we specified messages in the format binary number. This is indicated by the English letter “B” at the beginning of the B1000 code. In decimal notation this number becomes an eight. So we could call the function send like this: mySwitch.send(8, 4); Send can also accept binary strings: mySwitch.send("1000", 4);

3. Program for the receiver

Now let's write a program for the receiver. To demonstrate the fact of transmission, we will light the LED connected to pin No. 3 on the Arduino board. If the receiver has caught the code B1000, turn on the LED, and if B0100, turn it off. #include RCSwitch mySwitch = RCSwitch(); void setup() ( pinMode(3, OUTPUT); mySwitch.enableReceive(0); ) void loop() ( if(mySwitch.available())( int value = mySwitch.getReceivedValue(); if(value == B1000) digitalWrite(3, HIGH); else if(value == B0100) digitalWrite(3, LOW); mySwitch.resetAvailable(); ) ) Function available returns true if the transmitter has received at least some data: mySwitch.available() Function getReceivedValue extracts one packet from the data stream and decodes it into a number. In the program we assign the resulting number to a variable value : int value = mySwitch.getReceivedValue();

Tasks

Now you can try to practice and make various useful devices. Here are some ideas.
  1. Remote control for the lamp. On the receiver side, connected to the power supply circuit of the lamp (careful, 220 Volts!). On the transmitter side: . Write programs for the receiver and transmitter that, at the press of a button, will turn on a remote relay. When you press the button again, the relay will turn off.
  2. Outdoor thermometer with radio channel. Place on the transmitter side. Provide autonomous power supply from batteries. On the receiver side: . Write programs for the receiver and transmitter that will allow you to display temperature readings from a remote sensor on the display.

Conclusion

So now we know a simple and inexpensive way to transmit data over a distance. Unfortunately, the transmission speed and distance in such radio modules are very limited, so we will not be able to fully control, for example, a quadcopter. However, making the radio remote control simple household appliance: lamp, fan or TV, we can do it. Most radio channel control panels operate based on transceivers with a frequency of 433 MHz and 315 MHz. Given an Arduino and a receiver, we can decode the control signals and repeat them. We will write more about how to do this in one of the following lessons! October 5, 2016 at 6:41 pm

Barrier control using Arduino UNO and 433 MHz radio transmitter

  • Microcontroller programming

Hi all! I have a car park at work. Of course, the purpose of this article is not to brag, given the difficult situation on the roads with parking spaces, and not to PR for my management that they care about their employees (I won’t even mention my place of work!), that’s not the point. The point is, what is stopping anyone else who is not related to my place of work from parking in this parking lot? And this is a barrier that restricts entry and exit from this parking lot.

And like in many organizations, entry to my enterprise is carried out using ordinary passes in order to control me and everyone else. Well, they also made entrance to the parking lot using the same passes. That is, you drive up to the parking lot, present your pass to the reader, it works, the barrier opens (closes automatically), you drive in and that’s it. That's what they thought. But my passion for electronics and natural laziness (this means every time I drive up, open the window, pull out my hand, close the window, and if it’s raining, and if it’s cold) went against the system.

So, let's get to the point. First of all, I found out that the barrier turned out to be a fairly popular Nice company and began looking for information about it. However, despite the popularity of the manufacturer, there was very little information about its code formats. It turned out that there are 12-bit and 24-bit code formats. 12-bit is more ancient, 24-bit is more modern. Since I know that the barrier at work has been standing for a long time, I decided to start with 12-bit codes (later I got it right). And so the data packet consists of 12 bits. Before the 12-bit code there is a so-called “pilot period” and “starting impulse”. The “pilot period” consists of 36 low-level intervals, the “starting impulse” consists of 1 high-level interval. One data packet consists of a “pilot period”, followed by a “starting impulse” and followed by a 12-bit code (different for each barrier). The barrier remotes transmit 4 data packets at once, but I installed more, since many devices operate on this frequency (in particular, car alarms) and interference is possible. Pulse durations for Nice barriers:

  • Logical “1” – 1400 µs low (two intervals) and 700 µs high (one interval)
  • Logic "0" is 700 µs low (one interval) and 1400 µs high (one interval)
  • “Pilot period” – 25200 μs (36 intervals)
  • “Start pulse” – 700 µs (1 interval)
Since neither I nor anyone else has remote controls for this barrier (in such a case it would be possible to simply read the signal from the existing remote control), then you will have to guess the true code by searching through all possible options, but 4096.

How, in general, can all this be realized? My recent passion for Arduino platforms did not allow me to think about this issue for long.

List of components:

1. Arduino Uno,

2. 433 MHz radio transmitter, homemade antenna for it,

3. The battery is 9 volts, popularly “Krona”.

These radio transmitters are sold very cheaply in well-known Chinese stores (about 50 rubles), together with radio receivers. They are very simple, three pins: power, ground and signal pin. Power supply from 5 to 12 volts, the higher the supply voltage, the better the range. This is actually why a 9 volt battery was chosen. The recommended supply voltage for Arduino Uno is from 7 to 12 volts (Vin pin), so the “Krona” is quite suitable. Also, the range of the radio transmitter depends on the presence of an antenna (without it, the range will be about 1 meter). The whole set cost about 300 rubles.

Here, in fact, is the sketch for Arduino Uno:

Int send_code_pin = 13; //int send_code = 3061; this is the code determined by brute force for my barrier void setup() ( pinMode(send_code_pin, OUTPUT); ) void loop () ( for (int send_code = 0; send_code< 4096; send_code++) // этот цикл после того как код определен необходимо убрать { for (int j = 0; j <7; j++) // достаточно 4-х, но из-за помех поставил 7 { digitalWrite(send_code_pin, HIGH); // стартовый импульс delayMicroseconds(700); digitalWrite(send_code_pin, LOW); for (int i = 12; i >0; i--) ( boolean bit_code = bitRead(send_code, i - 1); if (bit_code) ( digitalWrite(send_code_pin, LOW); // unit delayMicroseconds(1400); digitalWrite(send_code_pin, HIGH); delayMicroseconds(700); ) else ( digitalWrite(send_code_pin, LOW); // zero delayMicroseconds(700); digitalWrite(send_code_pin, HIGH); delayMicroseconds(1400); ) ) digitalWrite(send_code_pin, LOW); // pilot period delayMicroseconds(25200); ) ) //delay(10000); after defining the code, set a delay)
Going through all possible options took about 1 week, taking into account one exit per day to the barrier. The technique for quickly selecting the correct code was very simple. Using the command micros() determined the transmission time of one code. It was approximately 0.25 seconds. The total time to go through all the options is about 17 minutes. In front of the barrier, I launched the Arduino and noted the time. At about 12.5 minutes the barrier opened. Based on this, I immediately discarded the first 2800 options. And so on. When there were about 30 options left, after each data transfer I set a delay of 1 second. Since I installed the data transfer contact as 13th (with an LED), every moment of transmission was visible, I counted and determined the exact code.

That's all! As a demo - video of the autopsy.