Hi all,
I have tried for the past 3 days to send the temperature and humidity reading using a DHT11 from one arduino to another using the Nrf24l01 modules. My programming skills are limited but I can understand basic programs. I have tried the example libraries ("getting started") and the modules seem to work fine but when I use this code (below) I get a "failed, response timed out" in the Serial monitor. I am sure there is a mistake in the programming but I can not see it, I have searched google but I cant find what I want or understand so any help would be appreciated. I have also put a 10uf capacitor on both modules without sucess.
transmitter:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(9, 10);
const uint64_t pipes[1] = {0xF0F0F0F0E1LL};
typedef struct {
int A;
int B;
}
M_d;
M_d myData;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, pipes[0]);
radio.startListening();
}
void loop(void)
{
unsigned long started_waiting_at = millis();
bool timeout = false;
while ( ! radio.available() && ! timeout )
if (millis() - started_waiting_at > 250 )
timeout = true;
if ( timeout )
{
Serial.println("Failed, response timed out.");
}
else
{
radio.read( &myData, sizeof(myData) );
}
// end of radio stuff
delay(1000);
// serial print received data
Serial.print("Humidity % = ");
Serial.println(myData.A);
Serial.print("Temperature oC = ");
Serial.println(myData.B);
// end of serial printing
}
Receiver:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 4
typedef struct {
float A;
float B;
}
M_d;
M_d myData;
RF24 radio(9, 10);
const uint64_t pipes[1] = {0xF0F0F0F0E1LL};
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipes[0]);
radio.stopListening();
}
void loop(void)
{
// we need data to sent...
Serial.println("\n");
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case 0: Serial.println("OK"); break;
case -1: Serial.println("Checksum error"); break;
case -2: Serial.println("Time out error"); break;
default: Serial.println("Unknown error"); break;
}
myData.A = ((float)DHT11.humidity, 2);
myData.B = ((float)DHT11.temperature, 2);
Serial.println((float)DHT11.humidity, 2);
Serial.println((float)DHT11.temperature, 2);
delay(1000);
// end of analog reading
// radio stuff
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.write( &myData, sizeof(myData) );
}
}
// end of radio stuff
}
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}
// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}