пока только код из видео
// код передатчика #include <SPI.h> #include <RH_RF95.h> #include <Wire.h> #include "SparkFunHTU21D.h" #include <BH1750.h> #include <BMP085.h> RH_RF95 rf95(10, 2); HTU21D myHumidity; BH1750 lightMeter(0x23); BMP085 dps = BMP085(); void setup() { Serial.begin(9600); myHumidity.begin(); lightMeter.begin(BH1750_CONTINUOUS_HIGH_RES_MODE); dps.init(); while (!Serial) ; // Wait for serial port to be available if (!rf95.init()) Serial.println("init failed"); // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on rf95.setTxPower(1); rf95.setFrequency(433.92); rf95.setModemConfig(RH_RF95::Bw125Cr48Sf4096 ); } struct SEND_DATA{ float Humidity; float TemperatureHTU21; long TemperatureBMP180; long Pressure; unsigned int lux; }; SEND_DATA mydata; void loop() { mydata.TemperatureHTU21 = myHumidity.readTemperature(); mydata.Humidity = myHumidity.readHumidity(); mydata.lux = lightMeter.readLightLevel(); dps.getTemperature(&mydata.TemperatureBMP180); dps.getPressure(&mydata.Pressure) ; rf95.send((uint8_t*)&mydata, sizeof(mydata)); rf95.waitPacketSent(); delay(1000); }
// код приемника #include <SPI.h> #include <RH_RF95.h> RH_RF95 rf95(7, 2); struct RECEIVE_DATA{ float Humidity; float TemperatureHTU21; long TemperatureBMP180; long Pressure; unsigned int lux; }; RECEIVE_DATA mydata; void setup() { Serial.begin(9600); while (!Serial) ; // Wait for serial port to be available if (!rf95.init()) Serial.println("init failed"); // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on rf95.setTxPower(1); rf95.setFrequency(433.92); rf95.setModemConfig(RH_RF95::Bw125Cr48Sf4096 ); } void loop() { if (rf95.available()) { uint8_t len = sizeof(mydata); if (rf95.recv((uint8_t*)&mydata, &len)) { Serial.println(mydata.TemperatureHTU21); Serial.println(mydata.TemperatureBMP180); Serial.println(mydata.Humidity); Serial.println(mydata.Pressure/133.3); Serial.println(mydata.lux); Serial.println( ); } } }