DHT11 using individual temp/humidity

I'm interested in creating a program that will use temperature and humidity as separate data with the DHT11.

I'm try to start by getting an LED to turn off when temp is 40 degrees C. But i can't seem to separate temp/humidity data, even though the sensor is printing it.

How can i reference humidity data and temp data separately so they can each control different functions.

Attached is my sketch. Notice a working model in the comments. It works as one single analog sensor output, but no way of separating data without errors.

sketch_aug14a.ino (1.15 KB)

if (Serial.read("Temperature" == 40);

Where to start?

Please, please just POST code, don't attach it.

Does this help at all?

What are you trying to do here?

if (Serial.read("Temperature" == 40);

It makes no sense, I don't think it will even compile.

It works as one single analog sensor output

I think the "D" in "DHT11" stands for "digital".

#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

int led = 13;

void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor
pinMode(led, OUTPUT);

}//end "setup()"

void loop(){
//Start of Program

int sensorValue = analogRead(A0);

if (Serial.read("Temperature" == 40);
{
digitalWrite(led, LOW);
}
else
{
digitalWrite(led, HIGH);
}
//with this configuaration, the light remains on, which means
//in my room with C.H. =66%, Temp=22, the sensor is operating at a level
//sensorValue >= 500.
//Also stays on with sensorValue <800
//Also
/*if (sensorValue < 500)
{
digitalWrite(led, LOW);
}
/else
{
digitalWrite(led, HIGH);
}
/

DHT.read11(dht_apin);

Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop()

Where did you get that code from?
It's nonsense.

Please, when posting code, get into the habit of using [code][/code] tags

aarg:
What are you trying to do here?

if (Serial.read("Temperature" == 40);

It makes no sense, I don't think it will even compile.

The sensor is able to distinguish between humidity and temperature, as I can have both values print on the serial monitor. I was trying to get the board to do something when temperature read 40.

Have you tried using any of the available DHT11 example code?

I was trying to get the board to do something when temperature read 40.

You have never, ever seen an "if" or a "print" written like that.
Lose the semicolon for a start.
Then lose the comparison.

Chill_Polins:
The sensor is able to distinguish between humidity and temperature, as I can have both values print on the serial monitor. I was trying to get the board to do something when temperature read 40.

Well let's start with something simple. The number of left and right parenthesis should always be the same.

This is DHT11 code I modified with the if statement.\

The section commented out works, I have that down. if the sensor outputs <500 bits(?), the light will turn off.

I want to use the temperature readings though. And the humidity readings. But separated. For 2 separate non related functions.

Since there's no clear way of doing that (and noone seems to have attempted this) I figured the arduiino could use the number that appears on the serial monitor. Something like if (serial.print == 40) do this ( ).

But I don't know how to reference the serial monitor as an input

aarg:
Well let's start with something simple. The number of left and right parenthesis should always be the same.

how do you mean?
Pic related, my serial monitor

His code down here

    DHT.read11(dht_apin);
    
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature); 
    Serial.println("C  ");
    
    delay(5000);//Wait 5 seconds before accessing sensor again.

is actually reading the temp and humidity, and printing them to serial - that much is fine.

The rest of the sketch seems to be nonsense though.
analogRead(A0) is going to get you non-meaningful values, since the sensor is read using DHT.read(), which puts the values into DHT.temperature and DHT.humidity - it's a digital sensor, not an analog one.

After it's done DHT.read(), you could do something like

if (DHT.temperature > 40) {
//put code here to run when temp is above 40
} else {
// put code here to run when temp is at or below 40.
}

Chill_Polins:
how do you mean?

(like this)

(not this

if (DHT.temperature > 19) {

digitalWrite(led, HIGH);
//put code here to run when temp is above 40
} else {
digitalWrite(led, LOW);
// put code here to run when temp is at or below 40.
}

It works! Thank you!

if (DHT.temperature > 19) {
  
  digitalWrite(led, HIGH);
  //put code here to run when temp is above 40

If the comment doesn't describe the code, it's misleading and should not be there.