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 :
- 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