Help coding for temperature and humidity controller !

Hello everyone,

I am a beginner so please be understanding. I have a project to control the temperature of a fridge to refine cheese making at home.
I wish I could adjust the temperature and humidity according to the needs of the cheese in the fridge.

For this project I have an

  • Arduino Uno microcontroller
  • DHT22 sensor
  • DFRobot Shield 1602 with 6 buttons,
  • I2C or IIC module with address 0x27
  • and Relay module 2 channels.

My goal is to have an average of 12 ℃ and 80% humidity that will vary depending on the cheese to refine, that's why I want to change the values through the buttons.

As I am amateur and my project is only to focus on a model controller PID or similar I am inspired by 2 tutorial that satisfied me, the first is the possibility to use the shield DFRobot with I2C module and the second is the possibility to have a menu and control or change the measurements.

With the help of a good man Mr Keith (the project is named after him)
I managed to compile a sketch, to succeed in compiling it was necessary to work a lot but after the assembly I noticed some malfunctions, for example :
I do not has no lighting,
the relay 2 which must work for the temperature does not do anything,
when I just want to increase the values of temperature or humidity it does not go up by uniter as indicate in the code,
each presses button must go up or go down once but it goes up and down by 3 or 5 or 7 ..

Finally I wanted to share the code with the experts to conclude this mission or mega project for me who is amateur.
I really need your help, I can not give you much besides my respect and karma,

#include <Wire.h>  
#include <DFR_Key.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

const int humidityRelay = 10; 
const int heaterRelay = 11; 
const int DHTPIN = 2;  

int temp = 12; 
int hum = 80; 
int readkey;
long int lastmillis;
long int hours;
long int minutes;
long int seconds;

char l2c1;
char l2c2;
char l2c3;

DHT dht (DHTPIN, DHT22);  

DFR_Key keypad(0); 

int localKey = 0;
String keyString = "";
int lcd_key = 0;
int adc_key_in = 0;

const byte btnRIGHT = 0;  
const byte btnUP = 1;     
const byte btnDOWN = 2;   
const byte btnLEFT = 3;   
const byte btnSELECT = 4; 
const byte btnNONE = 5;   

int read_LCD_buttons() 

{
  adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 150)  return btnUP;
  if (adc_key_in < 300)  return btnDOWN;
  if (adc_key_in < 460)  return btnLEFT;
  if (adc_key_in < 690)  return btnSELECT;
}

void setup() 

{
  pinMode(humidityRelay, OUTPUT);
  pinMode(heaterRelay, OUTPUT);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Keith control");
  lcd.setCursor(0, 1);
  lcd.print("Select instr");
  delay(2500);
  Serial.begin(9600);
  dht.begin();
  delay(1000);
  lcd.clear();
  keypad.setRate(10);
  digitalWrite(humidityRelay, HIGH);  
  digitalWrite(heaterRelay, HIGH);  

}

void loop() 

{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(t) || isnan(h))

{  
                             
    lcd.begin(16, 2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Capteur N/C!!");
    delay(10000);
  } 

else 
 
 {
    lcd_key = read_LCD_buttons(); 
    switch (lcd_key) 
 {
      case btnLEFT:
        {
          temp = temp + 1; 
          break;
        }
      case btnRIGHT:
        {
          temp = temp - 1; 
          break;
        }
      case btnUP:
        {
          hum = hum + 1; 
          break;
        }
      case btnDOWN:
        {
          hum = hum - 1; 
          break;
        }
      case btnSELECT:  
        {
          lcd.begin(16, 2);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Hum Up/Down +-1%");
          lcd.setCursor(0, 1);
          lcd.print("Temp L/R +-1");
          lcd.print((char)223);
          lcd.print("C");
          delay (5000);
          break;
        }
    } 
    lcd.setCursor(0, 0);    
    lcd.print("Hum: ");
    lcd.print(h);
    lcd.print("%");
    lcd.print("(");
    lcd.print(hum);
    lcd.print("%)");
    lcd.setCursor(0, 1);
    lcd.print("Tem: ");
    lcd.print(t);
    lcd.print((char)223);
    lcd.print("(");
    lcd.print(temp);
    lcd.print((char)223);
    lcd.print(")");
    
    int H = 70 + 10;  
   
    if (h < 85) digitalWrite(humidityRelay, LOW); 
    else if (h >= H) digitalWrite(humidityRelay, HIGH);  

    int T = 12 + 2 ; 
    
    if (t < 12 )
      digitalWrite(heaterRelay, LOW); 
    else if (t >= T)
      digitalWrite(heaterRelay, HIGH); 
  }

}

