no0b Stuck with Humidity and LED/RGBs - Send Help!

I'm trying to do this:
Have the Red LED (D12) turn on when the temperature is 25C and the Blue LED (D13)
when the temperature is below 25C
Have the Green LED on the RGB (D9) turn on when the humidity is below 50% and Blue
LED on the RGB (D11) when it’s above 50%

And after two grugling days, I've gotten to here:
#include "DHT.h"
int DHT11Pin = 4; //The DHT11 sensor is connected to pin 4 of the Arduino.
int waitTime = 5000; //The amount of time to wait between sensor reads.
DHT dht(DHT11Pin, DHT11);//Initialize the sensor.
int RGBGreenPin = 10; //The green RGB LED is connected pin 10 of the Arduino.
int RGBBluePin = 11; //The blue RGB LED is connected pin 11 of the Arduino.
int LEDRedPin = 12; // The red LED is connected.
int LEDBluePin = 13; // The blue LED is connected.

void setup(){
// Setup serial monitor
Serial.begin(9600);Serial.println(); //Break for the next line in Serial Monitor
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)"); //% of Humidity in the air, C and F Temperature values
dht.begin(); //Start the sensor.

pinMode(RGBGreenPin, OUTPUT); //Setup green RGB LED pin as an output pin.
pinMode(RGBBluePin, OUTPUT); //Setup blue RGB LED pin as an output pin.
pinMode (LEDRedPin, OUTPUT); //Stepup red LED as an output pin.
pinMode (LEDBluePin, OUTPUT); //Setup blue LED as an output pin.
}

void loop()
{
delay(waitTime);
float humidity = dht.readHumidity(); //Read the humidity value from the sensor.
float temp = dht.readTemperature(); //Read the temperature (c) value from the sensor.
float fahrenheit = dht.readTemperature(true); //Read the temperature (f) value from the sensor.
float heatIndexF = dht.computeHeatIndex(fahrenheit, humidity); //Calculate the heat index (f).
float heatIndexC = dht.computeHeatIndex(temp, humidity, false); //Calculate the heat index (c).

Serial.print("Humidity (%): ");
Serial.println(humidity ); //Display the humidity precentage.
Serial.print("Temperature(c): ");
Serial.println(temp); //Display the temperature in celsius.
Serial.print("Heat index (c): ");
Serial.println(heatIndexC); //Display the heat index in celsius.
Serial.print("Temperature(f): ");
Serial.println(fahrenheit); //Display the temperature in fahrenheit.
Serial.print("Heat index (f): ");
Serial.println(heatIndexF); //Display the heat index in fahrenheit.
Serial.println(temp);
if (digitalRead==(temp) > 24 && temp < 25)
{
analogWrite(12, HIGH);
analogWrite(13, LOW);
analogWrite(10, LOW);
analogWrite (11, LOW);
delay(1000);
}

//Changes colour to blue under 24C
if (digitalRead==(temp) > 24)
{
analogWrite(12, LOW);
analogWrite(13, HIGH);
analogWrite(10, LOW);
analogWrite(11, LOW);
delay(1000);
}
Serial.println(humidity);
if (digitalRead==(humidity) > 50%)
{
analogWrite(12, LOW);
analogWrite(13, LOW);
analogWrite(10, HIGH);
analogWrite(11, LOW);
delay(1000);
}

else

analogWrite(12, LOW);
analogWrite(13, HIGH);
analogWrite(10, LOW);
analogWrite(11, LOW);
delay(1000);
}

I'm sure this is a really dumb error, but I'm too new at this to figure it out :confused: Any thoughts?

Worth noting I'm on a Leonardo board

couple things jump out to start. first, use code tags so your code is easier to read.

but as far as the code itself, your IF statements are all wonky. You've already stored a value in your variables that you get by making function calls to your sensors, so the digitalRead()'s in your IF statements are not appropriate, and your logical operators aren't quite correct either. Plus, analogWrite() is for PWM output on select pins and specifies a PWM value between 0-255. What you want instead is digitalWrite().

So instead of:

    if (digitalRead==(temp) > 24)
    {
      analogWrite(12, LOW);
      analogWrite(13, HIGH);
      analogWrite(10, LOW);
      analogWrite(11, LOW);
      delay(1000);
    }

Its:

if (temp > 24)
    {
      digitalWrite(12, LOW);
      digitalWrite(13, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      delay(1000);
    }

for your first IF where you have multiple logical operators, you would format thusly:

if (temp > 24 && temp < 25)
    {
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      delay(1000);
    }

But you've also assigned names to pins 10, 11, 12, and 13, so you should use those variable names in your code instead of the digits themselves.

if (temp > 24)
    {
      digitalWrite(LEDRedPin, LOW);
      digitalWrite(LEDBluePin, HIGH);
      digitalWrite(RGBGreenPin, LOW);
      digitalWrite(RGBBluePin , LOW);
      delay(1000);
    }

I doubt that fixes everything, but its a start and what jumped out right away.

silly_cone:
couple things jump out to start. first, use code tags so your code is easier to read.

but as far as the code itself, your IF statements are all wonky. You've already stored a value in your variables that you get by making function calls to your sensors, so the digitalRead()'s in your IF statements are not appropriate, and your logical operators aren't quite correct either. Plus, analogWrite() is for PWM output on select pins and specifies a PWM value between 0-255. What you want instead is digitalWrite().

That really helps, thanks so much!

It does bring my back to the same error, though, for my first line of 'humidity, :
exit status 1
expected primary-expression before ')' token

I have NO clue what it whats me to add. I'm about ready to tear my hair out!

if (humidity > 50%)
{
digitalWrite(LEDRedPin, LOW);
digitalWrite(LEDBluePin, LOW);
digitalWrite(RGBGreenPin, HIGH);
digitalWrite(RGBBluePin, LOW);
delay(1000);
}

you're not trying to compile it with the "%" in it, are you?

silly_cone:
you're not trying to compile it with the "%" in it, are you?

...I may have been.
But now the error is 'Error compiling for board Arduino Leonardo.' Which I feel is worse?

I went ahead and cleaned up your code. I took a lot of stuff out and made it easier to follow. There were errors in the implementation and usage of the DHT.

I have not tested the following code, but it does compile for a Leonardo.

#include <dht.h>

int DHT11Pin = 4;     
int waitTime = 5000;   

int G=10, B=11, Red=12, Blue=13; 

float chk, humidity, temp;

dht DHT;

void setup(){
  Serial.begin(9600);
  Serial.println(); 
  
  pinMode(G, OUTPUT); 
  pinMode(B, OUTPUT);   
  pinMode(Red, OUTPUT); 
  pinMode(Blue, OUTPUT); 
}

void loop()
{ 
  chk = DHT.read11(DHT11Pin);
  humidity = DHT.humidity;  //Read the humidity value from the sensor.
  temp = DHT.temperature; //Read the temperature (c) value from the sensor. 

  Serial.print("Humidity   (%): "); 
  Serial.println(humidity );        //Display the humidity precentage.

  Serial.print("Temperature(c): ");
  Serial.println(temp);          //Display the temperature in celsius.

//RGB turns Blue if temp<25
  if (temp < 25)
    {
      digitalWrite(Red, LOW);
      digitalWrite(Blue, HIGH);
    }

//Changes colour to red if temp is at least 25
  if (temp >= 25)
    {
      digitalWrite(Red, HIGH);
      digitalWrite(Blue, LOW);
    }

//RGB turns blue if Rh at least 50%
  if (humidity >= 50)
    {
     digitalWrite(B, HIGH);
     digitalWrite(G, LOW);
    }

// RGB turns green if Rh less than 50%
  if (humidity < 50)
    {
     digitalWrite(B, LOW);
     digitalWrite(G, HIGH);
    }

  delay(waitTime);
}

silly_cone:
I went ahead and cleaned up your code. I took a lot of stuff out and made it easier to follow. There were errors in the implementation and usage of the DHT.

I have not tested the following code, but it does compile for a Leonardo.

#include <dht.h>

int DHT11Pin = 4;   
int waitTime = 5000;

int G=10, B=11, Red=12, Blue=13;

float chk, humidity, temp;

dht DHT;

void setup(){
  Serial.begin(9600);
  Serial.println();
 
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT); 
  pinMode(Red, OUTPUT);
  pinMode(Blue, OUTPUT);
}

void loop()
{
  chk = DHT.read11(DHT11Pin);
  humidity = DHT.humidity;  //Read the humidity value from the sensor.
  temp = DHT.temperature; //Read the temperature (c) value from the sensor.

Serial.print("Humidity  (%): ");
  Serial.println(humidity );        //Display the humidity precentage.

Serial.print("Temperature(c): ");
  Serial.println(temp);          //Display the temperature in celsius.

//RGB turns Blue if temp<25
  if (temp < 25)
    {
      digitalWrite(Red, LOW);
      digitalWrite(Blue, HIGH);
    }

//Changes colour to red if temp is at least 25
  if (temp >= 25)
    {
      digitalWrite(Red, HIGH);
      digitalWrite(Blue, LOW);
    }

//RGB turns blue if Rh at least 50%
  if (humidity >= 50)
    {
    digitalWrite(B, HIGH);
    digitalWrite(G, LOW);
    }

// RGB turns green if Rh less than 50%
  if (humidity < 50)
    {
    digitalWrite(B, LOW);
    digitalWrite(G, HIGH);
    }

delay(waitTime);
}

Thank you so much, man! That really helped! I've got a long way to go with Arduino!