Skip to main content
Fixed code formatting, added tag.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

latelyLately I've received a DHT22 sensor. I've started to create a small temperature and humidity monitor station. One of the things I noticed was if you pulled out the sensor while in use, it displayed "nan". What I wanted to do was if the variable "temp" (for the temperature) equaled "nan", my LCD would display a message. But I keep getting a scope, conversion, and declaring errors. I've tried every variable and a lot of online forums, documentations, and the official Arduino reference site. My code looks like this: `#include <Adafruit_Sensor.h>

#include <DHT.h>

#include <LiquidCrystal.h> const int rs = 53, en = 51, d4 = 49, d5 = 52, d6 = 48, d7 = 47; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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

int chk; float hum;
float temp;

byte bigdot[8] = { B00000, B00000, B00000, B01110, B01110, B01110, B00000, B00000 };

byte circle[8] = { B00110, B01001, B01001, B00110, B00000, B00000, B00000, B00000 };

void setup() {

lcd.createChar(0, bigdot); lcd.createChar(1, circle); lcd.begin(16, 2); dht.begin(); do { lcd.setCursor(5,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); lcd.setCursor(7,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); lcd.setCursor(9,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); dht.readHumidity(); dht.readTemperature(); } while (hum > 90 || temp > 50.00); Serial.begin(9600);

}

void loop() { hum = dht.readHumidity(); temp = dht.readTemperature(); lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(temp); lcd.write(byte(1)); lcd.print("C");

lcd.setCursor(0,1);
lcd.print("RH:   ");
lcd.print(hum);
lcd.print("%");

if (temp == a) {
  lcd.clear();
  lcd.home();
  lcd.print("Whoops! An");
  lcd.setCursor(0,1);
  lcd.print("error occured!");
};
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <LiquidCrystal.h>

const int rs = 53, en = 51, d4 = 49, d5 = 52, d6 = 48, d7 = 47;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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

int chk;
float hum;  
float temp; 

byte bigdot[8] = {
  B00000,
  B00000,
  B00000,
  B01110,
  B01110,
  B01110,
  B00000,
  B00000
};

byte circle[8] = {
  B00110,
  B01001,
  B01001,
  B00110,
  B00000,
  B00000,
  B00000,
  B00000
};

void setup() {
  lcd.createChar(0, bigdot);
  lcd.createChar(1, circle);
  lcd.begin(16, 2);
  dht.begin();
  do {
  lcd.setCursor(5,1);
  lcd.write(byte(2));
  lcd.setCursor(4,0);
  lcd.print("Loading");
  delay(500);
  lcd.clear();
  lcd.setCursor(7,1);
  lcd.write(byte(2));
  lcd.setCursor(4,0);
  lcd.print("Loading");
  delay(500);
  lcd.clear();
  lcd.setCursor(9,1);
  lcd.write(byte(2));
  lcd.setCursor(4,0);
  lcd.print("Loading");
  delay(500);
  lcd.clear();
  dht.readHumidity();
  dht.readTemperature();
  } while (hum > 90 || temp > 50.00);
  Serial.begin(9600);
  
  
}

void loop() {
    hum = dht.readHumidity();
    temp = dht.readTemperature();
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Temp: ");
    lcd.print(temp);
    lcd.write(byte(1));
    lcd.print("C");
    
    lcd.setCursor(0,1);
    lcd.print("RH:   ");
    lcd.print(hum);
    lcd.print("%");
    
    if (temp == a) {
      lcd.clear();
      lcd.home();
      lcd.print("Whoops! An");
      lcd.setCursor(0,1);
      lcd.print("error occured!");
    };
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.println(" Celsius");
    delay(2000); //Delay 2 sec.
 }

}` Thanks Thanks in advance!

lately I've received a DHT22 sensor. I've started to create a small temperature and humidity monitor station. One of the things I noticed was if you pulled out the sensor while in use, it displayed "nan". What I wanted to do was if the variable "temp" (for the temperature) equaled "nan", my LCD would display a message. But I keep getting a scope, conversion, and declaring errors. I've tried every variable and a lot of online forums, documentations, and the official Arduino reference site. My code looks like this: `#include <Adafruit_Sensor.h>

#include <DHT.h>

#include <LiquidCrystal.h> const int rs = 53, en = 51, d4 = 49, d5 = 52, d6 = 48, d7 = 47; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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

int chk; float hum;
float temp;

byte bigdot[8] = { B00000, B00000, B00000, B01110, B01110, B01110, B00000, B00000 };

byte circle[8] = { B00110, B01001, B01001, B00110, B00000, B00000, B00000, B00000 };

void setup() {

lcd.createChar(0, bigdot); lcd.createChar(1, circle); lcd.begin(16, 2); dht.begin(); do { lcd.setCursor(5,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); lcd.setCursor(7,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); lcd.setCursor(9,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); dht.readHumidity(); dht.readTemperature(); } while (hum > 90 || temp > 50.00); Serial.begin(9600);

}