I am thankful I do not forget the help bring.
Here is the complete code and shemas with change in the code for the pins A4 / A5 by D10 and D11 (for the relay)

Please help me, thank you in advance for your reading and may be a tip for me.
(I'm sorry for the mistakes I use a translator.)

Hopefully you’ll have better luck here than there... (I won’t be contributing twice)

Hello dear JML

Thank you for your support, as I had no answer from you, I think you're tired of me :slight_smile:
I am not easy amateur the beginning, and as no answer to my last messages,
I told myself that I should try to find solutions,

I thank you again for your support and also for your patience, but in the end I am like at the beginning,
so I wish to seek my luck here, maybe my answer this is here. If dear readers want to visit the link

I thank you in advance for your understanding, Too bad to see a message a bit naughty on your part but I'm sorry my goal was in no way disrespect you, besides

I'm just thanking you for your help but unfortunately that did not succeed, a pity to answer here and :wink: but I respect you anyway, cordially.

I gave you the structure of a code - what did you do with it? My message is not naughty, just factual.

I do not understand your intervention, I thank you again for the method of writing code but it did not work, I immediately send a comment with the error message but not received back. In the end, what is your goal? to lower me ? do not allow me to get help? but why, do I disrespect you once? I'm sorry but I do not understand you anymore.

Arduino : 1.8.4 (Windows 7), Carte : "Arduino/Genuino Uno"

C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino: In function 'void setup()':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                   C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:67:16: note: in expansion of macro 'F'

   Serial.begin(F(9600));   

                ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                        C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:67:16: note: in expansion of macro 'F'

   Serial.begin(F(9600));   

                ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino: In function 'void loop()':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:126:21: note: in expansion of macro 'F'

           lcd.print(F((char)223));  

                     ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^

C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:126:21: note: in expansion of macro 'F'

           lcd.print(F((char)223));  

                     ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:134:15: note: in expansion of macro 'F'

     lcd.print(F(h));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:134:15: note: in expansion of macro 'F'

     lcd.print(F(h));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:137:15: note: in expansion of macro 'F'

     lcd.print(F(hum));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:137:15: note: in expansion of macro 'F'

     lcd.print(F(hum));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^

C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:141:15: note: in expansion of macro 'F'

     lcd.print(F(t));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:141:15: note: in expansion of macro 'F'

     lcd.print(F(t));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:142:15: note: in expansion of macro 'F'

     lcd.print(F((char)223));  

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:142:15: note: in expansion of macro 'F'

     lcd.print(F((char)223));  

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:144:15: note: in expansion of macro 'F'

     lcd.print(F(temp));

               ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:144:15: note: in expansion of macro 'F'

     lcd.print(F(temp));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                          ^
C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:145:15: note: in expansion of macro 'F'

     lcd.print(F((char)223));

               ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

                                                                     C:\Users\\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:145:15: note: in expansion of macro 'F'

     lcd.print(F((char)223));

               ^
Erreur de compilation pour la carte Arduino/Genuino Uno

Why there is F in

lcd.print(F((char)223));

In my opinion, your code is way too big to handle for a beginner at once. My advice is try a smaller code wheres your problem resides. For example: make a small program that read the keypad. If keypad UP is pressed, send serial UP to your PC. if keypad DOWN is pressed, send serial DOWN to your PC and so on. If the small program is still have a problem, dont advance to the next step.

Col68:
I do not understand your intervention, I thank you again for the method of writing code but it did not work, I immediately send a comment with the error message but not received back. In the end, what is your goal? to lower me ? do not allow me to get help? but why, do I disrespect you once? I'm sorry but I do not understand you anymore.

Arduino : 1.8.4 (Windows 7), Carte : "Arduino/Genuino Uno"

C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino: In function 'void setup()':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:67:16: note: in expansion of macro 'F'

Serial.begin(F(9600));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:67:16: note: in expansion of macro 'F'

Serial.begin(F(9600));

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino: In function 'void loop()':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:126:21: note: in expansion of macro 'F'

lcd.print(F((char)223));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^

C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:126:21: note: in expansion of macro 'F'

lcd.print(F((char)223));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:134:15: note: in expansion of macro 'F'

lcd.print(F(h));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:134:15: note: in expansion of macro 'F'

lcd.print(F(h));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:137:15: note: in expansion of macro 'F'

lcd.print(F(hum));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:137:15: note: in expansion of macro 'F'

lcd.print(F(hum));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^

C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:141:15: note: in expansion of macro 'F'

lcd.print(F(t));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:141:15: note: in expansion of macro 'F'

lcd.print(F(t));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:142:15: note: in expansion of macro 'F'

lcd.print(F((char)223));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:142:15: note: in expansion of macro 'F'

lcd.print(F((char)223));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:144:15: note: in expansion of macro 'F'

lcd.print(F(temp));

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:144:15: note: in expansion of macro 'F'

lcd.print(F(temp));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: initializer fails to determine size of '__c'

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

^
C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:145:15: note: in expansion of macro 'F'

lcd.print(F((char)223));

^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:38:74: error: array must be initialized with a brace-enclosed initializer

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

C:\Users\Documents\Arduino\Essai_Code_JML_oct29\Essai_Code_JML_oct29.ino:145:15: note: in expansion of macro 'F'

lcd.print(F((char)223));

^
Erreur de compilation pour la carte Arduino/Genuino Uno

Well because you clearly did NOT use the code I gave you. I have no Serial.begin(F(9600)); in the code I wrote for you for example, so I have no clue what you are doing and which code you have been trying. Not mine clearly.

Hello dear Papatonk,

Why there is F in

The F is the method Macro F advisor by J-M-L, I do not know if it is me who mis-noted the instructions of J-M-L but it did not work.

You are too strong, that beautiful idea,
I will follow your instructions by installing the library "Menu management" Shield DFRobot and thus record the operation of the keys, I will try to work on this first main problem, Thank you again for your help, cordially.

Dear J-M-L, I assure you that I tried in 115200 it was the same, the code edit is here,

#include <Wire.h>  
#include <DFR_Key.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>


const byte humidityRelay = 18; 
const byte heaterRelay = 19;     
const byte DHTPIN = 2;  
const byte nbColumns = 16;
const byte nbLines   = 2;            

LiquidCrystal_I2C lcd( 0x27, nbColumns, nbLines);  

int temp = 12;  
int hum = 80;  
int readkey;
unsigned long lastmillis; 
long int hours;
long int minutes;   
long int seconds;

char l2c1;
char l2c2;
char l2c3;


DHT dht (DHTPIN, DHT22);  //  Type de capteur DHT22 (AM2023)


DFR_Key keypad(0); 

int localKey = 0;  
int lcd_key = 0;
int adc_key_in = 0;

const byte btnRIGHT = 0;  
const byte btnUP = 1;     
const byte btnDOWN = 2;   
const byte btnLEFT = 3;   
const byte btnSELECT = 4; 
const byte btnNONE = 5;   

int read_LCD_buttons() 
{
  adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 150)  return btnUP;
  if (adc_key_in < 300)  return btnDOWN;
  if (adc_key_in < 460)  return btnLEFT;
  if (adc_key_in < 690)  return btnSELECT;
}

void setup() 

{
  pinMode(humidityRelay, OUTPUT);
  pinMode(heaterRelay, OUTPUT);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("Keith control"));  //  utilisé le macro F () dans tous les Print () du Lcd ou de Serial
  lcd.setCursor(0, 1);
  lcd.print(F("Select instr"));  // 
  delay(2500);
  Serial.begin(F(115200));   // Mettre le port série sur 115200 au lieu de 9600
  dht.begin();
  delay(1000);
  lcd.clear();

  
  keypad.setRate(10);
  digitalWrite(humidityRelay, HIGH);  // Relais Humidité actif
  digitalWrite(heaterRelay, HIGH);  // Relais Température actif

}

void loop() 

{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(t) || isnan(h))
{  
                             
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(F("Capteur N/C!!"));  // utilisé le macro F () 
    delay(10000);
  } 
else 
 {
    lcd_key = read_LCD_buttons();  
    switch (lcd_key) 
 {
      case btnLEFT:
        {
          temp = temp + 1; 
          break;
        }
      case btnRIGHT:
        {
          temp = temp - 1;  
          break;
        }
      case btnUP:
        {
          hum = hum + 1;  
          break;
        }
      case btnDOWN:
        {
          hum = hum - 1;  
          break;
        }
      case btnSELECT:   
        {
          lcd.begin(16, 2);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print(F("Hum Up/Down +-1%"));  // utilisé le macro F () 
          lcd.setCursor(0, 1);
          lcd.print(F("Temp L/R +-1"));   
          lcd.print(F((char)223));  
          lcd.print(F("C"));  
          delay (5000);
          break;
        }
    } 
    lcd.setCursor(0, 0);     
    lcd.print(F("Hum: "));  // utilisé le macro F () pour tous les lcd.print
    lcd.print(F(h));
    lcd.print(F("%"));
    lcd.print(F("("));
    lcd.print(F(hum));
    lcd.print(F("%)"));
    lcd.setCursor(0, 1);
    lcd.print(F("Tem: "));
    lcd.print(F(t));
    lcd.print(F((char)223));  
    lcd.print(F("("));
    lcd.print(F(temp));
    lcd.print(F((char)223));
    lcd.print(F(")"));

    int H = 70 + 10;  
   
    if (h < 85) digitalWrite(humidityRelay, LOW);  
    
    else if (h >= H) digitalWrite(humidityRelay, HIGH);  
   
    int T = 12 + 2 ; 
    
    if (t < 12 )
      
    digitalWrite(heaterRelay, LOW);  
    
     else if (t >= T)
     
    digitalWrite(heaterRelay, HIGH);  
  }

}

no problem all your instructions are noted but I always received errors. I could not ask you to write the code for me, so I wrote down all your instructions piece by piece, and thank you very much.

  Serial.begin(F(115200));   // Mettre le port série sur 115200 au lieu de 9600

I never wrote it that way.... this should beSerial.begin(115200);

same for lcd.print(F((char)223));

OK?

Okay,
I'll try by editing the 2 pieces of text,

Thanks J-M-L,
I'm sorry for the mishaps, best regards.

Hello everyone,

Dear J-M-L thank you for your help, the errors have diminished by following your advice but persists,

#include <Wire.h>  
#include <DFR_Key.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

const byte humidityRelay = 18; 
const byte heaterRelay = 19;     
const byte DHTPIN = 2;  
const byte nbColumns = 20; // Essai pour voir en 20 et en 16
const byte nbLines   = 2;            

LiquidCrystal_I2C lcd( 0x27, nbColumns, nbLines);  

int temp = 12;
int hum = 80;  
int readkey;
unsigned long lastmillis;
long int hours;
long int minutes;   
long int seconds;

char l2c1;
char l2c2;
char l2c3;


DHT dht (DHTPIN, DHT22);  //  Type de capteur DHT22 (AM2023)


DFR_Key keypad(0); 

int localKey = 0;  
int lcd_key = 0;
int adc_key_in = 0;

const byte btnRIGHT = 0;  
const byte btnUP = 1;     
const byte btnDOWN = 2;   
const byte btnLEFT = 3;   
const byte btnSELECT = 4; 
const byte btnNONE = 5;   

int read_LCD_buttons() 
{
  adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 150)  return btnUP;
  if (adc_key_in < 300)  return btnDOWN;
  if (adc_key_in < 460)  return btnLEFT;
  if (adc_key_in < 690)  return btnSELECT;
}

void setup() 

{
  pinMode(humidityRelay, OUTPUT);
  pinMode(heaterRelay, OUTPUT);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("Keith control"));  // le macro F () dans tous les Print () du Lcd ou de Serial
  lcd.setCursor(0, 1);
  lcd.print(F("Select instr"));  // 
  delay(2500);
 Serial.begin(115200);  // Mettre le port serie sur 115200 
  dht.begin();
  delay(1000);
  lcd.clear();

  
  keypad.setRate(10);
  digitalWrite(humidityRelay, HIGH);  
  digitalWrite(heaterRelay, HIGH);  

}

void loop() 

{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(t) || isnan(h))
{  
                             
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(F("Capteur N/C!!"));  // Macro F ()
    delay(10000);
  } 
