Need help with this project

Hi
Ive written this code using snippetss of other to build a wireless humidity/temperature monitor. Ive tried my best but could not get it to fully work. Please could you check this and correct. You will have the transmitter piece which had the DHT11 (no pcb on this) which is connected to an nano board and an NRF24L01 board. The receiver end will have another NRF24LO1 board, nano board and be connected to either to a laptop to view on serial monitor but also on an LCD display. Thanks for your time

TRANSMITTER CODE

#include <dht.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <printf.h>

dht DHT;
#define DHT11_PIN 7

RF24 radio(2,3); // CE, CSN

const byte address[5] = “00001”;
struct package
{float temperature = 0;
};
typedef struct package Package;
Package data;

void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}

void loop() {
data= dht.readTemperature(DHT11_PIN);
radio.write(&data, sizeof(data));
delay(1000);
}

RECEIVER CODE:

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

RF24 radio(2,3); // CE, CSN

const byte address[5] = “00001”;

typedef struct package Package;
Package data;

void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}

void loop() {
if (radio.available()) {
radio.read(&data, sizeof(data));
Serial.println(data.temperature);
Serial.print(“C”);
}
}

I doubt that anyone here will "correct" your code for you. We will help you to get it to work, though. First describe what the code is actually doing and how that differs from what you want.

Please read the "how to use this forum-please read" stickies to see how to properly post code.

Try debugging it yourself - put some print statements at strategic points , print out variables and try and work out what is going wrong by looking at the results. Are the variables as expected , is the sketch running through ok ?

Ive tried my best but could not get it to fully work.

I can't really debug your code if I don't know what it's doing that's different to what it should be doing.

However:

If the root problem is that sometimes data transmission is unreliable, that the bytes you send aren't always the bytes you get, then this is a pretty general problem in comms. There are a squillion solutions. All of them involve sending more than just the bare two bytes of data in a float. You send some bytes that contain the data you need, but that also contain some extra stuff allowing the receiver to confirm that the message was received correctly.

For instance: transmit an asterisk and the two bytes of data three times, followed by a trailing hash. Furthermore, only transmit this data at most once a second.

The receiver works by reading transmissions into a buffer with a (say) 800ms timeout. This hopefully means that rubbish gets discarded, that when you read a message you are definitely getting the whole message from the starting point. You check that the message you actually got was the full 10 bytes long. You then check that the asterisks are where they are supposed to be (bytes 0, 3, 6) and there's a trailing hash at position 9. You then check that the three two-byte quantities all match. Then you check that that two-byte quantity is a valid floating-point number. Then you check that the number you got is a sensible-looking value. Once that is all done, you can be reasonably confident that the transmission was successful.

Of course, this is a very, very simple protocol as these things go. More advanced things use number theory and cryptography.

TL:DR; yes, that's right: radio transmissions can glitch, and your code must deal with potential transmission errors.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What does you code do and what doesn't it do?

Have you tried making you code in pieces and checking that those pieces work BEFORE pasting them together?

Thanks.. Tom... :slight_smile: