Toggle remote sockets with 433mhz modules and an atmega microcontroller (ATtiny 2313a)

projects › atmega 21.10.16 scenprogs

While there are many solutions to control remote switches with rasperry pi libraries I want introduce my solution with an atmega microcontroller written in c code.

understand the telegram, part 1

The telegram comes primarily from the 10 dip switches which are placed at the backside of each remote switch.

The first five dip switches tagged with the numbers 1, 2, 3, 4 and 5 are the system code. The system code represents the groups of remote switches and addresses which are remotely controllable. Whereas we have 5 dips in a row we face an address range of 5 bits which are 32 (2^5) different possibilities and groups of remote switches to adress. If we take the picture as an example we see the dips 1, 3, 4 and 5 enabled and dip 2 disabled. While the dip1 is the most significant bit we get the address 23 (2^4 + 2^2 + 2^1 + 2^0 = 16 + 4 + 2 + 1 = 23).

After the system code follow 5 more dip switches called receiver code which are tagged from A till E (A, B, C, D, E) to address one of five remote sockets within a group represented through the system code. In a telegram transmission only one remote socket can switched on or off. This has the consequence that only one dip switch of receiver code part (A till E) is enabled of every remote switch. And this results with 32 groups and 5 receivers in 160 (32*5) different remote switches we can switch on or off using this telegram.


Usually you start up with a set of 3 or 5 remote switches. Therefore you take for your remote switches one of 32 the possible groups. If you take the group 23, I used in the picture, you must set the same system code dip 1 on, dip 2 off, dip 3 on, dip 4 on, dip 5 on in all of your switches and set one of  the receiver dips. The binary addresses for 3 remote sockets than look like this:

10111 10000 (group 23, switch a)

10111 01000 (group 23, switch b)

10111 00100 (group 23, switch c) , displayed in picture

Put it together

Since we have now the knowledge to address the remote switches, the telegram must also involve the information which turns the remote switches on or off. Therefore the telegram includes 2 more bits after the system and receiver code.

To turn the remote switch c of group 23 on (picutre) we have to transmit the following binary telegram:

10111 00100 10

where 10111 is the system address for group 23, 00100 is the receiver address for remote switch C and 10 is the information to turn it on. To turn the switch c of group 23 off the telegram

10111 00100 01 has to transmit.

If we sum up all parts of the telegram we get a 12 bit telegram (5 bit systemcode, 5 bit reicever, 2 bit on/off) for a single telegram transmission.

understand the telegram, part 2

Because wireless transmissions face special conditions the telegram has some adaptions made to increase the transmission success. The binary information referenced through 1 and are transformed into special bit sequences.

telegram signal 0  (dip on)

The telegram signal 0 is a sequence of  the byte 10001000

telegram signal 1 (dip off)

The telegram signal 1 is a sequence of the byte 10001110

Which means if we transmit a 1 or 0 of the telegram displayed under part one we transmit for 1 the byte  10001000 and for 0 the byte 10001110 . Now we can transform the telegram of part 1 into the version the remote switch understands. The remote switch works with inverted logic which is the reason why we must invert the telegram first.

The telegram 10111 00100 10 of part 1 which turns on switch c of group 23 must changed to 01000 11011 01.

If we set for 0 the telegram signal 10001000 and for 1 the telegram signal 10001110 of the telegram 01000 11011 01 we can set up the full binary telegram which turns the remote socket c of group 23 on:

10001000 (010001110 (110001000 (0)  10001000 (0)  10001000 (0)  , system code

10001110 (110001110 (1)  10001000 (010001110 (110001110 (1) , receiver code

10001000 (0)  10001110 (1) , switch switch on

10001110 (1)  10001000 (0) * 31 times , sync signal


Since the telegram is braodcasted in sequence through the 433mhz transmitter module timing is also an important factor for transmission success. Every bit status of the telegram must be present about 400 microseconds for the tranmission.  Simply put, between every level change of the output pin must be a break of about 400 microseconds – or the pin status of our atmega microcontroller changes in a pitch of 400 micro seconds. If we now sum up all bytes transmitted in one telegram we get 44 bytes (5 byte system code + 5 byte receiver code + 2 byte on/off + 32 byte sync signal)  and 352 bit (44 byte * 8 bit) for one telegram whose transmission time is 141 milliseconds (352 Bit * 400 mirco seconds). Every telegram has to be broadcasted at least 2 times, the minimum transmission time is 282 milliseconds which is not that fast if you think about controlling many remote switches with only one 433mhz transmitter module.

wiring up


The used atmega 2313A is wired up in isp configuration. I use the pin PD4 of PORTD for broadcasting (UART out, yellow wire). The 433 mhz transmitter module is supplyed through the isp current.

the c code

The following solution is written for an atemga attiny 2313A. If you use another atmega microcontroller you have to adjust the registers and the used frequency.