Hi,
I'm trying to use an arduino as a replacement for the remote for my rf-controlled light switches. I've captured the signals sent from the remote using a rf-receiver, a soundcard and audacity. I'm able to send the signal for on and off for the receiver "1" but only able to send on for "2" and "4" and neither on or off for "3".
My process was to capture the signal from a receiver through a voltage divider and line-in on a soundcard. I then designated a short low for "l", a short high for "h", a long low for "L" and the long low ending signal for "E" (seems like a long low is the same as two short lows, but this works so..). I used the sampling points in audacity to figure out the timings. The following code was used (some borrowed from others work):
const int LED_PIN = 13;
const int TX = 2;
const int short_high = 567;
const int short_low = 612;
const int long_low = 1200;
const int end_low = 17000;
String off1 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhlhLhLE";
String on1 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhlhLhlhLhlhLhLhlhlhLhLhlhLhlhLhlhLhlhLhlhLE";
String off2 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhlhLhLhlhLhlhlhLhLhlhlhLhLhlhlhLhLhlhlhLhLE";
String on2 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhlhLhLhlhLhlhlhLhLhlhlhLhLhlhLhlhLhlhLhlhLE";
String off3 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhLhlhlhLhLhlhLhlhLhlhLhlhLhlhlhLhLhlhlhLhLE";
String on3 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhLhlhlhLhLhlhLhlhLhlhLhlhLhlhLhlhLhlhLhlhLE";
String off4 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhLhlhLhlhLhlhlhLhlhLhLhlhLhlhlhLhLhlhlhLhLE";
String on4 = "hlhlhlhlhlhLhlhLhlhLhlhLhLhlhlhLhLhlhlhLhlhLhlhLhLhlhlhLhlhLhLhlhLhlhLhlhLhlhlhLhlhLhLhlhLhlhLhlhLhlhLhlhLE";
void setup() {
pinMode(TX, OUTPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.print("Initialized");
}
void loop() {
transmit_code(on1);
delay(1000);
}
void transmit_code(const String& code) {
for (int i = 0; i < code.length(); i++) {
switch ( code[i] ) {
case 'h':
// transmit short high
transmit(short_high, 0);
break;
case 'l':
// transmit short low
transmit(0, short_low);
break;
case 'L':
// transmist long low
transmit(0, long_low);
break;
case 'E':
// transmit end of code
transmit(0, end_low);
}
}
}
void transmit(int usecsOn, int usecsOff) {
digitalWrite(LED_PIN, HIGH);
// first turn on
if ( usecsOn > 0 ) {
digitalWrite(TX, HIGH);
delayMicroseconds(usecsOn);
}
// Turn back off
if (usecsOff == 0 ) usecsOff=1;
digitalWrite(TX, LOW);
delayMicroseconds(usecsOff);
digitalWrite(LED_PIN, LOW);
}
Again, turning on and off receiver "1" works flawlessly, but none of the others. My knowledge of RF-signals is very limited, but the logic seems fine. If it works for receiver "1", why not the others? Does anyone have any experience with this sort of projects? Does the timings have to be absolutely correct? I recaptured some of the signals but still ended up with the same "key" for the buttons on the remote. What am I missing?
Thanks!