void loop() { hum = dht.readHumidity(); temp = dht.readTemperature(); lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(temp); lcd.write(byte(1)); lcd.print("C");

lcd.setCursor(0,1);
lcd.print("RH:   ");
lcd.print(hum);
lcd.print("%");

if (temp == a) {
  lcd.clear();
  lcd.home();
  lcd.print("Whoops! An");
  lcd.setCursor(0,1);
  lcd.print("error occured!");
};
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.

}` Thanks in advance!

Lately I've received a DHT22 sensor. I've started to create a small temperature and humidity monitor station. One of the things I noticed was if you pulled out the sensor while in use, it displayed "nan". What I wanted to do was if the variable "temp" (for the temperature) equaled "nan", my LCD would display a message. But I keep getting a scope, conversion, and declaring errors. I've tried every variable and a lot of online forums, documentations, and the official Arduino reference site. My code looks like this:

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <LiquidCrystal.h>

const int rs = 53, en = 51, d4 = 49, d5 = 52, d6 = 48, d7 = 47;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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

int chk;
float hum;  
float temp; 

byte bigdot[8] = {
  B00000,
  B00000,
  B00000,
  B01110,
  B01110,
  B01110,
  B00000,
  B00000
};

byte circle[8] = {
  B00110,
  B01001,
  B01001,
  B00110,
  B00000,
  B00000,
  B00000,
  B00000
};

void setup() {
  lcd.createChar(0, bigdot);
  lcd.createChar(1, circle);
  lcd.begin(16, 2);
  dht.begin();
  do {
  lcd.setCursor(5,1);
  lcd.write(byte(2));
  lcd.setCursor(4,0);
  lcd.print("Loading");
  delay(500);
  lcd.clear();
  lcd.setCursor(7,1);
  lcd.write(byte(2));
  lcd.setCursor(4,0);
  lcd.print("Loading");
  delay(500);
  lcd.clear();
  lcd.setCursor(9,1);
  lcd.write(byte(2));
  lcd.setCursor(4,0);
  lcd.print("Loading");
  delay(500);
  lcd.clear();
  dht.readHumidity();
  dht.readTemperature();
  } while (hum > 90 || temp > 50.00);
  Serial.begin(9600);
  
  
}

void loop() {
    hum = dht.readHumidity();
    temp = dht.readTemperature();
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Temp: ");
    lcd.print(temp);
    lcd.write(byte(1));
    lcd.print("C");
    
    lcd.setCursor(0,1);
    lcd.print("RH:   ");
    lcd.print(hum);
    lcd.print("%");
    
    if (temp == a) {
      lcd.clear();
      lcd.home();
      lcd.print("Whoops! An");
      lcd.setCursor(0,1);
      lcd.print("error occured!");
    };
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.println(" Celsius");
    delay(2000); //Delay 2 sec.
 }

Thanks in advance!

Source Link

Comparing a text string to text output (DHT22)

lately I've received a DHT22 sensor. I've started to create a small temperature and humidity monitor station. One of the things I noticed was if you pulled out the sensor while in use, it displayed "nan". What I wanted to do was if the variable "temp" (for the temperature) equaled "nan", my LCD would display a message. But I keep getting a scope, conversion, and declaring errors. I've tried every variable and a lot of online forums, documentations, and the official Arduino reference site. My code looks like this: `#include <Adafruit_Sensor.h>

#include <DHT.h>

#include <LiquidCrystal.h> const int rs = 53, en = 51, d4 = 49, d5 = 52, d6 = 48, d7 = 47; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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

int chk; float hum;
float temp;

byte bigdot[8] = { B00000, B00000, B00000, B01110, B01110, B01110, B00000, B00000 };

byte circle[8] = { B00110, B01001, B01001, B00110, B00000, B00000, B00000, B00000 };

void setup() {

lcd.createChar(0, bigdot); lcd.createChar(1, circle); lcd.begin(16, 2); dht.begin(); do { lcd.setCursor(5,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); lcd.setCursor(7,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); lcd.setCursor(9,1); lcd.write(byte(2)); lcd.setCursor(4,0); lcd.print("Loading"); delay(500); lcd.clear(); dht.readHumidity(); dht.readTemperature(); } while (hum > 90 || temp > 50.00); Serial.begin(9600);

}

void loop() { hum = dht.readHumidity(); temp = dht.readTemperature(); lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(temp); lcd.write(byte(1)); lcd.print("C");

lcd.setCursor(0,1);
lcd.print("RH:   ");
lcd.print(hum);
lcd.print("%");

if (temp == a) {
  lcd.clear();
  lcd.home();
  lcd.print("Whoops! An");
  lcd.setCursor(0,1);
  lcd.print("error occured!");
};
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.

}` Thanks in advance!