else 
 {
    lcd_key = read_LCD_buttons();  
    switch (lcd_key) 
 {
      case btnLEFT:
        {
          temp = temp + 1; 
          break;
        }
      case btnRIGHT:
        {
          temp = temp - 1;  
          break;
        }
      case btnUP:
        {
          hum = hum + 1;  
          break;
        }
      case btnDOWN:
        {
          hum = hum - 1;  
          break;
        }
      case btnSELECT:   
        {
          lcd.begin(16, 2);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print(F("Hum Up/Down +-1%"));  // Macro F () 
          lcd.setCursor(0, 1);
          lcd.print(F("Temp L/R +-1"));   
          lcd.print((char)223);  
          lcd.print(F("C"));  
          delay (5000);
          break;
        }
    } 
    lcd.setCursor(0, 0);     
    lcd.print("Hum: ");  // Macro F () pour tous les lcd.print
    lcd.print(h);
    lcd.print(F("%"));
    lcd.print(F("("));
    lcd.print(hum);
    lcd.print(F("%)"));
    lcd.setCursor(0, 1);
    lcd.print("Tem: ");
    lcd.print(t);
    lcd.print((char)223);  
    lcd.print(F("("));
    lcd.print(temp);
    lcd.print((char)223);
    lcd.print(F(")"));

    int H = 70 + 10;  
   
    if (h < 85) digitalWrite(humidityRelay, LOW);  
    
    else if (h >= H) digitalWrite(humidityRelay, HIGH);  
   
    int T = 12 + 2 ; 
    
    if (t < 12 )
      
    digitalWrite(heaterRelay, LOW);  
    
     else if (t >= T)
     
    digitalWrite(heaterRelay, HIGH);  
  }

}

I believe that this mission will be impossible to achieve for me at the moment, as I am only amateur. I do not give up but I will work in stages to understand what I do and what happens, thank you for your support J-M-L. If I hurt you, I beg your pardon, I apologize for disturbing you, you are here to help us, I thank you again for all your support. I wish you happiness and please, forgive this gallerian. With respect, cordially.

  • Code Error :
 Arduino : 1.8.4 (Windows 7), Carte : "Arduino/Genuino Uno"


C:\Users\\AppData\Local\Temp\ccTel6UO.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:13: undefined reference to `LiquidCrystal_I2C::LiquidCrystal_I2C(unsigned char, unsigned char, unsigned char)'

C:\Users\\AppData\Local\Temp\ccTel6UO.ltrans0.ltrans.o: In function `setup':

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:60: undefined reference to `LiquidCrystal_I2C::begin(unsigned char, unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:61: undefined reference to `LiquidCrystal_I2C::clear()'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:62: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:64: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:70: undefined reference to `LiquidCrystal_I2C::clear()'

C:\Users\\AppData\Local\Temp\ccTel6UO.ltrans0.ltrans.o: In function `loop':

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:88: undefined reference to `LiquidCrystal_I2C::clear()'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:89: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:120: undefined reference to `LiquidCrystal_I2C::begin(unsigned char, unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:121: undefined reference to `LiquidCrystal_I2C::clear()'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:122: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:124: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:132: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'

C:\Users\\Documents\Arduino\Code_Modif_31oct/Code_Modif_31oct.ino:139: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'

collect2.exe: error: ld returned 1 exit status

Utilisation de la bibliothèque Wire version 1.0 dans le dossier: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
Utilisation de la bibliothèque DFR_Key prise dans le dossier : C:\Users\\Documents\Arduino\libraries\DFR_Key (legacy)
Utilisation de la bibliothèque DHT_sensor_library version 1.2.3 dans le dossier: C:\Users\\Documents\Arduino\libraries\DHT_sensor_library 
Utilisation de la bibliothèque LiquidCrystal_I2C version 1.1 dans le dossier: C:\Users\\Documents\Arduino\libraries\LiquidCrystal_I2C 
exit status 1
Erreur de compilation pour la carte Arduino/Genuino Uno

There are (unfortunately) many versions of the LiquidCrystal_I2C library. Apparently, the one you have is not the one that the code is written for.

PaulS:
There are (unfortunately) many versions of the LiquidCrystal_I2C library. Apparently, the one you have is not the one that the code is written for.

Hello dear PaulS,

thank you for your very useful information. I will edit and try with the bookstores LiquidCrystal_I2C library until I find the right one. Thanks again for the help cordially.

@Col68

--> I mentioned the one I used in the french section check out this LiquidCrystal_I2C (that's the one which was going with the proposed code)

J-M-L:
@Col68

--> I mentioned the one I used in the french section check out this LiquidCrystal_I2C (that's the one which was going with the proposed code)

Thank you dear J-M-L for your help,
I will download it to try, thank you again for all that you have done for me, forgive this amateur, cordially.