Unable to read rf code from my gate remote

Hi i am unable to read rf codes from my gate remote using rf 433 receiver i used everything including these libraries : rf433any, RadioHead, Virtual Wire, rc-switch and finally found this code below for HCS301 micro chip still no luck please help me. I have attached my remote

#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[i];
         };
         uint32_t Encript = 0;
         for(int i = 34; i < 66;i++){
           Encript = (Encript << 1) + HCS_bit_array[i];
         };
         hcs301.Encript = Encript;
       }
     } 
     else {

       HCS_preamble_count = 0;
       goto exit;
     }
   }
 }
exit:;
 //digitalWrite(LED_PIN,cur_status);
}

How do you know what frequency your gate remote is using?

2 Likes

What brand is your gate controller?

1 Like

On the key fob board on a tiny silver piece it says R305. i am not sure if there's any R305 frequency , so i googled and found that most of the remotes uses 433 frequency, i have attached my remotes silver piece closeup pic
20220912_205947

Its steel line

I read HCS301 off the IC and Googled it:
http://ww1.microchip.com/downloads/en/devicedoc/21143b.pdf

It uses code hopping, so good luck.

@anon57585045 penchant for understatement. :expressionless:

@zakirox92 you will succeed by buying a second copy of the receiver and working from there.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.