Dick Cappels' project pages http://www.projects.cappels.org
Return to HOME (more projects)

A Multifunction 330 MHz Remote Control With an ATTINY2313 Simulating the PT2264 Encoder
This 330 MHz remote control sends timed sequences of control pulses to accomplish complicated tasks.

You can probably tell that I used a lot of solder flux on this board.
Lots of flux not only helps the solder wet to the copper, but it also greatly reduces solder bridges.

WARNING: This project includes a low power radio transmitter. It is up to the potential builder to determine whether the building and use of this transmitter is allowed by the laws governing the locality in which it would be built and used.

Download the AVRStudio assembly source for the program: pt2264i081004A.asm
Download the AVRStudio hex file: pt2264i081004A.hex
Download FreePC files in zipped format: pt2264 7th  freepcb files.zip

Find updates at http://www.projects.cappels.org


I recently had an opportunity to make a RF remote control transmitter to replace one that came on a commerical product.  The commerical product had only one button, and for many operations, the user was required to send multiple timed code bursts by pressing that one button. I figured that this was just crying out for a microcontroller.

And that is how this project got started.

This project is meant to be food for thought, or the starting point for another remote control project, possibly involving a Princeton Technology decoder. The actual firmware is customized for the electronics in my motor control electronics and my ideas of how to use it. in my own particular situation.

Decoding The Encoder And Copying The Functionality

I decided to see if I could make the transmitter and simulate the Princeton technology chip used in the key fob that was part of the commerical package, using an AVR controller. I made a little RF diode detector and looked at the pulses being transmitted -not particularly fast, and that was encouraging. Then I opened the key fob and found that the fob uses the PT2264 encoder, and downloaded the data sheet. Connecting a scope directly to the code output pin on the PT2264, and found the shortest timing period. After consulting the data sheet  I figured out that the clock frequency must be 13.25 kHz

The Assembly Language Code

Armed with the clock frequency, I measured the resistance from each of the address pins on the PT2264 to ground and V+, and from that derived the code. The PT2264 address and data inputs have three logic states: High (near V+), Low (near ground), and floating. After that it was a simple matter of getting the timer in an ATTINY2313 to generate interrupts at the an interval that is equal to the minimum interval between transitions, then writing subroutines to generate the "High", "Low" and "Floating" code patterns, and one more for the "Sync" character, and then another to string them together to make the coded control signal. Additonal routines proivded time delays.

The PT2264 address shown in the assembly language source file is one that I invented for illustrative purposes, and is not the PT2264 address for particular installation for which I wrote it..

The ATTINY2313 comes in both surface mount and DIP versions, so I breadboarded with the DIP because I could use a socket and with it, a Lazy ISP Socket Adapter so I didn't have to put the ISP socket on the PCB.  Once the code as what I wanted, I switched to the surface mount version of the ATTINY2313.

I had thought about switching to an ATTINY13 but when I realized how the pin change interrupt, which is available on the ATTIN2313 but not on the ATINY13, I dropped that idea. At 3 cm wide x 5 cm tall, the circuit board is small enough, especially if you consider the enclosure I wound up with (shown elsewhere on this page).

Here is the structure of the program:

    Start with power-on or when coming out of sleep.

    Initialize internal registers and I/O, then

    If any input pin is low:

                  Go to the routine associated with the first low pin tested.

                  Go to sleep.

    else (if no pin is low)

                Go to sleep.

The routines are as follows:

test: Turn on the transmitter and keep it on until power is removed or the reset pin is pulled low.

manual:  Send the code sequence once, just as when pressing the button on the key fob.

motorcycle_exit: Open the gate so the motorbike can leave, wait a while, then close the gate.

motorycle_enter: Open the gate about one meter so the motorbike can enter, wait a while, then close the gate.

Pedestrian_Open: Open the gate about one meter so a pedestrian can pass through.

Pedestrian_Close: Close the gate after a pedestrian has passed through.

One feature of the structure above, is that all registers and I/O are initialized each time the controller comes out of sleep, thus refreshing the machine's state every time.

Now to make a transmitter

