實驗硬件
發射端
Arduino + 433超外差發射機 高,低電平和懸空三種模式切換 由簡單的官方庫修改
/* This is a minimal sketch without using the library at all but only works for the 10 pole dip switch sockets. It saves a lot of memory and thus might be very useful to use with ATTinys :) https://github.com/sui77/rc-switch/ */ int RCLpin = 10; void setup() { pinMode(RCLpin, OUTPUT); } void loop() { // RCLswitch(0b010001000001); // DIPs an Steckdose: 0100010000 An:01 // delay(2000); // RCLswitch(0b010001000010); // DIPs an Steckdose: 0100010000 Aus:10 // RCLswitch(0); // delay(2000);
// digitalWrite(RCLpin, LOW);// 不停觸發
digitalWrite(RCLpin, HIGH);// 不處發 } void RCLswitch(uint16_t code) { for (int nRepeat=0; nRepeat<6; nRepeat++) { for (int i=4; i<16; i++) { RCLtransmit(1,3); if (((code << (i-4)) & 2048) > 0) { RCLtransmit(1,3); } else { RCLtransmit(3,1); } } RCLtransmit(1,31); } } void RCLtransmit(int nHighPulses, int nLowPulses) { digitalWrite(RCLpin, HIGH); delayMicroseconds( 350 * nHighPulses); digitalWrite(RCLpin, LOW); delayMicroseconds( 350 * nLowPulses); }
STM8+ 433超外差發射機 命令 = 引導碼+一系列高低電平
--------------------
接收端
Arduino + 433超外差接收機 四種中斷模式切換
int pin =13; volatile int state = LOW; int i=0; void setup() {Serial.begin(9600); pinMode(pin, OUTPUT); //attachInterrupt(0, blink, CHANGE);// 低 一直觸發 高 一直不觸發 attachInterrupt(0, blink,LOW); // 低 一直觸發 高 一直觸發 //attachInterrupt(0, blink,RISING); //低 一直觸發 高 不觸發 // attachInterrupt(0, blink,FALLING); //低 一直觸發 高 不觸發 很穩 digitalWrite(pin,!state); delay(10000); digitalWrite(pin, state); delay(10000); } void loop() { // digitalWrite(pin, state); } void blink() { Serial.println(i+1); state = !state; }
Arduino + 433超外差接收機 官方庫正常解碼模式
/* Simple example for receiving https://github.com/sui77/rc-switch/ */ #include <RCSwitch.h> #define led1 10 #define led2 11 RCSwitch mySwitch = RCSwitch(); void setup() { Serial.begin(9600); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2 } void loop() { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { Serial.print("Unknown encoding"); } else { if (value ==17) { if( digitalRead(led1)==0){ digitalWrite(led1, HIGH); } else{ digitalWrite(led1, LOW); } } if (value ==18) { if( digitalRead(led2)==0){ digitalWrite(led2, HIGH); } else{ digitalWrite(led2, LOW); } } Serial.print("Received "); Serial.print( mySwitch.getReceivedValue() ); Serial.print(" / "); Serial.print( mySwitch.getReceivedBitlength() ); Serial.print("bit "); Serial.print("Protocol: "); Serial.println( mySwitch.getReceivedProtocol() ); } mySwitch.resetAvailable(); } }
發射信號引腳狀態\接收信號引腳中斷觸發方式 | 上升沿 | 下降沿 | 改變(上升+下降) | 低電平 |
高電平 | 不觸發 | 不觸發 | 不觸發 | 一直觸發 |
低電平 | 一直觸發 | 一直觸發 | 一直觸發 | 一直觸發 |
懸空 | 一直觸發 | 一直觸發 | 一直觸發 | 一直觸發 |
測試結果
可怕結論: 433和330MH信號很容易被針對干擾(又何止是這個頻段),具體怎么實現懂的人看表格就能分析出來吧。(讓所有這個頻段的設備在干擾范圍不起作用,怪不國家要嚴格控制頻帶的划分和使用還有監測,這么大的弊端)。
可使用到產品的基礎:只要沒人特意干擾你,大多數的干擾都是隨機的,可以通過接收端編碼過濾掉。
可用結論:接收端使用上升沿或下降沿或改變三種方式來解碼命令
---恢復內容結束---