sending sensor data with nrf24l01 to app

hi guys. this is a project for sending sensor data with nrf24l01 to app.

the link of project:

....................................................................................

my problem is that when i upload below code, arduino get me this ERROR:

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Webhouse\Desktop\New folder\Sendsensordata_ar_nrf_dht22+LED\sketch_dec10a\sketch_dec10a.ino: In function 'void loop()':

sketch_dec10a:41:13: error: 'h' was not declared in this scope

if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).

         ^

sketch_dec10a:41:25: error: 't' was not declared in this scope

if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).

                     ^

sketch_dec10a:45:49: error: 't' was not declared in this scope

Serial.print(" Temperature: ");  Serial.print(t);  Serial.println("°C ");

                                             ^

exit status 1
'h' was not declared in this scope

how can i fix this guys?
....................................................................................

the full code:

/* Sending Sensor Data to Nordic BLE android app  by CircuitDigest(www.circuitdigest.com)
works with nRF24L01. and the works for Nordic's
It reads temperature from a DHT11 and sends it via BTLE.
Works with Nordic Semiconductor apps such as
"nRF Connect for Mobile" and "nRF Temp 2.0 for BLE"
Pin Mapping:
GND -> GND on the Arduino
VCC -> 3.3v on the Arduino
CE -> PIN 9 on the Arduino
CSN -> PIN 10 on the Arduino
SCK -> PIN 13 on the Arduino Uno
MOSI -> PIN 11 on the Arduino Uno
MISO -> PIN 12 on the Arduino Uno
IRQ -> not used
*/

#include <SPI.h>
#include <RF24.h>
#include <BTLE.h>
#include <DHT.h>                                                            // dht11 temperature and humidity sensor library

#define DHTPIN 4                                                           // what digital pin we're connected to
#define DHTTYPE DHT11                                                       // select dht type as DHT 11 or DHT22
DHT dht(DHTPIN, DHTTYPE);

RF24 radio(9, 10); // CE, CSN
BTLE btle(&radio);

void setup() {
Serial.begin(9600);
delay(1000);
Serial.print("BLE and DHT Starting... ");
Serial.println("Send Temperature Data over BTLE");
dht.begin();   // initialise DHT11 sensor
btle.begin("CD Temp");    // 8 chars max
Serial.println("Successfully Started");
}

void loop() {                                              
float temp = dht.readTemperature();   //read temperature data
[color=red]if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).
  Serial.println(F("Failed to read from DHT sensor!"));
  return;[/color]
}
Serial.print(" Temperature: ");  Serial.print(t);  Serial.println("°C ");
nrf_service_data buf;
buf.service_uuid = NRF_TEMPERATURE_SERVICE_UUID;
buf.value = BTLE::to_nRF_Float(temp);

if (!btle.advertise(0x16, &buf, sizeof(buf))) {
 Serial.println("BTLE advertisement failed..!");
}
btle.hopChannel(); 
delay(2000);
}

Please use code tags when posting code.

For the code to work at all, the variables h and t need to be defined, and set to valid numbers. Since those are probably humidity and temperature, you may have the wrong DHT library installed.

Get the sensor working using the example code, before adding anything else.

hi guys. this is a project for sending sensor data with nrf24l01 to app.

the link of project:

....................................................................................

my problem is that when i upload below code, arduino get me this ERROR:

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Webhouse\Desktop\New folder\Sendsensordata_ar_nrf_dht22+LED\sketch_dec10a\sketch_dec10a.ino: In function 'void loop()':

sketch_dec10a:41:13: error: 'h' was not declared in this scope

 if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).

           ^

sketch_dec10a:41:25: error: 't' was not declared in this scope

 if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).

                       ^

sketch_dec10a:45:49: error: 't' was not declared in this scope

 Serial.print(" Temperature: ");  Serial.print(t);  Serial.println("°C ");

                                               ^

exit status 1
'h' was not declared in this scope

how can i fix this guys?
....................................................................................

the full code:

/* Sending Sensor Data to Nordic BLE android app  by CircuitDigest(www.circuitdigest.com)
works with nRF24L01. and the works for Nordic's
 It reads temperature from a DHT11 and sends it via BTLE.
 Works with Nordic Semiconductor apps such as
 "nRF Connect for Mobile" and "nRF Temp 2.0 for BLE"
 Pin Mapping:
GND -> GND on the Arduino
VCC -> 3.3v on the Arduino
CE -> PIN 9 on the Arduino
CSN -> PIN 10 on the Arduino
SCK -> PIN 13 on the Arduino Uno
MOSI -> PIN 11 on the Arduino Uno
MISO -> PIN 12 on the Arduino Uno
IRQ -> not used
*/

#include <SPI.h>
#include <RF24.h>
#include <BTLE.h>
#include <DHT.h>                                                            // dht11 temperature and humidity sensor library

#define DHTPIN 4                                                           // what digital pin we're connected to
#define DHTTYPE DHT11                                                       // select dht type as DHT 11 or DHT22
DHT dht(DHTPIN, DHTTYPE);

RF24 radio(9, 10); // CE, CSN
BTLE btle(&radio);

void setup() {
Serial.begin(9600);
delay(1000);
Serial.print("BLE and DHT Starting... ");
Serial.println("Send Temperature Data over BTLE");
dht.begin();   // initialise DHT11 sensor
btle.begin("CD Temp");    // 8 chars max
Serial.println("Successfully Started");
}

