We control the AB400S Wireless Switch socket without a remote control
Recently, I got 3 AB400S Wireless Switch sockets controlled via a 433 MHz radio channel. The remote control from them was lost and the owner did not need them. As always, the inspection began with an analysis of the components.
Here, in fact, is the appearance of the insides of this outlet. The blue wires and the 1.2kΩ resistor were soldered by me, but more on that later.
A capacitor power supply and a 24V relay are immediately visible from above, a signal receiver with a filter on the op-amp, and a decoder of the received signal HX2272-L2, are below. To his right are the legs of the switch (DIP switch), which sets the "address" of the outlet.
I set out to connect it with the ATmega8 microcontroller and try to turn on the relay. I am not a fan of capacitor power supplies, especially when the board will lie on a table in front of my nose. I used a 5V source for power, from which my microcontroller is inserted into a deliberation board (in a breadboard with plug-in contacts).
I had a 433MHz transmitter from another device. To exclude the inoperability of the radio channel when testing the program transmitting data to the decoder, I decided to connect the microcontroller to the decoder directly. Solder the wires to the terminals VCC (18), GND (9) and DIN (14). I did not solder them specifically to the legs of the microcircuit, but simply on these lines where it was convenient.
From the description of the chipit follows that the information transmitted to the decoder consists of one word (word) consisting of 12 bits, followed by a synchronizing bit. Specifically for our decoder, it looks like this:
The value of the bits is set by the voltage level at the inputs A0-A9, bits D0-D1 correspond to the outputs of the same name. If the received address bits match the values set on the switch, then the outputs D0 and D1 take the values of the received bits D0 and D1. The bit can be 0, 1, or f (floating). In the case of “floating”, the input remains unconnected. On the circuit board, you can use 0 and “floating”. There is no way to set the unit, since there is no pull-up resistor. In the program, I used all three options, so a 1.2kOhm resistor was soldered to A0 to check the performance.
The bits are encoded as follows:
Each bit consists of two pulses. For 1 and 0, the first and second pulses coincide, while “floating” in the first cycle has the sequence “0”, in the second “1”. α is the period of the decoder clock. Its value is set by a resistor connected to the legs of OSC1 and OSC2. In our version of the board, it has a value of 1 MΩ.
According to the graphs, you can determine the frequency at which the decoder works. The frequency scale is logarithmic and 10 kHz offset. From the figure it follows that the frequency of the clock generator is approximately equal to 35 kHz.
Check the oscilloscope. To do this, place the oscilloscope probe on the OSC2 leg.
We take a more accurate value. For the decoder, α will be 1 / 34.26 kHz = 29.19 μs. From the description it follows that the decoder operates at a frequency of 2.5 ... 8 times greater than the device that generates the signal received on the DIN leg. Therefore, for coding the signal α of the transmitter can be equal, for example, 29.19 μs / 4 = 7.3 μs.
I will make a reservation right away that I am not a programmer. If there are suggestions on how to make it better, I will be glad to your advice.
Data for sending is stored in a vector. Bits A0 ... A9 correspond to the values set on the switch. (Standard combination from operating instructions) A relay is connected to the D0 output of the decoder via a transistor. The port to which the decoder input is connected is configured for output and is immediately turned on during initialization. When flashing the microcontroller, the relay should turn on immediately in accordance with the data in the vector.
The transmission cycle of the same data is repeated 3 times. Pressing the button inverts the last bit (on / off function) and resets the number of transmissions (transmitNum). I used a timer that calls the function (rf_function) every 7.3 μs if a button connected to the microcontroller was pressed.
Each time the function is called, counter α is incremented by one. If the number of passed α corresponds to the required number of ticks for the formation of one or another bit, then the pin value is inverted. After 16α (time of one cycle), the counter α is reset to zero and the cycle counter is incremented by one. The operation is repeated again. After two cycles, a new bit is taken from the vector and the operation is repeated until 12 bits are transmitted. Then a clock pulse is sent. It has other temporal characteristics.
At the stage of the test with the disassembled socket, the program's performance could be judged by the illuminated LED (the indicator for turning on the socket), because 5V power was supplied, and the relay is rated at 24V.
After successfully testing and connecting the transmitter (433 MHz), the socket immediately began to be controlled by radio.
The next goal is to connect the microcontroller to a smartphone and control three outlets. But that's another story.
Here, in fact, is the appearance of the insides of this outlet. The blue wires and the 1.2kΩ resistor were soldered by me, but more on that later.
A capacitor power supply and a 24V relay are immediately visible from above, a signal receiver with a filter on the op-amp, and a decoder of the received signal HX2272-L2, are below. To his right are the legs of the switch (DIP switch), which sets the "address" of the outlet.
I set out to connect it with the ATmega8 microcontroller and try to turn on the relay. I am not a fan of capacitor power supplies, especially when the board will lie on a table in front of my nose. I used a 5V source for power, from which my microcontroller is inserted into a deliberation board (in a breadboard with plug-in contacts).
I had a 433MHz transmitter from another device. To exclude the inoperability of the radio channel when testing the program transmitting data to the decoder, I decided to connect the microcontroller to the decoder directly. Solder the wires to the terminals VCC (18), GND (9) and DIN (14). I did not solder them specifically to the legs of the microcircuit, but simply on these lines where it was convenient.
From the description of the chipit follows that the information transmitted to the decoder consists of one word (word) consisting of 12 bits, followed by a synchronizing bit. Specifically for our decoder, it looks like this:
The value of the bits is set by the voltage level at the inputs A0-A9, bits D0-D1 correspond to the outputs of the same name. If the received address bits match the values set on the switch, then the outputs D0 and D1 take the values of the received bits D0 and D1. The bit can be 0, 1, or f (floating). In the case of “floating”, the input remains unconnected. On the circuit board, you can use 0 and “floating”. There is no way to set the unit, since there is no pull-up resistor. In the program, I used all three options, so a 1.2kOhm resistor was soldered to A0 to check the performance.
The bits are encoded as follows:
Each bit consists of two pulses. For 1 and 0, the first and second pulses coincide, while “floating” in the first cycle has the sequence “0”, in the second “1”. α is the period of the decoder clock. Its value is set by a resistor connected to the legs of OSC1 and OSC2. In our version of the board, it has a value of 1 MΩ.
According to the graphs, you can determine the frequency at which the decoder works. The frequency scale is logarithmic and 10 kHz offset. From the figure it follows that the frequency of the clock generator is approximately equal to 35 kHz.
Check the oscilloscope. To do this, place the oscilloscope probe on the OSC2 leg.
We take a more accurate value. For the decoder, α will be 1 / 34.26 kHz = 29.19 μs. From the description it follows that the decoder operates at a frequency of 2.5 ... 8 times greater than the device that generates the signal received on the DIN leg. Therefore, for coding the signal α of the transmitter can be equal, for example, 29.19 μs / 4 = 7.3 μs.
I will make a reservation right away that I am not a programmer. If there are suggestions on how to make it better, I will be glad to your advice.
Data for sending is stored in a vector. Bits A0 ... A9 correspond to the values set on the switch. (Standard combination from operating instructions) A relay is connected to the D0 output of the decoder via a transistor. The port to which the decoder input is connected is configured for output and is immediately turned on during initialization. When flashing the microcontroller, the relay should turn on immediately in accordance with the data in the vector.
short sendVector[12] = {0,2,0,2,0,0,2,2,2,2,0,1}; // A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 D1 D0
// BIT0 =0; BIT1 =1; BITf =2
The transmission cycle of the same data is repeated 3 times. Pressing the button inverts the last bit (on / off function) and resets the number of transmissions (transmitNum). I used a timer that calls the function (rf_function) every 7.3 μs if a button connected to the microcontroller was pressed.
rf_function
void rf_function(void) {
static short alphaCounter = 0; // подсчет количества тактов
static short bitCounter = 0; // подсчет переданных бит
static short cycle = 0; // подсчет количества повторов
if (bitCounter < 12) // отправить 12 бит
{
alphaCounter++;
if (cycle == 0) {
if ((alphaCounter == 4) && (sendVector[bitCounter] != 1)) // BIT0 и BITf идентичны
{
togglePin('C', _PIN0); //инвертировать пин
}
if ( (alphaCounter == 12) && (sendVector[bitCounter] == 1))
{
togglePin('C', _PIN0);
}
}
else {
if ((alphaCounter == 4) && (sendVector[bitCounter] == 0)) // BIT1 и BITf идентичны
{
togglePin('C', _PIN0); //инвертировать пин
}
if ( (alphaCounter == 12) && (sendVector[bitCounter] != 0))
{
togglePin('C', _PIN0);
}
}
if (alphaCounter == 16) // один цикл завершен
{
togglePin('C', _PIN0);
cycle++;
alphaCounter = 0; //сброс после выполнения одного цикла
}
if (cycle == 2) // переходим на следующий бит в векторе после 2х циклов
{
cycle = 0;
bitCounter++;
}
}
else //передаем синхронизирующий импульс
{
alphaCounter++;
if (alphaCounter == 4)
{
togglePin('C', _PIN0);
}
if (alphaCounter == 128)
{
togglePin('C', _PIN0);
bitCounter = 0; //сбросить счетчик после передачи всех бит
alphaCounter = 0; //сброс перед новой передачей
transmitNum++; // увеличить счетчик после каждой передачи
}
}
}
Each time the function is called, counter α is incremented by one. If the number of passed α corresponds to the required number of ticks for the formation of one or another bit, then the pin value is inverted. After 16α (time of one cycle), the counter α is reset to zero and the cycle counter is incremented by one. The operation is repeated again. After two cycles, a new bit is taken from the vector and the operation is repeated until 12 bits are transmitted. Then a clock pulse is sent. It has other temporal characteristics.
At the stage of the test with the disassembled socket, the program's performance could be judged by the illuminated LED (the indicator for turning on the socket), because 5V power was supplied, and the relay is rated at 24V.
After successfully testing and connecting the transmitter (433 MHz), the socket immediately began to be controlled by radio.
The next goal is to connect the microcontroller to a smartphone and control three outlets. But that's another story.