The transmitter does not have to be made on an etched printed circuit board, using a pattern on copper clad board for the inductor/antenna results in more stable and predictable operation than would a loop of wire. so I prefer it. The inductors in the earliest transmitters, such as the breadboard shown above, were cut into a piece of copper clad board using a 1.0 mm drill bit in a hand-held drill as a router. Crude, but it worked. This particular setup used an AT90S2313 rather than a Tiny because I had not yet decided which controller to use, and I still have a pile of AT90S2313's to use up.

Once it looked like I could freeze the basic PT2264 address stream - I was not really able to verify the actual code on the oscilloscope -I hooked it to the oscillator in the photograph above and adjusted the pot. Imagine the excitement, when I looked up and saw the gate opening! This was the best confirmation that the PT2264 data stream was correct.

I tried a couple of different oscillator circuits and finally settled on this one because it seemed better in both terms of reliable starting with various components and the ease of frequency adjustment.

At first, I set out to make a transmitter that would operate from 12 volts, the same as the key fob. Once I got to the micro controller part, I found myself making a 3 volt power supply, powered from the 12 supply, that would turn itself off at the end of a transmission. Well, that seemed to be pretty silly when I realized that I was using a micro controller that has a pin change interrupt and can draw mere tens of nano amps when sleeping. That finally lead to a 3 volt transmitter so I could dispense with all that power management overhead.

The transmitter is shown in the partial schematic above. As mentioned earlier, it is a Hartley oscillator. The inductor was made with a 0.09" trace on this version.

The transistor is a KST10 in an SOT-23 package, from Fairchild. This transistor was a nice choice because it also comes in a TO-92 package as the KSP-10.

Here are the important parameters to keep in mind if making a substitution:

Ft > 650 MHz when the collector current is 4 milliamps
hFE > 60
COB = 0.7 pf

The low 0.7 pf output capacitance is very nice. The low collector-to-base capacitance means that the oscillation frequency will have less dependence on battery voltage than it would with a transistor with a higher output capacitance.

You might want to experiment with values R1, R3, or R2 to optimize the bias for the particular type of transistor you end up using.

The 8 uH choke is a small ferrite bead with the wire passing through the hole four times. I bought a whole bunch of them from what was basically a walkie-talkie repair shop in Bangkok that had gone out of the repair business, and I was anxious to find a use for this inductor. In experiments after this one was made, I found that some chip inductors I had come across, and measured 5 uH, worked just fine too. I have some low-cost doorbell transmitters that operate at 315 MHz use a plastic molded choke, so I am starting to think that the choke itself is not very critical.

With only C1 connected directly across the inductor, setting of the oscillator frequency was very critical. Adding a 10 pf capacitor in series with the C1 reduced the tuning range and made tuning much easier. I don't know what the specified range of C1 is as I bought it surplus, but I measured the range to be 2 pf to 27 pf.

The Circuit

Once the transmitter circuit was working well, all that was left was to add an ATTINY2313, a battery, and some buttons. The Princeton Technology decoders, such as the PT2272, have an amazing tolerance for data rates - about plus or minus 50%. The ATTINY213 is clocked by its internal RC oscillator, and given the wide tolerance of the decoder, I didn't bother to calibrate the oscillator. The five input pins are configured as inputs with internal pullup resistors and the pin change interrupt, set to interrupt when the pin makes a high to low transition, is enabled for each input.

I'm not sure this is a really good idea,  but instead of using a large capacitor across the micro controller's power and ground pins, the controller shares the little 680 pf decoupling capacitor with the transmitter. Maybe a larger capacitor in parallel is a good idea.

Printed Circuit Board Design

The entire circuit was laid out using a free program called FreePCB (www.freepcb.com). As you may guess, I chose this because its free. And I could layout the board without using a schematic drawing program. There is a free schematic drawing program, which is recommended on the FreePCB site, but for now, I still like the looks of my old fashioned schematics.

The FreePCB design file, including the Gerber files, and a library with the nonstandard components in available as a zip file, near the top of this page.

Building It

I etched a printed circuit board using the laser toner resist method. The smallest features are lines 0.025 inches wide. All parts were mounted on the surface of the printed circuit board.  Even the through-hole style trimmer capacitor. I just bent the leads out into an "L" shape and clipped them short.

