Help with creating functions to turn on leds.

I need to create two functions that turn on leds if the temperature is above or below a certain number. I am stuck at the moment, my code works but the leds do not turn on. Thanks for any input.

#include "DHT.h"
int DHT11Pin = 4;           // The DHT11 sensor  is connected to pin 4 of the Arduino. 
int waitTime = 3000;        // The amount of time to wait between sensor reads. 
int redLed = 12;      // The red led connected to pin 12.
int blueLed = 13;      // The blue led connected to pin 13.
DHT dht(DHT11Pin, DHT11);   // Initialize the sensor.



void setup(){
  dht.begin();  // Start the sensor.
  pinMode(redLed, OUTPUT);    // 
  pinMode(blueLed, OUTPUT);   //
}

void loop()
{
  delay(waitTime);
  float humidity = dht.readHumidity();  // Read the humidity value from the sensor.
  float celsius = 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(celsius, humidity, false); // Calculate the heat index (c).
                                                                  
  Serial.print("Humidity   (%): "); 
  Serial.println(humidity );        // Display the humidity precentage.
  Serial.print("Temperature(c): ");
  Serial.println(celsius);          // 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.print("Dewpoint: ");
  Serial.println(dewPoint(celsius,humidity)); // Display the dewpoint.
  highTemp;    // Call the high temp function
  lowTemp;    // Call the low temp function
}

  double dewPoint(double celsius, double humidity) // dewpoint function
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
        double Td = (b * temp) / (a - temp);
        return Td;
}
  void highTemp(float celsius)  // Turn on the red led when temp is above 25c.
{
    if (celsius > 25);
    digitalWrite(redLed, HIGH);        
}
  void lowTemp(float celsius)   // Turn on the blue led when the temp is below 25c.
{
    if (celsius < 25);
    digitalWrite(blueLed, HIGH);  
}

my code works but the leds do not turn on

that’s not the definition of a working code...

Review your C code tutorial. Is that how you call a function?

  highTemp;    // Call the high temp function
  lowTemp;    // Call the low temp function

Calling a function requires a pair of parentheses after the name.

J-M-L:
that’s not the definition of a working code...

Review your C code tutorial. Is that how you call a function?

  highTemp;    // Call the high temp function

lowTemp;    // Call the low temp function

Touche. My code uploaded without any errors is what I meant.

No, I switched it to

  void highTemp();    // Call the high temp function
  void lowTemp();    // Call the low temp function

And am still getting no errors but no led activity.

Not too far... those functions need a parameter, don’t they ? What do you think void in front means?

(You should turn on compilation warnings in the preferences)

J-M-L:
Not too far... those functions need a parameter, don’t they ? What do you think void in front means?

(You should turn on compilation warnings in the preferences)

I have no clue. I turned on compilation warnings and switched it too:

  highTemp(celsius);    // Call the high temp function
  lowTemp(celsius);    // Call the low temp function

Now both leds turn on and stay on..

Look at the syntax for the if statement and where the semi colon needs to go if there is one (beginners should always use brackets {})

if (condition) {
  SomeStatementIfTrue1;
  SomeStatementIfTrue2;
  SomeStatementIfTrue3;
} else {
  SomeStatementIfFalse1;
  SomeStatementIfFalse2;
  SomeStatementIfFalse3;
}

Or if there is no need for the else part

if (condition) {
  SomeStatementIfTrue1;
  SomeStatementIfTrue2;
  SomeStatementIfTrue3;
}

Also ask yourself who is turning off the leds?

  void temp(float celsius)  // Turn on the led when temp is above or below 25c.
{
    if (celsius > 25);
    digitalWrite(redLed, HIGH);
    digitalWrite(blueLed, LOW); 
           
    if (celsius < 25);
    digitalWrite(blueLed, HIGH);
    digitalWrite(redLed, LOW);  
}

Alright I have it down to this now, the blue led is because the temp is below 25. Is there a way I can make the temp rise above 25 to see if the red led will turn on?

Blow warm air on your sensor or hold it tight in your hand

You still mess up the if...
if (celsius > 25)[color=red][b];  <=== wrong semicolon [/b][/color]
And use brackets...

Ahh. Such a simple mistake.

  void temp(float celsius)  // Turn on the red led when temp is above 25c.
{
    if (celsius > 25) {
    digitalWrite(redLed, HIGH);
    digitalWrite(blueLed, LOW);
    } 
           
    if (celsius < 25) {
    digitalWrite(blueLed, HIGH);
    digitalWrite(redLed, LOW);  
    }
}

Got this to work, thank you!

Congrats !

You could improve it a bit by using an else statement instead of two separated if:

  if (celsius > 25) {
    digitalWrite(redLed, HIGH);
    digitalWrite(blueLed, LOW);
  } else { //here celsius is <= 25
    digitalWrite(blueLed, HIGH);
    digitalWrite(redLed, LOW);  
  }