ATtiny85 RF Remote Control

3,239

8

11

Introduction: ATtiny85 RF Remote Control

NOTE: My Instructable "Virtual Hide-and-Seek Game" shows how to use this type of remote with an RXC6 module which automatically decodes the message.

As I mentioned in a previous Instructable I recently started playing with some ATtiny85 chips. The initial project I had in mind was to make an RF remote control that could operate on a coin battery. I needed to go with a raw chip because none of the Arduinos I have can meet both the need for very low power and relatively small size. A modified LilyPad came close but the chip is a better answer. The idea was not so much to duplicate an existing remote but to demonstrate how you can make up your own transmitter and receiver set. Besides being a fun learning project, it also allows you to create your own “secret” code combination. I put “secret” in quotes because it’s pretty easy to crack these simple codes.

Step 1: RF Message Format

For this project I chose to replicate the signals for one of my Etekcity RF wireless switches (refer to my Instructable on those modules). I did that because I was able to verify that my transmitter works with the Etekcity receiver and that my receiver works with the Etekcity remote. I also happen to know exactly what the correct codes and format are for those devices because I captured them previously. Refer to my “Arduino RF Sensor Decoder” Instructable for the code capture sketch.

The codes and formats for the Etekcity outlets are very typical of inexpensive RF devices. I have cheap security devices that use very similar formats with just some timing variations. The message length is a convenient 24 bits with a long start bit and a short stop bit. You can easily modify the code to add more bytes of data and to change the timing of the sync and data bits. Again, this sketch is just a starting template.

Step 2: Hardware

The transmitter runs on a coin battery (2032) so low power consumption is key. Most of that is accomplished in the software but it is helped by the fact that the ATtiny85 normally runs on the 1-MHz internal clock. The rule is that lower clock frequencies require less power and 1-MHz is perfect for the transmitter logic.

The actual RF transmitter module I like to use is an FS1000A that is commonly available. It comes in both 433-MHz and 315-MHz versions. The software doesn’t care which one you use, but you need to make sure that the receiver board operates at the same frequency. Most of my projects use 433-MHz devices because that is what is used by the various inexpensive wireless devices I have accumulated. The transmitter board layout shown in the picture fits nicely into an old pill bottle. It’s not pretty but good enough for a proof-of-concept.

The receiver is on a solderless breadboard because its only purpose is to show how to receive signals and how to turn something on/off based on the codes received. It uses an LED to indicate on/off status but you could replace that with a relay driver, etc. Any Arduino can be used for the receiver because it doesn’t need to run off of a battery. If size is still a consideration you can use another ATtiny85 chip. The key is that the ATtiny85 needs to run at 8-MHz in the receiver. Refer to my earlier ATtiny85 Instructable for a simple sketch that verifies that you have successfully changed the internal clock to 8-MHz. At the end of my Instructable on sensor decoding I include an Arduino Nano version of the receiver software. It’s identical to the ATtiny85 version included here except for a couple of chip register differences.

As I detailed in my earlier RF Instructables, I prefer to use a receiver like the common RXB6. It’s a super-heterodyne receiver which works much better than the super-regenerative receivers commonly bundled with the FS1000A transmitters.

Both the transmitter and receiver modules work better with the proper antennas but they are often not supplied. You can buy them (get the correct frequency) or you can make your own. At 433-MHz, the right length is about 16 cm for a straight wire antenna. To make a coiled one, take about 16 cm of insulated, solid core wire and wrap it around something like a 5/32-inch drill bit shank in a single layer. Strip the insulation off of a short straight section at one end and connect it to your transmitter/receiver board. I’ve found that the wire from a scrap Ethernet cable works well for antennas. The transmitter board usually has a place to solder the antenna but the receiver board may only have pins (like the RXB6). Just make sure that the connection is secure if you don’t solder it.

Step 3: Software

The transmitter software uses common techniques to put the chip into sleep mode. In that mode it draws less than 0.2ua of current. The switch inputs (D1-D4) have the internal pull-up resistors turned on but they don’t draw any current until a switch is pressed. The inputs are configured for interrupt-on-change (IOC). When a switch is pressed, an interrupt is generated and it forces the chip to wake up. The interrupt handler performs about 48msec of delay to allow the switch to debounce. A check is then made to determine which switch was pressed and the appropriate routine is called. The transmitted message is repeated several times (I chose 5 times). This is typical of commercial transmitters because there is so much RF traffic on 433-MHz and 315-MHz out there. The repeated messages help to ensure that at least one gets through to the receiver.

The sync and bit times are defined at the front of the transmitter software but the data bytes are embedded in each of the four button routines. They are obvious and easy to change and adding bytes to make a longer message is also easy. All of the same defines are included in the receiver software as well as the data byte definitions. If you add data bytes to your message, you will need to change the define for “Msg_Length” and add bytes to the variable “RF_Message”. You will also need to add code to the “RF_Message” check in “loop” to verify the proper receipt of the extra bytes and define those bytes.

Be the First to Share

    Recommendations

    • Make it Glow Contest

      Make it Glow Contest
    • First Time Author Contest

      First Time Author Contest
    • PCB Challenge

      PCB Challenge

    11 Discussions

    0
    Chazza2
    Chazza2

    Question 2 months ago

    Hi
    Do you have the link to Nano version of the receiver please? Also is it possible to use the transmitter with a rotary encoder that also has a push button switch. Like the one on the attached image
    Thankyou
    Chazza2

    Rotary Encoder.jpg
    0
    Boomer48
    Boomer48

    Answer 2 months ago

    I didn't use a Nano for the receiver but you could if you want. Just input the signal from the RXB6 board to D1 or change the input pin in the software. I'm not sure what you want to do with the rotary encoder. The push button switch could be used in place of one of the switches shown in the schematic but the rotary output cannot be used in this project.

    0
    Chazza2
    Chazza2

    Reply 2 months ago

    Hi Boomer48
    Thank you for your prompt reply. I did change the pin to D2 on the Nano
    The bit of code that is giving the error on the Nano is

    bitClear(GIMSK, INT0); // disable INT0 external interrupt
    bitSet(GIMSK, PCIE); // enable interrupt-on-change
    bitSet(PCMSK, Pulse_In);


    When I compile it gives the error ;
    'GIMSK' was not declared in this scope

    If I comment out the the lines
    bitClear(GIMSK, INT0); // disable INT0 external interrupt
    bitSet(GIMSK, PCIE); // enable interrupt-on-change


    It gives the error
    'PCMSK' was not declared in this scope

    I think I need to declare the variables GIMSK and PCMSK but are not sure what types they should be.

    Again Many thanks for your help
    All the best
    Chazza2

    0
    Boomer48
    Boomer48

    Reply 2 months ago

    Yes, I misspoke about using the Nano. The interrupts registers have different labels in the Nano and ATtiny85. My Instructable "Arduino RF Sensor Decoder" shows the correct labels for the Nano. Replace the GIMSK and PCMSK lines with:

    // Enable INT0 external interrupt, trigger on both edges
    bitSet(EICRA, ISC00);
    bitSet(EIMSK, INT0);

    Then change the interrupt handler name to:

    // INT0 interrupt handler
    ISR (INT0_vect)

    The INT0 pin on the Nano is D2 and cannot be changed. I've used the pin change interrupts on the Nano but it is a bit trickier than just using INT0 if you don't use the Interrupts library for the Arduino. Hope this works for you.

    0
    Chazza2
    Chazza2

    Reply 2 months ago

    Hi
    Thank you that is very helpful.
    Regards
    Pingback

    0
    Boomer48
    Boomer48

    Reply 2 months ago

    If you want to make an RF receiver that doesn't need an Arduino, take a look at my Instructable "Virtual Hide-and-Seek Game". The board I use there will decode up to four codes from the same transmitter.

    0
    Chazza2
    Chazza2

    Reply 2 months ago

    PS. The PCIE under
    bitSet(GIMSK, PCIE); // enable interrupt-on-change

    also generates a the following error
    'PCIE' was not declared in this scope

    0
    tytower
    tytower

    1 year ago

    Thats pretty good stuff . Need one for night LED's switch on and off on movement. Can you show me the reverse of the constructed board please. I like the way you have constructed that.

    0
    Aghsistratos
    Aghsistratos

    Reply 5 months ago

    i have this at pcb with Pad2pad if any one want to fix but with 1 button.

    0
    Boomer48
    Boomer48

    Reply 1 year ago

    Sorry for the late response. I never saw a notification that I had a comment. Nothing special for the wiring. Hope the pictures help. After soldering I added some clear glue (like GOOP brand) to the RF transmitter module and to the front switches board to make them sturdy.

    20190927_154310.jpg20190927_154329.jpg
    0
    tytower
    tytower

    Reply 1 year ago

    Thanks