2

I am building a weather station that contains a transmitter and a receiver and the data at the receiver's serial monitor shows either ovf, nan, 0.00 or some crazy number for the outside data (transmitter) so I'm hoping someone can take a quick look at the code and see if I missed something because I am out of ideas

The Receiver consists of an Arduino DUE, NRF24L01 transmitter, and a DHT 22 temp sensor The Transmitter consists of an Arduino NANO, NRF24L01 transmitter, and a DHT 22 temp sensor

Thank you for any help or advice

// Transmitter
#include "DHT.h"
#include <SPI.h>  
#include "RF24.h"

#define DHTPIN 4  
#define DHTTYPE DHT22 

RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};


struct package
{
  float temperature ;
  float humidity ;
};
typedef struct package Package;
Package data;

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
    Serial.begin(9600);
    delay(1000);
    dht.begin();
    myRadio.begin();  
    myRadio.setChannel(115); 
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate( RF24_250KBPS ) ; 
    myRadio.openWritingPipe( addresses[0]);
    delay(1000);
}



void loop()
{
  readSensor();
    myRadio.write(&data, sizeof(data)); 
  Serial.println(data.humidity);
  Serial.println(data.temperature);
  delay(1000);
}
void readSensor()
{
 data.humidity = dht.readHumidity();
 data.temperature = dht.readTemperature();
}
// Reciever
#include <SPI.h>  
#include "RF24.h" 
#include <DHT.h>

#define DHTPIN 53     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value

RF24 myRadio (51,49); // CE, CSN
struct package
{
  float temperature ;
  float humidity ;
};

byte addresses[][6] = {"0"}; 

typedef struct package Package;
Package data;

void setup() 
{
  Serial.begin(9600);
  dht.begin();
  delay(1000);
  myRadio.begin(); 
  myRadio.setChannel(115); 
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
}


void loop()  
{
  
  if ( myRadio.available()) 
  {
    while (myRadio.available())
    {
    myRadio.read( &data, sizeof(data) );
    }
    Serial.print("Outside Temperature: ");
    Serial.print(data.temperature);
    Serial.print(" C |");
    Serial.print("  Outside Humidity: ");
    Serial.print(data.humidity);
    Serial.println (" %");
  
  //Read data and store it to variables hum and temp
    hum = dht.readHumidity();
    temp= dht.readTemperature();
    //Print temp and humidity values to serial monitor
    Serial.print("Inside Temperature: ");
    Serial.print(temp);
    Serial.print(" C |");
    Serial.print("Inside Humidity: ");
    Serial.print(hum);
    Serial.println (" %");
    Serial.println("----------------------------------------------------");
    delay(2000); //Delay 2 sec.
    
  }
}
Serial Monitor
----------------------------------------------------
Outside Temperature: 0.00 C |  Outside Humidity: nan %
Inside Temperature: 20.50 C |Inside Humidity: 49.70 %
----------------------------------------------------
Outside Temperature: 0.00 C |  Outside Humidity: nan %
Inside Temperature: 20.50 C |Inside Humidity: 49.70 %
----------------------------------------------------
Outside Temperature: ovf C |  Outside Humidity: -8.00 %
Inside Temperature: 20.50 C |Inside Humidity: 49.80 %
----------------------------------------------------
Outside Temperature: 0.00 C |  Outside Humidity: ovf %
Inside Temperature: 20.50 C |Inside Humidity: 49.80 
2
  • 1
    Nothing wrong with your code. nRF24L01 consumed quite some power during transmission, the 3.3v regulators on your Due and Nano might not be able provide the surge current it needs, try to add a large cap (10uF or above) to both of nRF24L01 3.3v pins to see if it help, or use a 3.3v that can delivery 200mA+ current. – hcheung Dec 2 '20 at 1:04
  • Thank you!! It worked like a charm. – Bryan F Dec 2 '20 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.