hcs301 key fob chip-need code send/receive

Dear all,
i need arduino code to do following: to receive and send same rf 433mhz signal forward(to gate receiver).

Why i need this.
My house is far away from gate, and there are a few trees, so my key fob rf signal cant reach to gate receiver to open the gate from my window. I got an idea to use my arduino uno and 433mhz receiver and tramsmiter to do that(receive and send signal from my key fob to the gate).

Hardware that i have is :

  1. Doorhan key fob. HCS301 chip inside, 433,25mhz frequency.
    2 Arduino uno(clone)
    3.Rf 433mhz receiver
    4.Rf 433mhz transmitter

i use this code for receiver, and its working, but i need code to send this same signal forward.

#define LED_PIN 13
#define HCS_RECIEVER_PIN 2 // pin is connected to a receiver for remote controls

class HCS301 {
public:
unsigned BattaryLow :
1;
unsigned Repeat :
1;
unsigned BtnNoSound :
1;
unsigned BtnOpen :
1;
unsigned BtnClose :
1;
unsigned BtnRing :
1;
unsigned long SerialNum;
unsigned long Encript;
void print();
};

volatile boolean HCS_Listening = true;
byte HCS_preamble_count = 0;
uint32_t HCS_last_change = 0;
//uint32_t HCS_start_preamble = 0;
uint8_t HCS_bit_counter;
uint8_t HCS_bit_array[66];
#define HCS_TE 400
#define HCS_Te2_3 600 // HCS_TE * 3 / 2

HCS301 hcs301;

void setup()
{
Serial.begin(115200);
pinMode(HCS_RECIEVER_PIN, INPUT);
attachInterrupt(0, HCS_interrupt, CHANGE);
Serial.println(“Setup OK”);
}

