NRF24L01 And DHT22

Hey

I am working on a project where I measure the temperature wirelessly with the NRF24L01.
Have been looking all the time to look up tutorials but it does not work.

I currently have 2codes with no errors, but still he does not receive anything

Could someone help me?

thanks

Transmitter:

#include "DHT.h"
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>


#define DHTPIN 4  
#define DHTTYPE DHT22 

RF24 myRadio (7, 8);
byte addresses[][6] = {"00001"};
const int led_pin = 13;

struct package
{
  float temperature ;
  float humidity ;
};


typedef struct package Package;
Package data;

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
    Serial.begin(9600);
    pinMode(led_pin, OUTPUT);
    dht.begin();
    myRadio.begin();  
    myRadio.setChannel(115); 
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate( RF24_250KBPS ) ; 
    myRadio.openWritingPipe(00001);
    delay(1000);
}



void loop()
{
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  readSensor();
  Serial.println(data.humidity);
  Serial.println(data.temperature);
  myRadio.write(&data, sizeof(data)); 
  digitalWrite(led_pin, LOW);
  delay(1000);
}

void readSensor()
{
 data.humidity = dht.readHumidity();
 data.temperature = dht.readTemperature();
}

Receiver:

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

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

struct package
{
  float temperature ;
  float humidity ;
};

typedef struct package Package;
Package data;

void setup() {

  Serial.begin(9600);
  Serial.print("Starting Receiver \n");
  myRadio.begin();
  myRadio.openReadingPipe(0, 00001);      //open reading pipe 0 at address 00001 
  myRadio.setPALevel(RF24_PA_MAX);         //Set RF output to minimum
  myRadio.setDataRate(RF24_250KBPS);       //set datarate to 250kbps
  myRadio.setChannel(115);                 //set frequency to channel 100 
  myRadio.startListening();  
 }

void loop() {

  if (myRadio.available())                //check when received data available
  {
    
    myRadio.read(&data, sizeof(data));
    Serial.print(data.temperature);                //print data to serial monitor
    Serial.print(" C  ");
    Serial.print(data.humidity);                   //print data to serial monitor
    Serial.print(" %  ");

  }

}

Did you try the example that comes with the nRF24L01.h library? There is a nice example of two chips sending/receiving the time back and forth. Get that to work first, then work on incorporating your DHT sensor.

I had already done that.
I then added the dth22 and those 2codes are the result.

    myRadio.openWritingPipe(00001);

  myRadio.openReadingPipe(0, 00001);

What the heck is that supposed to do?

How do you guarantee that the memory from address 1 to 5 contains the same pattern on both Arduinos?

Normally it is this but that did not work either
I got this error:

C:\Documents\Arduino\libraries\RF24-master/RF24.h:350:8: note: initializing argument 2 of 'void RF24::openReadingPipe(uint8_t, uint64_t)'

void openReadingPipe(uint8_t number, uint64_t address);

^

  radio.openWritingPipe( addresses[0]);

  radio.openReadingPipe(1, addresses[0]);

And if correct code does not work, you change randomly addresses to integers?
That's a strange method for debug.

Have you verified the wiring with printDetails? (On both Arduinos)

  myRadio.setPALevel(RF24_PA_MAX);         //Set RF output to minimum

That's a strange comment and an bad setting for modules near to each other.

Have you tried Robin2's Simple nRF24L01+ 2.4GHz transceiver demo?

I thought he was asking the address there and if you look at the beginning of the code you see that there so if you put your address there yourself, I thought it did not make a difference.

It should be quite clear that the number 1 in octal (00001) is different from the address of an array filled with "00001".

There you have a point.

Unrelated to your problem:

struct package
{
  float temperature ;
  float humidity ;
};

typedef struct package Package;
Package data;

Could be simplified to

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

Have it adjusted but did not bring me further.

This is a picture what the Serial monitor is doing now: Imgur: The magic of the Internet

and this is now the 2 codes:

Transmitter:

#include "DHT.h"
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>


#define DHTPIN 4  
#define DHTTYPE DHT22 

RF24 myRadio (7, 12);
byte addresses[][6] = {"0"};
const int led_pin = 13;

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

DHT dht(DHTPIN, DHTTYPE);

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



void loop()
{
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  readSensor();
  Serial.println("humidity:"); 
  Serial.println(data.humidity);
  Serial.println("temperature:");  
  Serial.println(data.temperature);
  myRadio.write(&data, sizeof(data)); 
  digitalWrite(led_pin, LOW);
  delay(1000);
}

void readSensor()
{
 data.humidity = dht.readHumidity();
 data.temperature = dht.readTemperature();
}

Receiver:

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

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

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

void setup() {

  Serial.begin(9600);
  Serial.print("Starting Receiver \n");
  myRadio.begin();
  myRadio.openReadingPipe(1, addresses[0]);      //open reading pipe 0 at address 00001      //Set RF output to minimum
  myRadio.setDataRate(RF24_250KBPS);       //set datarate to 250kbps
  myRadio.setChannel(115);                 //set frequency to channel 100 
  myRadio.startListening();  
 }

void loop() {

  if (myRadio.available())                //check when received data available
  {
    
    myRadio.read(&data, sizeof(data));
    Serial.print(data.temperature);                //print data to serial monitor
    Serial.print(" C  ");
    Serial.print(data.humidity);                   //print data to serial monitor
    Serial.print(" %  ");
  }

}

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R

The connection work but i go a NAN spam

Picture: Imgur: The magic of the Internet

BartdePauw007:
The connection work but i go a NAN spam

Picture: https://imgur.com/a/XR21LVN

I don't understand - what connection?

I assume that is an image of text. Please don't post images of text, just copy and paste the text.

If it is not an image of text please make the image visible in your Post. See this Simple Image Guide

...R

I guess you did not read the second line of my comments in Reply #13.

Neither did you respond to my my first questiont!

...R