Home > Arduino, Home automation > AM Transmitters Arrived

AM Transmitters Arrived

October 28th, 2009 Ed Leave a comment Go to comments

Farnell delivered two packages, ordered at 4PM, the next day via UPS – very impressive, must have costed more than the £8 it cost me (free P&P).

So, with the help of the arduino playground and homeeasyhacking, my arduino could receive and transmit home easy messages.

Prototype

The photo shows my prototype of all parts of the project (ambient light – bit of paper coiled up, will be improved soon – and home easy controller).

Wire the data line of the receiver (any of the two work on my receiver) to pin 8, and the data line of the transmitter to pin 6, and connect power/ground/aerials accordingly (I haven’t used an aerial for the receiver yet). A 23cm piece of wire works well as an aerial. All my cables are strands from CAT5 – I’m a cheap-skate!

To use the following code, first download the HomeEasy package from homeeasyhacking, add the .h and .cpp file (Sketch > Add File), then copy and paste the following code. Upload it, then start the serial monitor.

Press a button on a home easy remote and you should see the sender code – copy this, and replace “2427994″ in the code below with yours. Then restart the program, and whatever you programmed the first button on the first slider of the remote should turn off and on. Make sure, unlike me, you haven’t plugged your computer into that device – I eventually got the code working only to kill my computer’s power, oops!

To control another device, change the setHEDevice(0) line.

#include "HomeEasy.h"
HomeEasy homeEasy;
int onOff = 0;
bool bit2[26]={};
bool bit3[4]={};
int txPin = 6;

void setup(){
homeEasy = HomeEasy();
homeEasy.registerAdvancedProtocolHandler(processReceivedRemote);
homeEasy.init();
pinMode(txPin, OUTPUT);
Serial.begin(9600);
setHEDevice(0); //Set destination home easy device (first device, 0)
itob(2427994,26); //Sender code from remote control - change this to match yours
transmit(1);
delay(10);
transmit(1);
delay(1000);
transmit(0);
delay(10);
transmit(0);
}

void loop(){
//do nothing regularly
}

void processReceivedRemote(unsigned long sender, unsigned int recipient, bool on, bool group) {
Serial.print("Sender: ");
Serial.print(sender);
Serial.print("\nRecipient: ");
Serial.print(recipient);
Serial.print("\nOn: ");
Serial.print(on);
Serial.print("\nGroup: ");
Serial.print(group);
Serial.print("\n\n");
}

void transmit(int blnOn) {
int i;
// Do the latch sequence..
digitalWrite(txPin, HIGH);
delayMicroseconds(275); // bit of radio shouting before we start.
digitalWrite(txPin, LOW);
delayMicroseconds(9900); // low for 9900 for latch 1
digitalWrite(txPin, HIGH); // high again
delayMicroseconds(275); // wait a moment 275
digitalWrite(txPin, LOW); // low again for 2675 - latch 2.
delayMicroseconds(2675);
// End on a high
digitalWrite(txPin, HIGH);
// Send HE Device Address
for (i=0; i<26;i++) {
sendPair(bit2[i]);
}
// Send 26th bit - group 1/0
sendPair(false);
// Send 27th bit - on/off 1/0
sendPair(blnOn);
sendPair(bit3[0]); //MSB
sendPair(bit3[1]);
sendPair(bit3[2]);
sendPair(bit3[3]); //LSB
digitalWrite(txPin, HIGH); // high again (shut up)
delayMicroseconds(275); // wait a moment
digitalWrite(txPin, LOW); // low again for 2675 - latch 2.
}
void sendPair(boolean b) {
// Send the Manchester Encoded data 01 or 10, never 11 or 00
if(b) {
sendBit(true);
sendBit(false);
} else {
sendBit(false);
sendBit(true);
}
}
void sendBit(boolean b) {
if (b) {
digitalWrite(txPin, HIGH);
delayMicroseconds(310); //275 orinally, but tweaked.
digitalWrite(txPin, LOW);
delayMicroseconds(1340); //1225 orinally, but tweaked.
} else {
digitalWrite(txPin, HIGH);
delayMicroseconds(310); //275 orinally, but tweaked.
digitalWrite(txPin, LOW);
delayMicroseconds(310); //275 orinally, but tweaked.
}
}
void itob(unsigned long integer, int length)
{ //needs bit2[length]
// Convert long device code into binary (stores in global bit2 array.)
for (int i=0; i<length; i++){
if ((integer / power2(length-1-i))==1){
integer-=power2(length-1-i);
bit2[i]=1;
}
else bit2[i]=0;
}
}
void setHEDevice(int integer) {
int length = 4;
// Convert long device code into binary (stores in global sendDevice array.)
for (int i=0; i<length; i++){
if ((integer / power2(length-1-i))==1){
integer-=power2(length-1-i);
hedevice[i]=1;
}
else hedevice[i]=0;
}
}
unsigned long power2(int power){ //gives 2 to the (power)
unsigned long integer=1;
for (int i=0; i<power; i++){
integer*=2;
}
return integer;
}

  1. December 16th, 2009 at 19:39 | #1

    Hi there, great to see someone using the HomeEasy arduino library. It’s now been updated so that it can send messages as well as receive them.

  2. Manu91
    February 4th, 2010 at 08:13 | #2

    Hello,
    I Have a problem when I was trying your code, In fact your 3 last for are not complet… :
    “for (int i=0; i ”
    I have completed it with a code found on the arduino site but, I don’t know if my add is good, cause when I used a HE307 interrupt, the code received and put in the good line don’t work… after upload, the light don’t do anythink…
    Can You update your code please ?

  3. Ed
    February 4th, 2010 at 09:35 | #3

    @Manu91
    Sorry about that – HTML escaping went wrong. Code is corrected. FYI, it mostly came from http://www.arduino.cc/playground/Code/HomeEasy

    Good luck getting your code to work!

  4. Manu91
    February 4th, 2010 at 13:03 | #4

    hello,
    thanks for that, you have corrected 1 line, but the other two are same :
    the lines with “for” instruction on “void itob” and “void setHEDevice”
    thanks from a newbee in “C” !

  5. Ed
    February 4th, 2010 at 13:14 | #5

    @Manu91
    Ah, sorry – more escaping needed. Fixed now.

    I’m also relatively new to C – it’s horrible – oh for Java ;)

  1. No trackbacks yet.