void loop()
{
long CurTime = millis();

if(HCS_Listening == false){
HCS301 msg;
memcpy(&msg,&hcs301,sizeof(HCS301));
HCS_Listening = true;
Serial.println(String(“KeyFb#”)+String(msg.SerialNum));
}
}

void HCS301::print(){
String btn;
if (BtnRing == 1) btn += “Ring”;
if (BtnClose == 1) btn += “Close”;
if (BtnOpen == 1) btn += “Open”;
if (BtnNoSound == 1) btn += “NoSound”;
String it2;
it2 += "Encript ";
it2 += Encript;
it2 += " Serial “;
it2 += SerialNum;
it2 += " “;
it2 += btn;
it2 += " BattaryLow=”;
it2 += BattaryLow;
it2 += " Rep=”;
it2 += Repeat;
Serial.println(it2);
}

void HCS_interrupt(){
if(HCS_Listening == false){
return;
}
uint32_t cur_timestamp = micros();
uint8_t cur_status = digitalRead(HCS_RECIEVER_PIN);
uint32_t pulse_duration = cur_timestamp - HCS_last_change;
HCS_last_change = cur_timestamp;
if(HCS_preamble_count < 12){
if(cur_status == HIGH){
if( ((pulse_duration > 150) && (pulse_duration < 500)) || HCS_preamble_count == 0){

//if(HCS_preamble_count == 0){
// HCS_start_preamble = cur_timestamp;
//}
}
else {

HCS_preamble_count = 0;
goto exit;

}
}
else {

if((pulse_duration > 300) && (pulse_duration < 600)){

HCS_preamble_count ++;
if(HCS_preamble_count == 12){

//HCS_Te = (cur_timestamp - HCS_start_preamble) / 23;
//HCS_Te2_3 = HCS_Te * 3 / 2;
HCS_bit_counter = 0;
goto exit;
}
}
else {

HCS_preamble_count = 0;
goto exit;
}
}
}

if(HCS_preamble_count == 12){
if(cur_status == HIGH){
if(((pulse_duration > 250) && (pulse_duration < 900)) || HCS_bit_counter == 0){

}
else {

HCS_preamble_count = 0;
goto exit;
}
}
else {

if((pulse_duration > 250) && (pulse_duration < 900)){
HCS_bit_array[65 - HCS_bit_counter] = (pulse_duration > HCS_Te2_3) ? 0 : 1;
HCS_bit_counter++;
if(HCS_bit_counter == 66){

HCS_Listening = false;
HCS_preamble_count = 0;
hcs301.Repeat = HCS_bit_array[0];
hcs301.BattaryLow = HCS_bit_array[1];
hcs301.BtnNoSound = HCS_bit_array[2];
hcs301.BtnOpen = HCS_bit_array[3];
hcs301.BtnClose = HCS_bit_array[4];
hcs301.BtnRing = HCS_bit_array[5];
hcs301.SerialNum = 0;
for(int i = 6; i < 34;i++){
hcs301.SerialNum = (hcs301.SerialNum << 1) + HCS_bit_array*;*

  • };*
  • uint32_t Encript = 0;*
  • for(int i = 34; i < 66;i++){*
    Encript = (Encript << 1) + HCS_bit_array*;
    _
    };_
    _
    hcs301.Encript = Encript;_
    _
    }_
    _
    }_
    _
    else {*_

* HCS_preamble_count = 0;
_
goto exit;_
_
}_
_
}_
_
}_
exit:;
//digitalWrite(LED_PIN,cur_status);
_
}*_
I dont need to decode signal, just to forward it via arduino to the gate. i will place arduino somewhere inbetween my house and the gate so it could be reachable to my key fob and gate.
Thanks

Please edit your post and post your code properly: add code tags (</> button).

#define LED_PIN     13
#define HCS_RECIEVER_PIN  2 // pin is connected to a receiver for remote controls
 
class HCS301 {
public:
unsigned BattaryLow :
 1; 
unsigned Repeat :
 1;
unsigned BtnNoSound :
 1;
unsigned BtnOpen :
 1;
unsigned BtnClose :
 1;
unsigned BtnRing :
 1;
 unsigned long SerialNum;
 unsigned long Encript;
 void print();
};
 
volatile boolean    HCS_Listening = true;     
byte                HCS_preamble_count = 0;
uint32_t            HCS_last_change = 0;
//uint32_t          HCS_start_preamble = 0;
uint8_t             HCS_bit_counter;               
uint8_t             HCS_bit_array[66];             
#define             HCS_TE      400               
#define             HCS_Te2_3   600                 // HCS_TE * 3 / 2
 
HCS301 hcs301;
 
void setup()
{
 Serial.begin(115200);
 pinMode(HCS_RECIEVER_PIN, INPUT);
 attachInterrupt(0, HCS_interrupt, CHANGE);
 Serial.println("Setup OK");
}
 
void loop()
{
 long CurTime = millis();
 
 if(HCS_Listening == false){
   HCS301 msg;
   memcpy(&msg,&hcs301,sizeof(HCS301));
   HCS_Listening = true;
   Serial.println(String("KeyFb#")+String(msg.SerialNum));
 }
}
 
void HCS301::print(){
 String btn;
 if (BtnRing == 1) btn += "Ring";
 if (BtnClose == 1) btn += "Close";
 if (BtnOpen == 1) btn += "Open";
 if (BtnNoSound == 1) btn += "NoSound";
 String it2;
 it2 += "Encript ";
 it2 += Encript;
 it2 += " Serial ";
 it2 += SerialNum;
 it2 += " ";
 it2 += btn;
 it2 += " BattaryLow=";
 it2 += BattaryLow;
 it2 += " Rep=";
 it2 += Repeat;
 Serial.println(it2);
}
 
void HCS_interrupt(){
 if(HCS_Listening == false){
   return;
 }
 uint32_t cur_timestamp = micros();
 uint8_t  cur_status = digitalRead(HCS_RECIEVER_PIN);
 uint32_t pulse_duration = cur_timestamp - HCS_last_change;
 HCS_last_change         = cur_timestamp;
 if(HCS_preamble_count < 12){
   if(cur_status == HIGH){
     if( ((pulse_duration > 150) && (pulse_duration < 500)) || HCS_preamble_count == 0){
 
       //if(HCS_preamble_count == 0){
       //  HCS_start_preamble = cur_timestamp;
       //}
     }
     else {
       
       HCS_preamble_count = 0;
       goto exit;
 
     }
   }
   else {
 
     if((pulse_duration > 300) && (pulse_duration < 600)){
 
       HCS_preamble_count ++;
       if(HCS_preamble_count == 12){
 
         //HCS_Te = (cur_timestamp - HCS_start_preamble) / 23; 
         //HCS_Te2_3 = HCS_Te * 3 / 2;
         HCS_bit_counter = 0;
         goto exit;
       }
     }
     else {
 
       HCS_preamble_count = 0;
       goto exit;
     }
   }
 }
 
 if(HCS_preamble_count == 12){
   if(cur_status == HIGH){
     if(((pulse_duration > 250) && (pulse_duration < 900)) || HCS_bit_counter == 0){
 
     }
     else {
 
       HCS_preamble_count = 0;
       goto exit;
     }
   }
   else {
 
     if((pulse_duration > 250) && (pulse_duration < 900)){
       HCS_bit_array[65 - HCS_bit_counter] = (pulse_duration > HCS_Te2_3) ? 0 : 1;
       HCS_bit_counter++;
       if(HCS_bit_counter == 66){
 
         HCS_Listening = false;
         HCS_preamble_count = 0;
         hcs301.Repeat = HCS_bit_array[0];
         hcs301.BattaryLow = HCS_bit_array[1];
         hcs301.BtnNoSound = HCS_bit_array[2];
         hcs301.BtnOpen = HCS_bit_array[3];
         hcs301.BtnClose = HCS_bit_array[4];
         hcs301.BtnRing = HCS_bit_array[5];
         hcs301.SerialNum = 0;
         for(int i = 6; i < 34;i++){
           hcs301.SerialNum = (hcs301.SerialNum << 1) + HCS_bit_array;
         };
         uint32_t Encript = 0;
         for(int i = 34; i < 66;i++){
           Encript = (Encript << 1) + HCS_bit_array;
         };
         hcs301.Encript = Encript;
       }
     }
     else {
 
       HCS_preamble_count = 0;
       goto exit;
     }
   }
 }
exit:;
 //digitalWrite(LED_PIN,cur_status);
}

Also, code should do next: receive signal, wait 1 sec, then send same signal, then stop sending.

Can someone explain, what this code really does. i see that is working, and on serial monitor appears this:

start
 - keelog invert - 
FC2A33E-hop
4BFB14-fix
E4-btn
3-dop
- sending keelog -
FC - 2 - A3 - 3E - 4B - FB - 14 - E4 - 3 -  - keelog invert - 
6A8967-hop
4BFB14-fix
E4-btn
3-dop
- sending keelog -
6 - A - 89 - 67 - 4B - FB - 14 - E4 - 3 -  - keelog invert - 
DD82A5C7-hop
4BFB14-fix
E4-btn
2-dop
- sending keelog -
DD - 82 - A5 - C7 - 4B - FB - 14 - E4 - 2 -  - keelog invert

and the code is:

#include "math.h" 


#define txPin 8
#define rxPin 7
#define signalPin 6

int lastRxValue = 0;
int tempRxValue = 0;
unsigned long lastRxTime = 0;
unsigned long tempTime = 0;
unsigned long difTime = 0;
boolean bValidPacket = false;
int decodeMethod = 1; //0 real - as in manual, 1 inver as Oleg do


//Global vars end
void send_meander(int time){
  digitalWrite(txPin, HIGH);
  delayMicroseconds(time);
  digitalWrite(txPin, LOW);
  delayMicroseconds(time);
}
//keelog start
int keelog_state = 0;
int keelogCounter = 0;
byte keelog_code[9];

void keelog_vardump(){
  if(decodeMethod == 0){
    Serial.println(" - keelog origin - ");
  }
  else{
    Serial.println(" - keelog invert - ");
  }
  Serial.print(keelog_code[0], HEX);
  Serial.print(keelog_code[1], HEX);
  Serial.print(keelog_code[2], HEX);
  Serial.print(keelog_code[3], HEX);
  Serial.println("-hop");
  Serial.print(keelog_code[4], HEX);
  Serial.print(keelog_code[5], HEX);
  Serial.print(keelog_code[6], HEX);
  Serial.println("-fix");
  Serial.print(keelog_code[7], HEX);
  Serial.println("-btn");
  Serial.print(keelog_code[8], HEX);
  Serial.println("-dop");
  
  /*for(int i = 0; i<9; i++){
    Serial.print(keelog_code[i], HEX);
    Serial.print(" - ");
  }*/
  keelog_send(keelog_code);
  digitalWrite(signalPin, HIGH);
  delay(100);
  digitalWrite(signalPin, LOW);
  keelog_state = 0;
  for(int i = 0; i<9; i++){
    keelog_code[i]=0;
  }
}
void keelog_send(byte* keelog_code){
  Serial.println("- sending keelog -");
  for(int i = 0; i<9; i++){
    Serial.print(keelog_code[i], HEX);
    Serial.print(" - ");
  }
  for(int i = 0; i<11; i++){//посылаем преамблу
    send_meander(400);
  }
  digitalWrite(txPin, HIGH);
  delayMicroseconds(400);
  digitalWrite(txPin, LOW);
  delayMicroseconds(4000);//посылаем хедер
  
  for( int i = 0; i<9; i++){
    if(decodeMethod==1){
      for(int i2 = 7;i2>=0;i2--){
        if(bitRead(keelog_code[i], i2)){
          digitalWrite(txPin, HIGH);
          delayMicroseconds(400);
          digitalWrite(txPin, LOW);
          delayMicroseconds(2*400);
        }
        else{
          digitalWrite(txPin, HIGH);
          delayMicroseconds(2*400);
          digitalWrite(txPin, LOW);
          delayMicroseconds(400);
        }
      }
    }
    else{
        for(int i2 = 0;i2<8;i2++){
          if(!bitRead(keelog_code[i], i2)){
            digitalWrite(txPin, HIGH);
            delayMicroseconds(400);
            digitalWrite(txPin, LOW);
            delayMicroseconds(2*400);
          }
          else{
            digitalWrite(txPin, HIGH);
            delayMicroseconds(2*400);
            digitalWrite(txPin, LOW);
            delayMicroseconds(400);
          }
       } 
    }
    
  }
}
void keelog_get(){
    bValidPacket = false;
    if(keelog_state==0){//ждем преамбулу и хедер
      if(difTime > 280 && difTime < 620 && lastRxValue != tempRxValue){
        keelogCounter ++;
      }
      else{
        if(keelogCounter==23){
          if(difTime>2800 && difTime<6200 && lastRxValue == 0){
            keelog_state=1;
          }
        }
       keelogCounter = 0;
      }
    }
    else if(keelog_state==1){// получаем биты
      if(difTime > 560 && difTime < 1240 && lastRxValue == 1){// получили 1
        if(decodeMethod==0){
          keelog_code[round(keelogCounter/8)] = (keelog_code[round(keelogCounter/8)]>>1)|B10000000;
        }
        else{
          keelog_code[round(keelogCounter/8)] = (keelog_code[round(keelogCounter/8)]<<1)|B00000000;
        }
        bValidPacket = true;
      }
      else if(difTime > 280 && difTime < 620 && lastRxValue == 1){
        if(decodeMethod==0){
          keelog_code[round(keelogCounter/8)] = (keelog_code[round(keelogCounter/8)]>>1)|B00000000;
        }
        else{
          keelog_code[round(keelogCounter/8)] = (keelog_code[round(keelogCounter/8)]<<1)|B00000001;
        }
        bValidPacket = true;
      }
      else if(lastRxValue == 0){
      }
      else{
        keelog_state=1;
        keelogCounter = 0;
      }
      
      if(bValidPacket){
        keelogCounter++;
        if(keelogCounter==66){
          keelog_vardump();
          keelogCounter = 0;
          keelog_state = 0;
        }
      }
    }
}
//keelog end


void setup() {                
  pinMode(txPin, OUTPUT);
  pinMode(rxPin, INPUT);
  pinMode(signalPin, OUTPUT);
  //
  Serial.begin(9600);
  Serial.println("start");
  lastRxValue = digitalRead(rxPin);
  lastRxTime = micros();
  
  //attachInterrupt(0, grab, CHANGE);
}

void loop() {
  tempRxValue = digitalRead(rxPin);
  
  if(tempRxValue != lastRxValue){
    tempTime = micros();
    difTime = tempTime - lastRxTime;
    keelog_get();  
    lastRxTime = tempTime;
    lastRxValue = tempRxValue;
  }
}

Yes, repete the incoming RX data to a TX. It is a repeter rebuilding the code, I got it via RTL-SDR, it works very fine.

But I was searching some code to clone my remote with rolling code for my bike !!
No way until now.

See you.
Rino.