Arduino Uno, DS18B20 and NRF24l01

Hey guys. I'm doing a hobby project and can't seem to get it working. Aim of the project is to transmit temperature values from a DS18B20 using an Arduino Uno and NRF24l01. The transmitter part should power on once every minute, transmit temperature values. The receiver is an Arduino Uno with NRF24l01. Problem is that serial monitor on the transmitter displays the temperature values perfectly. The receiver however shows radio not found. Both the radios work perfectly as i tested them using the example joystick code.

TX part

#include <RF24Network.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define ONE_WIRE_BUS 2
#define CE_PIN 9
#define CSN_PIN 10
RF24 radio(9,10);
RF24Network network(radio);

const uint16_t this_node = 1;
const uint16_t other_node = 0;
const unsigned long interval = 2000; //ms
unsigned long last_sent;
unsigned long packets_sent;
const uint64_t pipe = 0xE8E8F0F0E1LL;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
Serial.println("Dallas Temperature IC Control Library Demo");
network.begin(80, this_node);
sensors.begin();
}

void loop(void)
{
Serial.print(" Requesting temperatures...");
Serial.println("DONE");
float currentTemp;
currentTemp = sensors.getTempCByIndex(0);
Serial.print("Temperature for Device 1 is: ");
// radio.write( &currentTemp, sizeof(currentTemp) );
RF24NetworkHeader header(/to node/ other_node);
bool ok = network.write(header,&currentTemp,sizeof(currentTemp));
Serial.print(currentTemp);
uint16_t sensorValue = currentTemp;
}

RX part

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24Network.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
#define CE_PIN 9
#define CSN_PIN 10
RF24 radio(9,10); //NRF24L01 CE to pin9, CSN to pin10 on Uno
RF24Network network(radio);

const uint64_t pipe = 0xE8E8F0F0E1LL;
const uint16_t this_node = 1;
const uint16_t other_node = 0;

void setup()
{
Serial.begin(9600);
//delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
network.begin( 80, this_node);
radio.openReadingPipe(1,pipe);
radio.startListening();
}

void loop()
{
//network.update();
float currentTemp;
if ( network.available() )
{
bool done = false;
while (!done)
{
//if ( radio.available() )
RF24NetworkHeader header;
network.read( header,&currentTemp,sizeof(currentTemp) );
//radio.read( &currentTemp, sizeof(currentTemp) );
Serial.print("Temperature is ");
Serial.print(currentTemp);
}
}
else
{
Serial.print("radio not available");
}
}

The following websites were used to connect the circuit

http://www.hobbytronics.co.uk/ds18b20-arduino
https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

Can anyone point out the mistake i'm making and fix it please?

Why are you including the DallasTemperature and OneWire libraries on the receiver? You don't use them.

float currentTemp;
 currentTemp = sensors.getTempCByIndex(0);

bool ok = network.write(header,&currentTemp,sizeof(currentTemp));

Consistency is good. There is no reason to declare a local variable on one line, with no initial value, and then immediately assign it a value on the next line. One line, as in the second bit of code, if better.

uint16_t sensorValue = currentTemp;

Useless. The variable immediately goes out of scope.

 Serial.print(" Requesting temperatures...");
 Serial.println("DONE");

Done with what? Not with getting the temperature.

And, how many temperatures are you requesting?

Hi Paul, Thanks for replying. Yeah I will get rid of the useless header files.
Also, declared the local variable and assigned it to the sensor value in a single line.
Removed the line "uint16_t sensorValue = currentTemp;"
The last two serial print lines were in the example code my friend. I just didn't delete them as I was kinda trying to fix the transmission and reception issues. I agree that the code has a lot of crap but I just ignored them as it didn't affect the output. I'm still not able to fix the problem :confused:

The receiver however shows radio not found.

That sounds like a hardware/wiring issue, not a programming issue.

PaulS:
That sounds like a hardware/wiring issue, not a programming issue.

Well, that's what I thought but the demo code works just fine. The receiver receives junk values and shows radio not found only when the transmitter is disconnected.

If the 2 radios are too close together, I've had problems with TX overpowering and swamping RX.
Try lowering TX power like this:

void setup()
 {
 Serial.begin(9600);
 radio.begin();
 radio.openWritingPipe(pipe);
 radio.setPALevel( RF24_PA_MIN );
 Serial.println("Dallas Temperature IC Control Library Demo");
 network.begin(80, this_node);
 sensors.begin();
 }

Worked for me.

jcallen:
If the 2 radios are too close together, I've had problems with TX overpowering and swamping RX.
Try lowering TX power like this:

void setup()

{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
radio.setPALevel( RF24_PA_MIN );
Serial.println("Dallas Temperature IC Control Library Demo");
network.begin(80, this_node);
sensors.begin();
}




Worked for me.

Hello Jcallen. Thanks for the reply buddy. That doesn't work either. Serial monitor of the receiver still says no radio found

Hi,

The receiver receives junk values and shows radio not found only when the transmitter is disconnected.

Ofcourse it does, what do you expect, the TX is turned OFF, so the Rx cannot see it.

The NRF24l01 system, is not just a TX and RX, it is a communication system, the two units talk to each other even when there is no data to be sent.

How are you turnng the TX end OFF?
If you are disconnecting power to it, when you reconnect, it will not initialise, it needs the setup() instructions to tell it how to perform.

radio.openWritingPipe(pipe);
and
network.begin(80, this_node);

Need to be run again to intialise it.

Tom.... :slight_smile:

TomGeorge:
The NRF24l01 system, is not just a TX and RX, it is a communication system, the two units talk to each other even when there is no data to be sent.

No, they do not.

There is communication beside the framed datagrams, but only directly caused by/connected to user initiated sends.

TomGeorge:
Hi,
Ofcourse it does, what do you expect, the TX is turned OFF, so the Rx cannot see it.

The NRF24l01 system, is not just a TX and RX, it is a communication system, the two units talk to each other even when there is no data to be sent.

How are you turnng the TX end OFF?
If you are disconnecting power to it, when you reconnect, it will not initialise, it needs the setup() instructions to tell it how to perform.

radio.openWritingPipe(pipe);
and
network.begin(80, this_node);

Need to be run again to intialise it.

Tom.... :slight_smile:

Well, I tried it buddy. Didn't work out. Feels like I will never get it to work

You are using the same addresses for both RX and TX, try to exchange one side.

 const uint16_t this_node = 1;
 const uint16_t other_node = 0;


 const uint16_t this_node = 1;
 const uint16_t other_node = 0;