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);
}
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.
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
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]
}
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.
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.
/* 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.