# Generating Rolling Code with Arduino for RF Switch

I am working home automation using Arduino and TX/RX module. From various sources I learned that Rolling Code based RF Switches are having better security.

I have following queries

1. How suitable it is to use FIXED code RF relays for Home automation. I need it for switching on and off lights and not for key locks.

2. Is it possible to generate rolling code using arduino for a given receiver working on rolling code RF.

1. Using fixed code RF is suitable for your application, as long as you keep it just to lighting/opening curtains/other mundane things. The worst thing that could happen is that an obnoxious (and clever) neighbor figures out how to shut your lights off on you!

2. I would need to know which radio transceiver you are using and what the architecture of your system is to answer this question. I am 90% sure that the answer is "yes, you can make your own rolling code system"

As long as you can program all the nodes in your system yourself, you can make a rolling code system. Here is a bad example with very poor security, but maybe it will help you get the idea.

You have 2 arduinos that need to send ascii messages back and forth. you specify the following protocol: Each message is exactly 4 bytes long. The first 9 bytes contain the data you want to transmit. The last 1 byte contains a key that will be used to encrypt the next transmission. A basic encryption algorithm which adds a constant value to each letter can be used.

Here is an example: Before arduino 1 transmits its message, it encrypts it with our basic encryption algorithm. at startup, the encryption key for both arduinos is 0, so the letters in the first message aren't shifted.

[arduino 1]                                         [arduino 2]
(boots up)                                          (boots up)
|'h'|'e'|'y'| 4 |   ---------------------------->   (recieved "hey", next msg will be shifted by 4.)
|'h'|'i'|'i'| 2 |   -> |h+4 = 'l'|'m'|'m'| 6 | ->   (recieved "lmm", subtract 4 from each letter to get "hey".  Next msg will be shifted by 6 - 4 = 2.)
|'h'|'o'|'w'| 3 |   -> |h+2 = 'j'|'r'|'y'| 5 | ->   (received "jry", subtract 3 from each letter to get "how".  Next msg will be shifted by 5 - 2 = 3.)


Again, this is a HYPOTHETICAL example with very very poor security! I don't know your system architecture or the radio transcievers you are using, so I am not 100% sure if my silly little example would work for you. Even though this is terrible encryption, it would still deter any novice hackers. A real rolling code system is more complex than this. I'm just demonstrating that, as long as you can program all the nodes in your radio network, you can implement your own arbitrary rolling code system.

• Thanks for your response. First question is quite clear to me now. For second question- I am going to user arduino uno R3 along with RF 315MHz or 433MHz transmitter-receiver module. – rahulopengts Sep 7 '14 at 4:28
• Can you please send me a datasheet or product sheet for the rx/tx shield you are using? Also, if you are transmitting data, someone has to be receiving it. Can you please tell me about the system that is receiving the arduino's data? – johnny_boy Sep 7 '14 at 4:33
• THank you very much for the nice explanation. It helps to understand the RF. I am trying to get the datasheet for the product. Will share as soon as i get for further help. THanks again for this. – rahulopengts Sep 8 '14 at 4:44