Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
I need some help figuring out the protocol this remote uses, so I can write some code to decipher it.
//original code from Arduino Forum, users pmalmsten and David Cuartielles// link: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434/0#0#define IR_Pin 4 // digital pin 4#define ledPin 13 // digital pin 13 #define btnDown 145#define btnUp 144#define btnLeft 146#define btnRight 147#define btnStop 1432// remote control variables#define start_bit 2200 // Start bit threshold (Microseconds)#define bin_1 1000 // Binary 1 threshold (Microseconds)#define bin_0 400 // Binary 0 threshold (Microseconds)void setup(){ pinMode(ledPin, OUTPUT); pinMode(IR_Pin, INPUT); //hardware serial Serial.begin(9600);}void loop(){ Get_IR_Command();}void Get_IR_Command() { int key = getIRKey(); //Fetch the key if (key != -1) { Serial.print("Key: "); Serial.print(key, DEC); } // do something with the key... switch (key) { case btnLeft: TurnLeft(); break; case btnRight: TurnRight(); break; case btnUp: Forward(); break; case btnDown: Reverse(); break; case btnStop: Stop(); break; } }//--------------------------int getIRKey() { int data[12]; //adjust this to match the number of bits your remote sends digitalWrite(ledPin, HIGH); //Ok, i'm ready to recieve while(pulseIn(IR_Pin, LOW) < start_bit) { //Wait for a start bit } for(int i=0;i<11;i++){ data[i] = pulseIn(IR_Pin, LOW); //Start measuring bits, we only want low pulses } digitalWrite(ledPin, LOW); //Done receiving for(int i=0;i<11;i++) { //Parse them if(data[i] > bin_1) { //is it a 1? data[i] = 1; } else { if(data[i] > bin_0) { //is it a 0? data[i] = 0; } else { data[i] = 2; //Flag the data as invalid; I don't know what it is! } } } for(int i=0;i<11;i++) { //Pre-check data for errors if(data[i] > 1) { return -1; //Return -1 on invalid data } } int result = 0; int seed = 1; for(int i=0;i<11;i++) { //Convert bits to integer if(data[i] == 1) { result += seed; } seed = seed * 2; } return result; //Return key number}
I've now gone through and recorded the binary output of all 32 buttons on the remote (it took like, half an hour)
As you can see, each code starts with 8 '0's followed by 8 '1's. Each code ends with '101'.EDIT: Added a third column to the spreadsheet, with the header and stop bits chopped off.EDIT 2: Added 4th column with decimal value of 3rd column.
Button UC1 Decimal UC2 DecimalStandby 10001 17 01110 14Timer 10101 21 01010 10Sleep 10011 19 01100 12Mode 10111 23 01000 8Function 00000 0 11111 311 11000 24 00111 72 11100 28 00011 33 11010 26 00101 5Band 00100 4 11011 274 11110 30 00001 15 11001 25 00110 66 11101 29 00010 2Mute 00001 1 11110 307 11011 27 00100 48 11111 31 00000 09 01000 8 10111 23Tray 00110 6 11001 250 01100 12 10011 19Add 10 01010 10 10101 21Memory 01110 14 10001 17Down 01001 9 10110 22Up 01101 13 10010 18Play 01011 11 10100 20Stop 01111 15 10000 16Auto Scan 10000 16 01111 15Select 10100 20 01011 11Info 10010 18 01101 13Setup 10110 22 01001 9Bass 00010 2 11101 29EQ 00101 5 11010 26Vol- 00011 3 11100 28Vol+ 00111 7 11000 24