void loop() {                                              
float temp = dht.readTemperature();   //read temperature data
if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).
   Serial.println(F("Failed to read from DHT sensor!"));
   return;
}
Serial.print(" Temperature: ");  Serial.print(t);  Serial.println("°C ");
nrf_service_data buf;
buf.service_uuid = NRF_TEMPERATURE_SERVICE_UUID;
buf.value = BTLE::to_nRF_Float(temp);

if (!btle.advertise(0x16, &buf, sizeof(buf))) {
  Serial.println("BTLE advertisement failed..!");
}
btle.hopChannel(); 
delay(2000);
}

Read "How to use this Forum", especially #7, how to attach code in a way that makes it nicely readable by the helpers.

  if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).

                        ^

sketch_dec10a:45:49: error: 't' was not declared in this scope

  Serial.print(" Temperature: ");  Serial.print(t);  Serial.println("°C ");

                                                ^

exit status 1
'h' was not declared in this scope

Read the error message and declare "h" and "t".

sorry i fix the message now.

they mean humidity and temperature but i donot know what elements is h and t in this code?.

my library attached. can u say what should i do for fixing h , t:

DHT.zip (18 KB)

Fine! It's appreciated!

What is thus code:

void loop() {                                              
float temp = dht.readTemperature();   //read temperature data
[colorFine! It's appreciated!

What is thus code:
[code]void loop() {                                              
float temp = dht.readTemperature();   //read temperature data
[color=red]if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).
   Serial.println(F("Failed to read from DHT sensor!"));
   return;[/color]
}

What is the beginning this line supposed to do:

[color=red]if (isnan(h) || isnan(t)) {

What's the doing there?

Get the temperature and humidity values from your library and send those instead.

Start by getting the example in the library to work, and understand how it works.

The line that is causing the error

if (isnan(h) || isnan(t)) {

suggests to me that there is some stuff missing from your program - the stuff that creates the h and the t variables and puts values into them.

I was not aware that you could use an nRF24 for BLE. I must investigate that further when I have time. I will bookmark your CircuitDigest link.

I just noticed this in the BTLE.h Github page which leads me to think this is not a very practical BLE system.

The nRF24L01+ can only send and receive up to 32 bytes. For advertising messages, this means 32 - 6 (MAC) - 2 (header) - 3 (CRC) = 21 bytes of payload can be sent and received at most. Consequently, a full iBeacon message won't fit in there and will never be received. Also, if you're sending advertisements from your phone, the device name alone will take up a significant chunk of that budget.

...R

thank you for helping me so much!

i add these 3 lines in my void loop from library:

 float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

but when i upload it, i see in my serial monitor many of this message:

Failed to read from DHT sensor!

where is the problem?

Does the example from the library work?

the example worked but my problem not solved yet. (serial monitor show temperatur and humidity data)

the example in readme of DHT library:

#include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  delay(2000);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}
```

Please post ALL of the latest code, using code tags, and a wiring diagram.

You seem to have double posted - which just wastes everyone's time. I have already responded in your other Thread.

I am suggesting to the Moderator to merge the two Threads

...R

Thanks for notifying the moderators of this @Robin2!

I've merged your other cross-post @hadimargo.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

this is the project i want to do it:

project

this is the images of project:

this is the projcet code:

/* Sending Sensor Data to Nordic BLE android app  by CircuitDigest(www.circuitdigest.com)
  works with nRF24L01. and the works for Nordic's
   It reads temperature from a DHT11 and sends it via BTLE.
   Works with Nordic Semiconductor apps such as
   "nRF Connect for Mobile" and "nRF Temp 2.0 for BLE"
   Pin Mapping:
  GND -> GND on the Arduino
  VCC -> 3.3v on the Arduino
  CE -> PIN 9 on the Arduino
  CSN -> PIN 10 on the Arduino
  SCK -> PIN 13 on the Arduino Uno
  MOSI -> PIN 11 on the Arduino Uno
  MISO -> PIN 12 on the Arduino Uno
  IRQ -> not used
*/

#include <SPI.h>
#include <RF24.h>
#include <BTLE.h>
#include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

RF24 radio(9, 10); // CE, CSN
BTLE btle(&radio);

void setup() {
  Serial.begin(9600);
  delay(1000);
  Serial.print("BLE and DHT Starting... ");
  Serial.println("Send Temperature Data over BTLE");
  dht.begin();   // initialise DHT11 sensor
  btle.begin("CD Temp");    // 8 chars max
  Serial.println("Successfully Started");
}

void loop() { 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);                                             
  float temp = dht.readTemperature();   //read temperature data
  if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.print(" Temperature: ");  Serial.print(t);  Serial.println("°C ");
  nrf_service_data buf;
  buf.service_uuid = NRF_TEMPERATURE_SERVICE_UUID;
  buf.value = BTLE::to_nRF_Float(temp);

  if (!btle.advertise(0x16, &buf, sizeof(buf))) {
    Serial.println("BTLE advertisement failed..!");
  }
  btle.hopChannel(); 
  delay(2000);
}

and this is the problem 1 (result):

the second problem is that the application nRF Temp 2 cannot detect the nrf module and i cannot see the result in application.

hadimargo:
]and this is the problem 1 (result):

Don't post pictures of text - they are quite unreadable. Just copy and paste text.

...R