U1 is mislabeled on the silk-screen drawing (above) as P2. H1 and H2 are the rows of pads used to connect the in-circuit serial programmer, the battery, and the buttons.  I have to point out that I did not test this exact PCB layout. In particular, C5 was added to the layout after I built this board.  As with everything you find on the web, proceed with caution and at your own risk.

 In the hardware version shown in the photographs, C5 was added after the board was etched, so the copper pattern above is not the same as the one in the pictures. The transmitter I made after this one was laid out using the same L1, C1, and C5 pattern used in the artwork above, and it works fine.

The board was laid out with spacing for 1206 components, except for R1, R3, and C5, which are spaced for 0805.

The png files of the artwork are, according to the documentation for PCB-Tools (the package that converted the Gerber files to png files) generated at 200 pixels per inch, as, I think, is the gif image above. In any case, you will probably need to adjust the scaling of the image when you print it. Just make sure the pads for the ATTINY2313 have the right spacing and everything else will take care of itself.

Soldering the #26 insulated wires to the tiny pads was not easy. Prior to connecting these wires, I had connected wires from an Atmel in-system programmer with which I programmed the chip. Those wires were removed, a little more flux added to the pads, and the wires from the battery and the button were connected.

The enclosure was purchased surplus. It has an integrated battery holder for four AA cells, but when I tried to use it with just two AA cells, for 3 volts total, the batteries would not stay in place. I added a little bit of printed circuit board material hot glued into the batter compartment solved the problem.

The top of the enclosure with the button labels temporarily held in place with tape is shown above.


Since battery voltage has some affect on transmit frequency, start with a fresh set of batteries.

The hard way;
Stand with the transmitter a distance from the receiver, and repeatedly push the "manual" button while changing the setting of the tuning capacitor in excruciatingly small increments. Once the transmitter is tuned, move further away until the receiver no longer responds to the transmitter and retune. Repeat until you get so far away that you can't get the receiver to respond, then go back to where you were standing when the receiver last worked, and retune. Very painful, and it does not give the best results.

The easy way: 
I was overjoyed when I realised that my 60 MHz, 1 Gigasample per second Tektronix TDS-2002 scope has some response up to the Nyquist limit of 500 MHz. Good job, Tektronix! I used the scope as an FFT analyzer, which gave me a spectrum analyzer display, adjusted the scope's controls to put 330 MHz in the middle of the screen, with 5 MHz per major division, and just tuned in the oscillator with C1. A variation would be to use an RF (no direct contact) UHF frequency meter or receiver with a signal strength meter as a tuning reference.

Getting the transmitter tuned dead-on is very important, especially since both the transmitter and receiver will drift a bit, and the difference between transmit and receive frequencies affect maximum distance.

HOME (More Projects)
Contents ©2008 Richard Cappels All Rights Reserved. Find updates at www.projects.cappels.org

First posted in October, 2008

You can send  email to me at projects(at)cappels.org. Replace "(at)" with "@" before mailing.

If you find this article on a web site other than cappels.org, please tell me.

Use of information presented on this page is for personal, nonprofit educational and noncommercial use only. This material (including object files) is copyrighted by Richard Cappels and may not be republished or used directly for commercial purposes. For commercial license, click here.

  Liability Disclaimer and intellectual property notice
(Summary: No warranties, use these pages at your own risk. You may use the information provided here for personal and educational purposes but you may not republish or use this information for any commercial purpose without explicit permission.) I neither express nor imply any warranty for the quality, fitness for any particular purpose or  user, or freedom from patents or other restrictions on the rights of use of any software, firmware, hardware, design, service,information, or advice provided, mentioned,or made reference to in these pages. By utilizing or relying on software, firmware, hardware, design, service,information, or advice provided, mentioned, or made reference to in these pages, the user takes responsibility to assume all risk and associated with said activity and hold Richard Cappels harmless in the event of any loss or expense associated with said activity. The contents of this web site, unless otherwise noted, is copyrighted by Richard Cappels. Use of information presented on this site for personal, nonprofit educational and noncommercial use is encouraged, but unless explicitly stated with respect to particular material, the material itself may not be republished or used directly for commercial purposes. For the purposes of this notice, copying binary data resulting from program files, including assembly source code and object (hex) files into semiconductor memories for personal, nonprofit educational or other noncommercial use is not considered republishing. Entities desiring to use any material published in this pages for commercial purposes should contact the respective copyright holder(s).