Problems With Isnan And Serial - Arduino Forum
Maybe your like
Hello.
I am new to Arduino, and I have been trying to modify the DH11 sketch to suit my LCD screen. Everything is working perfectly, but I have a problems with the isnan and serial.
As seen on the code below, I want the serial to output a error message when the sensor is not present or working. I have been searching around for "isnan" but there is little information. When I unplug the sensor, is shows the value 0 at LCD, and nothing in Serial.
Can I also display the message on the LCD with lcd.print("Message..");??
Last question, what is the difference between print and println?
if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } else...https://gist.github.com/amfgames/14237a35ed17e4caef5721b01aab2e0f
Thanks! ![]()
Are you sure you are getting a NaN from the sensor? That is pretty arcane.
You can try if ((h==h) ==0) since NaN's cannot even compare equal to themselves.
Sweetwater April 3, 2017, 11:05pm 3I tried
// Check if any reads failed and exit early (to try again). if (h==0) { Serial.println("Failed to read from DHT sensor!"); return; }And this worked perfectly. Could you explain to me why the DHTester example in the library, uses the code I mentioned and does indeed report back in serial? Is it because it uses the float datatype?
Code for the example: https://gist.github.com/amfgames/7e6b2673bf45d5c84d016b37ec5e10da
Thanks again!
KeithRB April 3, 2017, 11:30pm 4If h is an integral type, it cannot be a Nan, which is strictly a floating point thing.
sterretje April 4, 2017, 3:53am 5Please edit your posts and replace "quote" by "code" to post code properly ![]()
sterretje: Please edit your posts and replace "quote" by "code" to post code properly
Great! Thanks for the tip! ![]()
Sweetwater: Hello.
I am new to Arduino, and I have been trying to modify the DH11 sketch to suit my LCD screen. Everything is working perfectly, but I have a problems with the isnan and serial.
As seen on the code below, I want the serial to output a error message when the sensor is not present or working. I have been searching around for "isnan" but there is little information.
When using floating pointg numbers and formatting the result into ASCII and you get 'float' formatted to "isnan", then the meaning is: "is not a number". As simple as that.
Typically this isnan value is the result of DOING A SEVERE MISTAKE WITH FLOATING POINT MATH!
Especially after doing a "floating point math division by zero, the result will be nan (not a number).
And the difference between print() and println (short for "print line") is this:
The print line println() command will add two extra characters for two functions that could be executed by electric typewriters in former times:
- carriage return (CR, ASCII-code 13)
- line feed (LF, ASII -code 10)
On old electrical typewriters the "carriage return" and "linefeed" control characters would do mechanical functions.
But when used on the serial monitor, the same control codes will simply place the writing mark (cursor or caret) at the left-most writing position in the next line. When used in the last line of the serial monitor, the previous contents in the serial monitor will scroll one line up and then start a new line with the cursor in the left-most writing position.
Related topics
| Topic | Replies | Views | Activity |
|---|---|---|---|
| DHT11 sensor reading NAN Sensors | 7 | 432 | September 10, 2024 |
| DHT 11 not working, need help Programming | 8 | 639 | February 12, 2025 |
| DHT11 Temperature and Humidity Sensor not outputting values General Guidance | 19 | 1021 | January 26, 2025 |
| Why won't my DHT sensor work? Help please! Sensors | 21 | 2868 | November 29, 2023 |
| This noobie needs help I just wanna know how it works General Guidance | 15 | 222 | January 14, 2026 |
Tag » Arduino Isnan(h)
-
Isnan() | Cộng đồng Arduino Việt Nam
-
Using Isnan - Programming Questions - Arduino Forum
-
Simple Code Question - Programming Questions - Arduino Forum
-
Capteur Humidité Avec Contacteur - Français - Arduino Forum
-
Writing Program For NaN Condition - Arduino Forum
-
Error: 'isnan' Was Not Declared In The Scope - Arduino Forum
-
Arduino: Read Temperature From DHT11 Module - C# Corner
-
[Solved] Error: 'isnan' Was Not Declared In This Scope Isnan(n)
-
Isnan - C++ Reference
-
Phần 1: Arduino Căn Bản Với Esp8266 → Nhiệt độ Và độ ẩm DHT
-
Arduino With IstSOS — IstSOS 2.4.0-RC4 Documentation
-
DHT11/DHT22 Temperature And Humidity Sensor Using Arduino IDE