Pages: [1]   Go Down
Author Topic: Easy remote control  (Read 606 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 203
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I needed a couple indicator lights in a remote location. In the process of building them I stumbled on some easy to use parts that work well with the arduino to make simple remote operated devices.

The first piece is the radio module. I used the Laipac RLP434. This is a 315MHz unit that does about 2400bps over 150 meters. I got mine from sparkfun electronics.  $12 for the transmitter and receiver. http://www.sparkfun.com/ (Other frequencies are available.)

Next is the decoder. The Holtek HT12D is designed for things like garage door openers. You get an 8 bit address and 4 data bits. http://www.holtek.com.tw/english/docum/consumer/2_12d.htm  Note that we don't use the corresponding encoder. We will do that in software since that takes only one data pin instead of 12 on the arduino and we can save parts and soldering. I don't recall where I bought this, maybe futurelec? It was someplace for about $3 and no minimum order.

Yes.. see where we are going? You can put a couple hundred of these around your house and have little lights all over the place that are all individually addressable!

There is very little to be done in the build.  You need to select the clock rate of the decoder to be compatible with the bit rate capability of the radio.  50kohm for the decoder and 1Mohm for the encoder chip (if you used one) fits nicely. (parallel two 100kohm resistors for an easy 50k)

The HT12D doesn't make much current at all, you won't drive an LED directly. I used some little transistors and resistors to drive my uncomfortably bright LEDs.

On the transmitter end it is power, ground, data pin, and a 30cm antenna wire. Nothing to go wrong there.

A note about the radios: The receiver automatically sets its gain, so if you aren't transmitting it turns up the gain until it hallucinates data. You have to use some form of encoding and decoding on the link, fortunately the HT12D takes care of that. Also, you have to send some data to get the radio synced, so you will end up sending your codes several times to make sure they get through.

Now the encoder code:
Code:
int bitTime = 380;// microseconds per cycle of fOsc, 3 of these make up a bit time.
                  // You want this to be 1/50 of the fOsc on the decoder. 380 is the right answer
                  // if you use a 50k resistor for the decoder (2 100k in parallel). This fits nicely
                  // in the 3kHz rate of my radio units and matches with a 1M resistor on the encoder
                  // chip if you use a physical encoder chip instead of software.

void encodeBit( byte pin, byte val)
{
  val = (val ? 1 : 0);
  digitalWrite( pin, 0);
  delayMicroseconds( val ? bitTime * 2 : bitTime );
  digitalWrite( pin, 1);
  delayMicroseconds( val ? bitTime : bitTime * 2 );
}

// Note: depending on your radio you have to do more than one of these. It might take your radio
// a while to settle down.  I have to do 2 with mine.  Maybe a brief period of 1-0-1-0 would be
// faster for getting the radio's attention if you are speed constrained.
void encodeTransmit( byte pin, byte addr, byte data)
{
  byte i,j;
  
  for ( int j = 0; j < 4; j++) {   // send 4 times
    // do the pilot phase
    digitalWrite( pin, 0);
    delayMicroseconds( bitTime * 12);  // make sure we have met minimum low time
    digitalWrite( pin, 1);
    delayMicroseconds( bitTime);       // 1/3 of a bit of high

    for( i = 1; i; i <<= 1) encodeBit( pin, addr&i); // send the address bits
    for( i = 1; i != 0x10; i <<= 1) encodeBit( pin, data&i); // send the data bits
  }
  digitalWrite( pin, 0);  
}

... then you can do things like...
  encodeTransmit( encoderPin, addressByte, valueByte);
  encodeTransmit( encoderPin, addressByte, valueByte);
  encodeTransmit( encoderPin, addressByte, valueByte);
  delay(1000);  // this is a shared radio frequency, don't monopolize it

Notice that bit about not transmitting too often. As I understand this frequency, it is intended for intermittent use. You don't want to get on it and keep it.  Send your code a few times and get off.  Hope it got through. I update my lights every few seconds, so if one doesn't get through it will on the next update.

Also, it is possible for noise or a neighbor's garage door to trigger your decoder and latch in new bits. Don't use this for controlling anything that will upset you if it fires accidentally.

In my application my router collects data and passes bytes down the serial port to the ardino to set the state of the lights. The arduino just acts as the radio controller. In the next incarnation I will put an arduino on the receiving end as well with a 16 channel, 4096 level LED controller chip and have 16 channels of analog current controlled lines for variable intensity lights and driving analog meters... but that is a project for March.

Enjoy.
Logged

Pages: [1]   Go Up
Jump to: