Dehydrator Code

Hello, this is my first post here.

One of my first projects is a program to use the arduino as a Dehydrator. A DHT11 should give me data about humidity and temperature in the Dehydrator. I want to use this data to trigger a relay which will then trigger either a heating element (a ceramic heater lamp) and/or a fan that sucks the humidity out of the dehydrator.

I want to use an LCD monitor to show me the current humidity and the current temperature. It will also show me the thresholds for MaxTemperatur (which switches the heater off) and MaxHumidity (which switches the fan on)

Finally, I will use 2 capacitors to change the values of the maximal temperature and the maximal humidity.

Good News. Everything works. But there are 2 Problems i cannot solve

  1. Problem when i rotate the capacitor connected to A0 the MaxHumidity Value changes as well
  2. Problem when i rotate the capacitor connected to A0 the MaxTemperatur Value changes from 0 to 10 to 20 to 30 to 40 till 90 and then it increases by +1 till 49. Thats obviously not 50.
#include <dht11.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#define DHT11PIN 4
dht11 DHT11;

int Fanout = 2;
int Heat = 3;

void setup()
{
  Serial.begin(9600);
  pinMode(Fanout, OUTPUT);
  pinMode(Heat, OUTPUT);
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
 
}

void loop()
{
  Serial.println();

   int chk = DHT11.read(DHT11PIN);
   //defining Pin 11 as DHT11 Datapin

   int TempMax = analogRead(A0);
    // read out Potentiometer Value and define as Variable
  TempMax = map(TempMax, 0, 1023, 0, 50); 
    //remap Value to accomodate possible Min and Max Temperatur Values of DHT11
   int HumMax = analogRead(A1);
   // read out Potentiometer Value and define as Variable
  HumMax = map(HumMax, 0, 1023, 20, 90);
    //remap Value to accomodate possible Min and Max Humidity Values of DHT11
    
  Serial.print("Humidity (%): ");
    Serial.println((float)DHT11.humidity);

  Serial.print("Temperature (C): ");
    Serial.println((float)DHT11.temperature);

  Serial.print("TempMax (C): ");
    Serial.println((float)TempMax);

  Serial.print("HumMax (%): ");
    Serial.println((float)HumMax);
    
  if (DHT11.humidity > HumMax) {digitalWrite(Fanout, HIGH);} //If the HumMax Value is exceeded the Fan will start to blow out the AIR
  else {digitalWrite(Fanout, LOW);}

  if (DHT11.temperature > TempMax) {digitalWrite(Heat, HIGH);} //If the TempMax Value is exceeded the Heating Relay will switch of 
  else {digitalWrite(Heat, LOW);}

    
  
  lcd.setCursor(0, 0);
    lcd.print("Te Hu MaxT MaxH");
//Setting the 4 Kategories on the LCD
  lcd.setCursor(0, 1);
    lcd.print(DHT11.temperature);

  lcd.setCursor(3, 1);
    lcd.print(DHT11.humidity);

  lcd.setCursor(6, 1);
    lcd.print(TempMax);

  lcd.setCursor(11, 1);
    lcd.print(HumMax);

  delay(100);

}

Please post a schematic of your project. A photo of a hand drawn circuit is good enough

I assume that you mean a potentiometer when you refer to capacitors

Hey man. Thanx for your answer. Yes you are right. I mean a potentiometer. I made a Fritzing of my setup. I have not yet connected a 2. potentiometer for the Humidity Value because my "Starter Kit" came with just 2 potentiometer.

You can not expect stable analog read values from a pin with nothing connected to it.

I would recommend that you use a fixed resistor to ground for the lcd contrast and move your second pot to the input for humidity setting.

In regards to the inaccuracy of the mapping, can you confirm the maximum analog read value from your pots.

Thx! switching the pot with a resistor and the plugin the pot into the himudity analog pin helped and solved the problem of simultaniously increasing and decreaing MaxHumidity AND MaxTemperature.

The second problem still excists. If MaxTemperatur value falls und 10 it De-and increases in steps of 10. 10 20 30 40.

The third problem still excists. The Values stop at MaxTemperature 49 and MaxHumidity 88. They also stop at MaxTemperature 3 and MaxHumidity 21. MaxHumidity also kind of fluctates +-1. Is it due to insufficient accuracy of the pot? Maybe poor buildquality?

I dont know how to do that.

Thx so far!

Here is my new Fritzing:

Not true. You write 1, 2, 3, ... and the 0 (from 10) is staying on. You must always write 2 chars. 01, 02, 03, ... or (space)1, (space)2, ...

if (value < 10){
  lcd.print("0"); // or lcd.print(" ");
}

Thank you for the clarification.

Your Code doesn't seem to work. Sorry.

Problem when i rotate the capacitor connected to A0 the MaxTemperatur Value changes from 0 to 10 to 20 to 30 to 40 till 90 and then it increases by +1 till 49. Thats obviously not 50.

You have two issues with the temperature(and humidity as well). The first has been addressed by @pommel where you are not overwriting the previous value correctly. I always print spaces in the field where the data will go and then reposition the cursor back to the starting index and print the data.
Another issue with the lcd management is that any unchanging data like the headers, should be printed in setup() and not with each pass of the loop. It reduces the time spent printing to the lcd which can be important in many cases.

The issue with the failure to map to the maximum value relates to the math of the map function which returns an integer.

Work the math. If your analog read does not return the exact input max value, it won't map to the output max. For example if you have
TempMax = map(TempMax, 0, 1023, 0, 50) and the analog reading is 1022 you will map to 49, because of the integer truncation.

You can examine the analog reading value you see by printing out the unmapped raw values of the two analog readings. You might want to set the top end of the analog reading to be mapped as 1020.

1 Like

This was pseudo code and not to copy paste.

lcd.setCursor(0, 1);
if(DHT11.temperature < 10){
	lcd.print("0");
	//lcd.print(" ");
}
lcd.print(DHT11.temperature);
1 Like

Now i understand. Thanks.

I made it my own.

if(TempMax < 10){
  lcd.setCursor(6,1);
	lcd.print("0");
  lcd.setCursor(7,1);
  lcd.print(TempMax);
}
else {lcd.setCursor(6,1);
      lcd.print(TempMax);

}

This fixed the problem! Thank you everyone!
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.