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.)
