Use multiple DHT 11 solar air heater school project

Hey there,

Last week i got into arduino for a school project.
I’am building a solar air heater and I use arduino to control fans in the heater.
I mixed some codes to control the fans based on fixed temperatures and display them on lcd.
The next step is another temp sensor…
I’am using two DHT11-sensors (3-pin variant on board), but I can’t adres them properly.

arduino uno
lcd 16x2
4 relays

Could you help me?

code;

//Solar air heater

#include <dht.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht DHT;

#define DHT11_PIN 6
#define DHT11_PIN 10 //temperaturesensor2
int fanlow = 8;
int fanhigh = 9;
int psu = 7;
int i = 0;


void setup()

{
  
lcd.begin(16, 2);

Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperatureout,\tTempreturein, (C)");

pinMode(fanlow, OUTPUT);
pinMode(fanhigh, OUTPUT);
pinMode(psu, OUTPUT);

}


void loop()
{

Serial.print("DHT11, \t");
int chk = DHT.read11(DHT11_PIN);


Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
//Serial.println(temperaturesensor2); 

{
lcd.setCursor(0,0);
lcd.print(DHT.temperature);
lcd.setCursor(0,1);
lcd.print("xxxx"); //temperature 2  
}

  if (DHT.temperature<25) 
  {
  digitalWrite(psu,HIGH);
  digitalWrite(fanlow,HIGH);
  digitalWrite(fanhigh,HIGH);
  }

  
  if (DHT.temperature>=26 && DHT.temperature<=30) 
  {
  digitalWrite(psu,LOW);
  delay(2000);
  digitalWrite(fanlow,LOW);
  digitalWrite(fanhigh,HIGH);
  } 

  
  if (DHT.temperature>31) 
  {
  digitalWrite(fanlow,LOW);
  digitalWrite(fanhigh,LOW);
  }

delay(500);
}

Please follow the instructions in “How to Post”. Edit your post and use code tags (select and hit the “</>” button).

try this version, DHT connect to pin 6

I did refactor the code a bit, so find the 7 differences :wink:

//Solar air heater

#include <dht.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht DHT;

#define DHT11_PIN 6
// #define DHT11_PIN 10 //temperaturesensor2

int fanlow = 8;
int fanhigh = 9;
int psu = 7;
int i = 0;

void setup()
{
  lcd.begin(16, 2);

  Serial.begin(115200);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperatureout,\tTempreturein, (C)");

  pinMode(fanlow, OUTPUT);
  pinMode(fanhigh, OUTPUT);
  pinMode(psu, OUTPUT);
}


void loop()
{
  Serial.print("DHT11, \t");
  int chk = DHT.read11(DHT11_PIN);

  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.println(DHT.temperature, 1);
  //Serial.println(temperaturesensor2);

  lcd.setCursor(0, 0);
  lcd.print(DHT.temperature);
  lcd.setCursor(0, 1);
  lcd.print("xxxx"); //temperature 2

  int temperature = DHT.temperature;
  
  if (temperature < 25)
  {
    digitalWrite(psu, HIGH);
    digitalWrite(fanlow, HIGH);
    digitalWrite(fanhigh, HIGH);
  }
  else if (temperature <= 30)
  {
    digitalWrite(psu, LOW);
    digitalWrite(fanlow, LOW);
    digitalWrite(fanhigh, HIGH);
  }
  else // temperature > 31
  {
    digitalWrite(psu, LOW);     // <<<<<<<  ?????? IS THIS RIGHT
    digitalWrite(fanlow, LOW);
    digitalWrite(fanhigh, LOW);
  }

  delay(2000);
}

If you want to work with two sensors you could do it like this

//Solar air heater
#include <dht.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht DHT;

#define INPUT_DHT11_PIN 6
#define OUTPUT_DHT11_PIN 10

int fanlow = 8;
int fanhigh = 9;
int i = 0;

void setup()
{
  lcd.begin(16, 2);

  Serial.begin(115200);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperatureout,\tTempreturein, (C)");

  pinMode(fanlow, OUTPUT);
  pinMode(fanhigh, OUTPUT);
}


void loop()
{
  int chk = DHT.read11(INPUT_DHT11_PIN);
  int inputTemp = DHT.temperature;
  int inputHum = DHT.humidity;
  
  chk = DHT.read11(OUTPUT_DHT11_PIN);
  int outputTemp = DHT.temperature;
  int outputHum = DHT.humidity;
  
  lcd.setCursor(0, 0);
  lcd.print(inputTemp);
  lcd.setCursor(0, 1);
  lcd.print(outputTemp);

  int tempDifference = inputTemp - outputTemp;
  
  if (tempDifference < 2)
  {
    digitalWrite(fanlow, HIGH);
    digitalWrite(fanhigh, HIGH);
  }
  else if (tempDifference < 6)
  {
    digitalWrite(fanlow, LOW);
    digitalWrite(fanhigh, HIGH);
  }
  else // tempDifference > 5
  {
    digitalWrite(fanlow, LOW);
    digitalWrite(fanhigh, LOW);
  }

  delay(2000);
}