Arduino to emulate HT12E Transmitter

Hi folks, I'm new to Arduino but have had some programming over the years.

I have set up a 433 MHz RF link using the HT12E encoder and HT12D decoder as a simple switch.

What I started with is using the Arduino to monitor 5 sensors and transmit a signal to turn the remote switch on for 1/2 a second. I used the RF link with the encoder/decoder chips as a dumb switch - which worked. I then realised that I could remove the HT12E encoder IC and use the Arduino to drive the RF [u]transmitter[/u] directly BUT the info in the PDF of the HT12E is not that helpful when it comes to the format of the code used. It says things like pilot period and sync period.

I only need it to send one packet of encoded data over and over for half a second.

I realise there is a HT12E library - but this is for the Arduino decoding data from a dumb keyfob encoder.

I have read the discussion on the HT12E but the code is not clear to me for a simple example.

HT12E Datasheet

Thank you for any help.

This is the only code I could find on doing this - and there must be a more basic version somewhere but after half a day looking I can't find it simplified.

http://forum.arduino.cc/index.php?topic=54788.0

After more searching I have found a Blog with a tutorial on cloning a 433MHz transmitter, capturing the code and decoding it suitable to transmit again - http://arduinobasics.blogspot.co.uk/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html

May help someone, but not what I was originally after. I'll have to work through it to get what I need because it is like making a radio to listen to morse code, then working out what what all the signals are, decoding it into something useful and then being able to transmit it - when all I wanted was a look-up sheet on morse code.

After I hooked up the scope to the chip this morning I could see the encoding signals quite clearly. Took a little while later to come up with some code for it, and have managed to achieve what I wanted to do with the Arduino!

  • Which is to drive a tranmitter directly from it to a reciever connected to a DVR that has an Alarm input. So when it gets a 5v signal in, it starts recording.
    The receiver has the HT12D decoder chip in it, and I am able to send directly to that when the sensors on the Arduino pick up some movement. The problem was that the DVR system cameras were too far away to detect movement at a distant location, but with the remote sensor module - it can now turn on to film when they trip. As it can decide it’s own filming time, half a second signal is good enough to turn it on. The main program has an inhibit for the same length of time the DVR is on so it is not sending all the time - just when the DVR is off.

Full explanation of the coding is in the header of the program for anyone wanting to use this chip.

If you can improve on the code - please do, as I’ve only been coding a week. Some form of serial monitor output would be good to see what code it is transmitting.

sketch_HT12E_Emulator.ino (3.17 KB)

If anyone can include the code to read here instead of an attachment - please tell me!

/* This sketch can be used instead of the HT12E Encoder IC and be used to drive transmitters directly.
 *  It will be decoded by a simple receiver using the HT12D ic to act as remote switches.
 
 The HT12E transmits a series of bursts of 13 High bits with a space of 7 Milliseconds between bursts.
 Each Bit is 0.2 Milliseconds long for a "0" and 0.4 Milliseconds long for a "1"
 There is 0.6 Milliseconds between the END of each bit Therefore a "0,1" will only have a gap of 0.2Ms
 The easiest way to get the timing right is to call each "0" as 010, and each "1" as 110 when sending pulses.
 With an uncoded chip (with no encoding pins connected to ground) and with no buttons pressed, it
 sends out a signal of 13 bits as all "0"
 The Coding adds a "1" as follows =
 A0 = Bit2=1        A5 = Bit7=1
 A1 = Bit3=1        A6 = Bit8=1
 A2 = Bit4=1        A7 = Bit9=1
 A3 = Bit5=1
 A4 = Bit6=1

 Bit 1 is always a 0 it seems.

 Button Presses affect Bit 10,11,12 & 13
 D8 (pin10) = Bit10
 D9 (pin11) = Bit11
 D10(pin12) = Bit12
 D11(pin13) = Bit13

 Thus with no encoding pins, and pressing button on pin 11, you get - 
 0,0,0,0,0,0,0,0,0,0,1,0,0  as the code to be sent
 as each "0" is sent as a "010" as a voltage square wave, you get
 010010010010010010010010010010110010010, then a gap of 7Ms, then repeat.

 With a supply of 5v to the chip, the data line was still 3v, so sending the data out at 3.3v seems a good idea.
 The HT12D decoder will act as a latch, so if you only transmit this - it will turn on and stay on, 
 so you will need to turn it off again after a short delay.
*/

int dataPin = 3;            // Any pwm pin out you want to connect to the transmitter DATA input
void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
  pinMode(dataPin, OUTPUT); // any output pin 
  
}

void loop() {
 
for (int i=0; i<10; i++) {

delay (7);

zero();           // preamble/ sync
zero();
zero();
zero();
zero();          // ) all 8 bits are the hard encoding A0 - A7
zero();
zero();
zero();
zero();
zero();          // contact on pin D8  (pin 10 on ic)
one();          // corresponds to pressing switch on pin D9 (pin11 on ic)
zero();          // contact on pin D10 (pin 12 on ic)
zero();          // contact on pin D11 (pin 13 on ic)
}                   // Loop for 10 send cycles to make sure it gets the message
delay(500);       // Time for transmit signal On
Off();          // Simple way to call a signal on or off in program
delay(3600);      // Time for signal Off for "Blink"

}

void one ()
{
  digitalWrite(dataPin, HIGH);
  delayMicroseconds(400);
  digitalWrite(dataPin, LOW);
  delayMicroseconds(200);
  
}
void zero () {
  digitalWrite(dataPin, LOW); 
  delayMicroseconds(200);
  digitalWrite(dataPin, HIGH);
  delayMicroseconds(200);
  digitalWrite(dataPin, LOW); 
  delayMicroseconds(200);
  
}
void Off () {
  for (int i=0; i<10; i++){        // Cycles for 10 loops

  delay (7);
  
zero();                           // Off Sequence
zero();
zero();
zero();                           // You could do the same with the On sequence
zero();          
zero();
zero();
zero();
zero();
zero();          
zero();          
zero();          
zero();                         // Off sequence

  }
}
// END

Hello to all,

Dont beat me if I am wrong, tried the Holteks ICs looong time ago. Looked through the code - its simple and should work, but I think I remember, threre was something about frequency setting resistors, which were cruicial to select appropriate, othervise the ICs wouldn't work. Something like 1M for encoder and 51K for decoder. I think someone should mention what resistor should be used for decoder unit, as your code has no specification for decoder oscilator emulation (said not very "politically correct", but you understood). I think I used 47K on decoder, but dont remember the encoder resistor value. Forgot to mention - it should also depend on Arduino clock, so guys, don't forget to check if you're running at 16MHz. If you would make a device and use the lower clock (to save the battery, for example), you might have to adjust the code.