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);
}
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?
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);
}
}