Hello everyone, I am writing to you because I can not finish my project of control of temperature and humidity.
The material for my project is:
Keypad 1602 Shield (to control from a menu)
I2C module (to save space behind the screen and gain arduino pin)
Relay module 2 channels (1 for cold “fridge” 2 for humidifier in the fridge)
Uno as a microcrontroller
Breadboard and its external power supply
As i am amateur, i was inspired by 2 tutorials, the first shows how to use the i2c module with the shield 1602 the second to control the temperature and humidity with Shield 1602, relay 2 channels and dht22.
With help i managed to adapt the 2 codes with editing but i have major problems to finalize my project. firstly i had no backlight and after removing the Pin 10 LCD to Pin 1 of the module I2C the problem is set, now I see the screen,
I can adjust the temperature and humidity +1 or -1 without problem, but unfortunately the arduino does not take into account the setpoint changes, it works according to the instruction of end of the scketch that with (if temp <20 relay …)
it does not want to accept the change buttons, but the buttons work very well. Relays also work without problem according to the guidelines of the sketch but not buttons. Realiter the menu is simple but as I am amateur this is a new world for me.
if you can help me finalize please I would be happy. Here is the complete code
(the delays are long for the sensor, in order to avoid the frequent starts of the compressor of the fridge.
#include <DHT.h> // inclure les librairies
#include <Wire.h>
#include <LCD.h>
#include <DFR_Key.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0.27 est l'adresse du bus I2C
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const int humidityRelay = 11; // PIN 11pour le relais
const int heaterRelay = 12; // PIN 12
// Demarrage des valeurs, apres le demarrage on peut les changer
int temp = 19;
int hum = 49;
int readkey;
long unsigned lastmillis;
long int hours;
long int minutes;
long int seconds;
char l2c1;
char l2c2;
char l2c3;
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(" ThanksKeith control");
lcd.setCursor(0, 1);
lcd.print("Instr on Select");
delay(2500);
Serial.begin(9600);
dht.begin();
delay(10000);
lcd.clear();
// Taux d'echantillonnage (par defaut 10ms)
// Sampling rate (default 10ms)
keypad.setRate(100);
digitalWrite(humidityRelay, HIGH);
digitalWrite(heaterRelay, HIGH);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h))
{
if (millis() - lastmillis > 20000)
lcd.setBacklight(HIGH);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Capteur N/C!!");
delay(15000);
}
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 (10000);
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(")");
if (h > 45) digitalWrite(humidityRelay, HIGH);
else if (h < 40) digitalWrite(humidityRelay, LOW);
if (t < 25)
digitalWrite(heaterRelay, HIGH);
else if (t > 20)
digitalWrite(heaterRelay, LOW);
}
}
In pictures of the diagram fritzing the pins may have been changed but the base is the same.
the blue wire between lcd pin 10 and I2C pin 1 (from the right side) has to be put out if not no light.
Thank you for your reading, I apologize for the mistakes I use a translator, cordially.