Problems with 433MHz module

Hi! I have a pair of transmitter-receiver modules that communicate on 433MHz. I've written Arduino sketch for sending data from Arduino Uno to Arduino Pro Mini. While everything works fine, radio modules don't seem to communicate. I think that transmitter isn't transmitting because when I set it to send data every 0 seconds, LED blinks fast even though I've set baud rate to 10.

Here is code for transmitter:

#include <Wire.h>
#include <dht.h>
#include <Adafruit_BMP085.h>
#include <RTClib.h>
#include <WeatherCalculations.h>
#include <VirtualWire.h>

const byte DHTpin = 9;
const byte transmitPin = 10;
const float altitude = 222.0;

dht DHT;
Adafruit_BMP085 BMP;
RTC_DS1307 RTC;
Weather weather;

unsigned long lastTimeSensors = 2000UL;
unsigned long lastTimeTransmitter = 2000UL;
boolean correct = false;
boolean ledState = false;

struct packet {
  float dewPoint, temperature, seaLevelPressure, airPressure, humidity;
  byte hour, minute, second, day, month;
  unsigned int year;
  boolean clockTicking;
};
typedef struct packet Packet;
Packet data;

void setup() {
  while (!BMP.begin() || !RTC.begin()) {}

  vw_set_tx_pin(transmitPin);
  vw_setup(500);       // Bits per sec
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  readSensorsAndTime();
  sendData();
}

void readSensorsAndTime() {
  if (millis() - lastTimeSensors >= 2000) {
    do {
      correct = DHT.read22(DHTpin);
      data.humidity = DHT.humidity;
      lastTimeSensors = millis();
    } while (correct || data.humidity > 100.0);
  }
  data.temperature = BMP.readTemperature();
  data.airPressure = BMP.readPressure() / 100.0;
  data.seaLevelPressure = weather.getSeaLevelPressure(altitude, data.airPressure);
  data.dewPoint = weather.getDewPoint(data.temperature, data.humidity);

  data.clockTicking = RTC.isrunning();

  DateTime now = RTC.now();

  data.day = now.day();
  data.month = now.month();
  data.year = now.year();
  data.hour = now.hour();
  data.minute = now.minute();
  data.second = now.second();

}

void sendData() {
  if (millis() - lastTimeTransmitter >= 2000) {
    vw_send((byte *)&data, sizeof(data));
    vw_wait_tx(); // Wait until the whole message is gone
    ledState = !ledState;
    digitalWrite(LED_BUILTIN, ledState);
    lastTimeTransmitter = millis();
  }
}

And for the receiver:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <VirtualWire.h>

const byte receivePin = 10;

unsigned long lastTimeLCD = 4000UL;
byte page = 1;
boolean ledState = false;

struct packet {
  float dewPoint, temperature, seaLevelPressure, airPressure, humidity;
  byte hour, minute, second, day, month;
  unsigned int year;
  boolean clockTicking;
};
typedef struct packet Packet;
Packet data;

LiquidCrystal_I2C LCD(0x3F, 16, 2);

byte degree[8] = {
  B00110,
  B01001,
  B01001,
  B00110,
  B00000,
  B00000,
  B00000,
  B00000,
};

void setup() {
  Serial.begin(9600);
  LCD.begin();
  LCD.clear();
  LCD.createChar(0, degree);
  // Initialise the IO and ISR
  vw_set_rx_pin(receivePin);
  vw_setup(500);   // Bits per sec
  vw_rx_start();       // Start the receiver PLL running
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  receiveData();
  writeOnLCD();
  Serial.println(data.temperature);
}

void receiveData() {
  byte buffer[sizeof(data)];
  byte bufferLength = sizeof(data);

  if (vw_have_message())  // Is there a packet for us?
  {
    vw_get_message(buffer, &bufferLength);
    vw_wait_rx();
    memcpy(&data, &buffer, bufferLength);
    ledState = !ledState;
    digitalWrite(LED_BUILTIN, ledState);
  }
}

void writeOnLCD() {
  /*
  if (!data.clockTicking) {
    LCD.print(F("RTC not ticking!"));
  }*/

  if (millis() - lastTimeLCD >= 4000) {
    LCD.clear();
    LCD.setCursor(0, 0);

    switch (page) {
      case 1:
        LCD.print(F("Temp: "));
        LCD.print(data.temperature);
        LCD.write(0);
        LCD.print(F("C"));
        LCD.setCursor(0, 1);
        LCD.print(F("Hum: "));
        LCD.print(data.humidity);
        LCD.print(F("%"));
        page = 2;
        break;

      case 2:
        LCD.print(F("Pr: "));
        LCD.print(data.airPressure);
        LCD.print(F("hPa"));
        LCD.setCursor(0, 1);
        LCD.print(F("Dew pt: "));
        LCD.print(data.dewPoint);
        LCD.write(0);
        LCD.print(F("C"));
        page = 3;
        break;

      case 3:
        LCD.print(F("Pressure on sea:"));
        LCD.setCursor(0, 1);
        LCD.print(data.seaLevelPressure);
        LCD.print(F("hPa"));
        page = 4;
        break;

      case 4:
        LCD.print(data.day);
        LCD.print(F("."));
        LCD.print(data.month);
        LCD.print(F("."));
        LCD.print(data.year);
        LCD.print(F("."));
        LCD.setCursor(0, 1);
        LCD.print(data.hour);
        LCD.print(F(":"));
        LCD.print(data.minute);
        page = 1;
        break;
    }
    lastTimeLCD = millis();
  }
}

Weather_Transmitter.ino (1.85 KB)

Weather_Receiver.ino (2.55 KB)

I found problem. Just by commenting out //boolean clockTicking; it solved my problem. Everything now works fine.

Your struct is 28 bytes when the clockTicking variable is added and VirtualWire can do a maximum of 27 bytes.
You can use 2000 for the bitrate, that works best for the cheap transmitter and receiver modules. Lowering the bitrate will not make it more reliable.

In setup() you could print the size of the struct. It is: sizeof(data)

Thanks!