Hello everyone ! ,
I've tried to complete my system, but unfortunately newer problem occurred, in fact im trying to
control Peltier based fridge usig a TEC , Fans, sinc and DHT 11 sensor, The purpose is to control this
system via LCD keypad Shield in 2 schedules:
1st - To control manually by increasing the power of TEC and FAN through pwm pins
2nd - Automatic switch based on entry level number
with my sketch i could control it manually and display it in fine way using the " switch...case"
commands
to determine the pressed key and to do action ( increase or decrease power), but when it comes to
include the automatic sketch in the 5-th case (or button) , it didnt work perfectly , and i think the
problem is in how to save this mode ( i included (delay) the auto mode worked just when pressing the
key, worked during that delay and i had to push the button each time after that the delay
ends to make auto mode works;
so please any suggestions and solutions how to save the auto mode , also how to adjust the auto
mode power or temperature reference ?
This is my sktech :
<#include <dht.h> // include DHT library
#include <LiquidCrystal.h> // Include LCD 16 x2 Library
#define dht_apin A1 // Analog Pin sensor is connected to
LiquidCrystal lcd(8,9,4,5,6,7); // introduce LCD digital pins
dht DHT;
int fan= 3; //The N-Channel MOSFET connected to fan
//is on digital pin 3
int powerfan= 0; //fan Power level fro 0 to 99%
int fan_level = map(powerfan, 0, 100, 0, 255); // convert fan power to percentage (0_100%)
int tec = 11; // N -Channel Mosfet connected to digital pin 11
int powertec = 0; // TEC power level from 0 to 100%
int tec_level = map(powertec, 0, 100, 0, 255); // convert TEC power to percentage(0_100%)
int temp=DHT.temperature;
int val; // value of the pressed key on keypad shield
byte degree[8] = // Create (') character before ("C") temperature unit
{
0b00011,
0b00011,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup() {
// put your setup code here, to run once:
pinMode(fan, OUTPUT);
pinMode(tec, OUTPUT);
lcd.begin(16,2);
lcd.createChar(1, degree);
lcd.setCursor(0,0);
lcd.print("PAINT SAFE");
lcd.setCursor(0,1);
lcd.print(" by SAMER");
delay(1000);
lcd.clear();
}
byte key(){ // sel - 637 , lef - 405, dow - 253, up - 97, righ - 0
int val = analogRead(0);
if (val < 50 ) return 5;
else if (val < 150 ) return 4;
else if (val < 300) return 3;
else if (val < 500 ) return 2;
else if (val < 750) return 1;
else if ( val <= 1023) return 0;
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Fan:");
lcd.print(powerfan);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("COOL:");
lcd.print(powertec);
lcd.print("%");
lcd.setCursor( 10,0);
lcd.print("H:");
lcd.print(DHT.humidity,0);
lcd.print(" %");
lcd.setCursor(10,1);
lcd.print("T:");
lcd.print(DHT.temperature, 0);
lcd.write(1);
lcd.print("C");
delay(250);
switch (key()){
case 5:
powertec += 10; //increase tec power by 10 %
break;
case 4:
powerfan += 10; // increase fan power by 10 %
break;
case 3:
powerfan -= 10; // decrease fan power by 10 %
break;
case 2:
powertec -= 10; // decrease tec by 10 %
break;
case 1:
lcd.clear();
lcd.print ("AUTO");
lcd.setCursor(10,0);
lcd.print("T:");
lcd.print(DHT.temperature,0);
lcd.setCursor(10,1);
lcd.print(DHT.humidity,0);
lcd.print("%");
if (DHT.temperature <=23) {
powerfan -=100;
powertec -=100;
}
else if (DHT.temperature > 23) {
powerfan +=100;
powertec +=100;
}
lcd.setCursor(0,0);
lcd.print("AUTO");
lcd.setCursor(0,1);
lcd.print(" ");
delay(2000);
break;
}
if(powerfan > 100) powerfan =100;
if(powerfan < 0) powerfan =0;
fan_level = map(powerfan, 0, 100, 0, 255);
if (powertec > 100) powertec = 100;
if (powertec <0) powertec = 0;
tec_level = map(powertec,0 ,100, 0, 200);
analogWrite(fan, fan_level);
analogWrite(tec, tec_level);
delay(50);
DHT.read11(dht_apin);
// put your main code here, to run repeatedly:
}
>
Thank you Kind people !!