Controller 3D printer kast met 3 fans en 3 DHT11 sensoren

Toon hier Uw afgeronde projecten aan anderen.
Berichten: 1
Geregistreerd: 10 Mrt 2022, 19:13

Controller 3D printer kast met 3 fans en 3 DHT11 sensoren

Berichtdoor SteefNL » 10 Mrt 2022, 19:54

Beste forum bezoekers,

sinds kort ben ik begonnen met het programmeren met behulp van de arduino. Inmiddels, na veel zoekwerk en vooral vele missers, heb ik uiteindelijk een systeem weten te maken dat werkt zoals ik het in mijn hoofd had.
Nu wil ik dit graag met jullie delen, om te horen of er verbeterpunten zijn in het wegschrijven van bepaalde zaken om het enigszins in te korten en te voorkomen dat het mogelijk na langere tijd draaien zal gaan vast lopen. Op dit moment gebruikt de schets 1214 bytes (59%) van mijn Arduino Uno.
Ik hoor graag verbeterpunten!

Samenvatting: Systeem voor het reguleren van de warmte en luchtvochtigheid binnen mijn 3D printer kast (ontwerp met 4 Ikea Lack tafels op elkaar en bovenste 3 openingen omheind met plexiglas).
Deze 3 kasten zijn middels 2 fans onderling verbonden en de derde fan aan de bovenzijde. Op level 1 (laagste niveau) is alle elektronica, level 2 (middelste niveau) staat de 3D printer, op level 3 (bovenste niveau) de 3D filament rollen.
Op elk niveau is een DHT-11 sensor die meet hoe warm en vochtig de ruimte is. En de minimale en maximale temperatuur zijn per level instelbaar. De status is af te lezen via een 16x2 LCD scherm (LCD1602) via I2C.

Ik wilde de code zowel als bijlage toevoegen als hieronder in tekst. Helaas is bijlage in .txt of .ino geen optie. Dus het ziet er nu iets minder fraai uit qua opmaak, maar maakt het niet minder werkend :).

Code:
//Includes:
#include <Wire.h> // Include Wire Library for I2C
#include <LiquidCrystal_I2C.h> // Include NewLiquidCrystal Library for I2C
#include "DHT.h"; // Include DHT Libraries from Adafruit

//Defines:
const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3; // Defines LCD pinout
const int i2c_addr = 0x27; // Defines I2C Address for Liquid_Crystal_I2C lcd

int temp1Min = 22; // Defines minimal temperature to stop cooling at level 1
int temp1Max = 25; // Defines maximal temperature to cool at 80% speed at level 1
int temp1OFF = 27; // Defines maximal temperature to cool at 100% speed at level 1
int fan1Speed = 0; // Defines initial fan 1 speed at PWM 0 (speed must be between 0 and 255)
int fan1LCD; // Defines fan 1 speed on LCD in percent

int temp2Min = 29; // Defines minimal temperature to stop cooling at level 2
int temp2Max = 38; // Defines maximal temperature to cool at 80% speed at level 2
int temp2OFF = 45; // Defines maximal temperature to cool at 100% speed at level 2
int fan2Speed = 0; // Defines initial fan 2 speed at PWM 0 (speed must be between 0 and 255)
int fan2LCD; // Defines fan 2 speed on LCD in percent

int temp3Min = 30; // Defines minimal temperature to stop cooling at level 3
int temp3Max = 32; // Defines maximal temperature to cool at 80% speed at level 3
int temp3OFF = 34; // Defines maximal temperature to cool at 100% speed at level 3
int fan3Speed = 0; // Defines initial fan 3 speed at PWM 0 (speed must be between 0 and 255)
int fan3LCD; // Defines fan 3 speed on LCD in percent

float hum1; // Stores humidity 1 value in percent
float hum2; // Stores humidity 2 value in percent
float hum3; // Stores humidity 3 value in percent
float temp1; // Stores temperature 1 value in Celsius
float temp2; // Stores temperature 2 value in Celcius
float temp3; // Stores temperature 3 value in Celcius
float temp1Ver = (temp1Max-temp1Min); // Calculates difference between minimum and maximal temperature at level 1
float temp1Mid = ((temp1Ver)/2)+temp1Min; // Define middle temperature between minimal and maximal temperature at level 1
float temp2Ver = (temp2Max-temp2Min); // Calculates difference between minimum and maximal temperature at level 2
float temp2Mid = ((temp2Ver)/2)+temp2Min; // Define middle temperature between minimal and maximal temperature at level 2
float temp3Ver = (temp3Max-temp3Min); // Calculates difference between minimum and maximal temperature at level 3
float temp3Mid = ((temp3Ver)/2)+temp3Min; // Define middle temperature between minimal and maximal temperature at level 3

#define DHTTYPE DHT11 // DHT Type is DHT 11 for all sensors
#define DHTPIN 6 // DHT-11(1) Output Pin connection
#define DHTPIN 7 // DHT-11(2) Output Pin connection
#define DHTPIN 5 // DHT-11(3) Output Pin connection
#define FAN1PIN 8 // Set pin 8 as Fan 1 pin
#define FAN2PIN 9 // Set pin 9 as Fan 2 pin
#define FAN3PIN 10 // Set pin 10 as Fan 3 pin

DHT dht1(6, DHTTYPE); // Setup DHT1 sensor for normal 16mhz Arduino
DHT dht2(7, DHTTYPE); // Setup DHT2 sensor for normal 16mhz Arduino
DHT dht3(5, DHTTYPE); // Setup DHT3 sensor for normal 16mhz Arduino

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE); // Defines LCD I2C adress and display connections

byte bar00[8] ={ 0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000}; // Defines new character, bar fan 00 %
byte bar20[8] ={ 0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b10000,0b00000}; // Defines new character, bar fan 20 %
byte bar40[8] ={ 0b00000,0b00000,0b00000,0b00000,0b00000,0b01000,0b11000,0b00000}; // Defines new character, bar fan 40 %
byte bar60[8] ={ 0b00000,0b00000,0b00000,0b00000,0b00100,0b01100,0b11100,0b00000}; // Defines new character, bar fan 60 %
byte bar80[8] ={ 0b00000,0b00000,0b00000,0b00010,0b00110,0b01110,0b11110,0b00000}; // Defines new character, bar fan 80 %
byte bar100[8] ={ 0b00000,0b00000,0b00001,0b00011,0b00111,0b01111,0b11111,0b00000}; // Defines new character, bar fan 100 %


void setup() {
Wire.setClock(10000); // Set I2C clockspeed to 10.000 instead off default 100.000
pinMode(FAN1PIN, OUTPUT); // Set Fan 1 pin as output

Serial.begin(9600); // Set serial speed at 9600 baut
lcd.begin(16,2); // Set display type as 16 char, 2 rows

dht1.begin(); // Initialize DHT-11 (1)
dht2.begin(); // Initialize DHT-11 (2)
dht3.begin(); // Initialize DHT-11 (3)

lcd.createChar(0, degree); // Create 8 byte character degree
lcd.createChar(1, bar00); // Create 8 byte character bar empty
lcd.createChar(2, bar20); // Create 8 byte character bar 20% speed
lcd.createChar(3, bar40); // Create 8 byte character bar 40% speed
lcd.createChar(4, bar60); // Create 8 byte character bar 60% speed
lcd.createChar(5, bar80); // Create 8 byte character bar 80% speed
lcd.createChar(6, bar100); // Create 8 byte character bar full speed

temp1= dht1.readTemperature(); // Get Temperature value 1
temp2= dht2.readTemperature(); // Get Temperature value 2
temp3= dht3.readTemperature(); // Get Temperature value 3

char buffer[70]; // Creates char array called buffer with 70 byte amount of space available
sprintf(buffer,"Level 1: Min temp at: %d C, Max temp at: %d C, Current temp: ", // Make string function wich will combine text and val for sensor 1
temp1Min, temp1Max) ; // Values needed in string
Serial.print(buffer); // Serial print buffer string to monitor
Serial.println(temp1,0); // Serial print current temperature sensor 1
delay(1000); // Delay 1 second for verifying program starts

char buffer1[70]; // Creates char array called buffer1 with 70 byte amount of space available
sprintf(buffer1,"Level 2: Min temp at: %d C, Max temp at: %d C, Current temp: ", // Make string function wich will combine text and val for sensor 2
temp2Min, temp2Max) ; // Values needed in string
Serial.print(buffer1); // Serial print buffer string to monitor
Serial.println(temp2,0); // Serial print current temperature sensor 2
delay(1000); // Delay 1 second for verifying program starts

char buffer2[70]; // Creates char array called buffer2 with 70 byte amount of space available
sprintf(buffer2,"Level 3: Min temp at: %d C, Max temp at: %d C, Current temp: ", // Make string function wich will combine text and val for sensor 3
temp3Min, temp3Max) ; // Values needed in string
Serial.print(buffer2); // Serial print buffer string to monitor
Serial.println(temp3,0); // Serial print current temperature sensor 3
delay(1000); // Delay 1 second for verifying program starts

lcd.setCursor(5,0); // Placing cursor at line 1 (of 2) at position 5
lcd.print("WELCOME");Serial.println("WELCOME"); // LCD & Monitor Print startup program to verify working
delay(500); // Delay 1/2 second
lcd.setCursor(3,1); // Placing cursor at line 2 (of 2) at position 3

lcd.print("LOADING");Serial.print("LOADING"); // Printing text to serial monitor and LCD
delay(500); // Delay 1/2 second
lcd.setCursor(11,1); // Placing cursor at line 2 (of 2) at position 11
lcd.print(".");Serial.print("."); // Printing text to serial monitor and LCD
delay(500); // Delay 1/2 second
lcd.setCursor(12,1); // Placing cursor at line 2 (of 2) at position 12
lcd.print(".");Serial.print("."); // Printing text to serial monitor and LCD
delay(500); // Delay 1/2 second
lcd.setCursor(13,1); // Placing cursor at line 2 (of 2) at position 13
lcd.print(".");Serial.println("."); // Printing text to serial monitor and LCD
delay(1000); // Delay for 1 second

lcd.clear(); // Clear LCD screen for following test
lcd.setCursor(2,0); // Placing cursor at line 1 (of 2) at position 2
lcd.print("TESTING FAN 1");Serial.print("Testing FAN 1 "); // Printing text : Testing Fan
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN1 60% ");Serial.print("60% "); // Printing text to serial monitor and LCD
lcd.write(4); // LCD write character 4; bar 60% speed
analogWrite(FAN1PIN, 155); // Testing Fan at 60% speed
delay(1000); // Delay for 2 seconds
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN1 80% "); Serial.print("80% "); // Printing text to serial monitor and LCD
lcd.write(5); // LCD write character 5; bar 80% speed
analogWrite(FAN1PIN, 205); // Testing Fan at 80% speed
delay(1000); // Delay for 2 seconds
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN1 100% ");Serial.println("100% "); // Printing text to serial monitor and LCD
lcd.write(6); // LCD write character 6; bar 100% speed
analogWrite(FAN1PIN, 255); // Testing Fan at 100% speed
delay(1000); // Delay for 2 seconds
analogWrite(FAN1PIN, 0); // Write Fan1 pin Low (0 Volts, 0 PWM)

lcd.clear(); // Clear LCD screen
lcd.setCursor(2,0); // Placing cursor at line 1 (of 2) at position 2
lcd.print("TESTING FAN 2");Serial.print("Testing FAN 2 "); // Printing text : Testing Fan 2
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN2 60% ");Serial.print("60% "); // Printing text to serial monitor and LCD
lcd.write(4); // LCD write character 4; bar 60% speed
analogWrite(FAN2PIN, 155); // Testing Fan 2 at 60% speed
delay(1000); // Delay for 2 seconds
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN2 80% "); Serial.print("80% "); // Printing text to serial monitor and LCD
lcd.write(5); // LCD write character 5; bar 80% speed
analogWrite(FAN2PIN, 205); // Testing Fan 2 at 80% speed
delay(1000); // Delay for 2 seconds
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN2 100% ");Serial.println("100% "); // Printing text to serial monitor and LCD
lcd.write(6); // LCD write character 6; bar 100% speed
analogWrite(FAN2PIN, 255); // Testing Fan 2 at 100% speed
delay(1000); // Delay for 2 seconds
analogWrite(FAN2PIN, 0); // Write Fan2 pin Low (0 Volts, 0 PWM)

lcd.clear(); // Clear LCD screen
lcd.setCursor(2,0); // Placing cursor at line 1 (of 2) at position 2
lcd.print("TESTING FAN 3");Serial.print("Testing FAN 3 "); // Printing text : Testing Fan 3
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN3 60% ");Serial.print("60% "); // Printing text to serial monitor and LCD
lcd.write(4); // LCD write character 4; bar 60% speed
analogWrite(FAN3PIN, 155); // Testing Fan 3 at 60% speed
delay(000); // Delay for 2 seconds
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN3 80% "); Serial.print("80% "); // Printing text to serial monitor and LCD
lcd.write(5); // LCD write character 5; bar 80% speed
analogWrite(FAN3PIN, 205); // Testing Fan 3 at 80% speed
delay(1000); // Delay for 2 seconds
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("FAN3 100% ");Serial.println("100% "); // Printing text to serial monitor and LCD
lcd.write(6); // LCD write character 6; bar 100% speed
analogWrite(FAN3PIN, 255); // Testing Fan 3 at 100% speed
delay(1000); // Delay for 2 seconds
analogWrite(FAN3PIN, 0); // Write Fan3 pin Low (0 Volts, 0 PWM)

lcd.clear(); // Clear LCD screen

lcd.setCursor(1,0); // Placing cursor at line 1 (of 2) at position 1
lcd.print("CHECKING TEMP"); // Printing text to LCD
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("LEVEL SETTINGS"); // Printing text to LCD
delay(1000); // Delay for 1 second

lcd.clear(); // Clear LCD screen
lcd.setCursor(0,0); // Placing cursor at line 1 (of 2) at position 0
lcd.print("SETTINGS LEVEL 1"); // Printing text to LCD
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("MIN: "); // Printing text to LCD
lcd.print(temp1Min); // Printing temp1Min value to LCD
lcd.setCursor(8,1); // Placing cursor at line 2 (of 2) at position 8
lcd.print("MAX: "); // Printing text to LCD
lcd.print(temp1Max); // Printing temp1Max value to LCD
delay(2000); // Delay for 2 seconds

lcd.clear(); // Clear LCD screen
lcd.setCursor(0,0); // Placing cursor at line 1 (of 2) at position 0
lcd.print("SETTINGS LEVEL 2"); // Printing text to LCD
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("MIN: "); // Printing text to LCD
lcd.print(temp2Min); // Printing temp2Min value to LCD
lcd.setCursor(8,1); // Placing cursor at line 2 (of 2) at position 8
lcd.print("MAX: "); // Printing text to LCD
lcd.print(temp2Max); // Printing temp2Max value to LCD
delay(2000); // Delay for 2 seconds

lcd.clear(); // Clear LCD screen
lcd.setCursor(0,0); // Placing cursor at line 1 (of 2) at position 0
lcd.print("SETTINGS LEVEL 3"); // Printing text to LCD
lcd.setCursor(0,1); // Placing cursor at line 2 (of 2) at position 0
lcd.print("MIN: "); // Printing text to LCD
lcd.print(temp3Min); // Printing temp2Min value to LCD
lcd.setCursor(8,1); // Placing cursor at line 2 (of 2) at position 8
lcd.print("MAX: "); // Printing text to LCD
lcd.print(temp3Max); // Printing temp2Max value to LCD
delay(2000); // Delay for 2 seconds

lcd.clear();
lcd.setCursor(2,0); // Placing cursor at line 1 (of 2) at position 2
lcd.print("INITIALIZING");Serial.print("INITIALIZING "); // Printing text to serial monitor and LCD
lcd.setCursor(2,1); // Placing cursor at line 2 (of 2) at position 2
lcd.print("TEMP SENSORS");Serial.println("TEMP SENSORS"); // Printing text to serial monitor and LCD
delay(2000); // Delay for 2 seconds for warming up Sensors
}

void loop(){

lcd.clear(); // Clear the display for loop function

hum1 = dht1.readHumidity(); // Get Humidity value 1
temp1= dht1.readTemperature(); // Get Temperature value 1
hum2 = dht2.readHumidity(); // Get Humidity value 2
temp2= dht2.readTemperature(); // Get Temperature value 2
hum3 = dht3.readHumidity(); // Get Humidity value 3
temp3= dht3.readTemperature(); // Get Temperature value 3

Serial.print("Temperature sensor 1 = "); // Serial print text to monitor
Serial.print(temp1,0); // Serial print temperature 1 to monitor for checkup
Serial.print(" sensor 2 = "); // Serial print text to monitor for sensor 2
Serial.print(temp2,0); // Serial print temperature 2 to monitor for checkup
Serial.print(" sensor 3 = "); // Serial print text to monitor for sensor 3
Serial.println(temp3,0); // Serial print temperature 3 to monitor for checkup

lcd.setCursor(1,0); // Places LCD cursor at line 1 (of 2), at position 1
lcd.print(temp1,0); // Print temperatures on top line, with 0 decimals
lcd.print("C"); // Print celsius after temp1

if(temp1 < temp1Min){ // Set first condition; if current temp is lower than temp1Min, set Fan 1 off
fan1Speed = 0; // Sets fan1speed at 0 PWM
lcd.write(1); // LCD write character 1; bar 00% speed
digitalWrite(FAN1PIN, LOW);} // Sets Fan1 pin low (0 volts, 0 PWM)

if((temp1 >= temp1Min) && (temp1 <temp1Mid)){ // Set second condition; if current temp is higher than temp1Min, but lower than temp1Mid, set Fan 1 on
fan1Speed = map(temp1, temp1Min, temp1Mid, 102, 125); // Fan1speed is mapped for controlling PWM
fan1LCD = map(temp1, temp1Min, temp1Mid, 40, 50); // Fan1LCD is mapped for showing percent speed on LCD
lcd.write(3); // LCD write character 3; bar 40% speed
analogWrite(FAN1PIN, fan1Speed);} // Controlling Fan1 output from mapping fan1speed

if((temp1 >= temp1Mid) && (temp1 < temp1Max)){ // Set third condition; if current temp is higher than temp1Mid, but lower than temp1Max, set Fan 1 on
fan1Speed = map(temp1, temp1Mid, temp1Max, 125, 204); // Fan1speed is mapped for controlling PWM
fan1LCD = map(temp1, temp1Mid, temp1Max, 50, 80); // Fan1LCD is mapped for showing percent speed on LCD
lcd.write(4); // LCD write character 4; bar 60% speed
analogWrite(FAN1PIN, fan1Speed);} // Controlling Fan1 output from mapping fan1speed

if((temp1 >= temp1Max)&&(temp1<temp1OFF)){ // Set fourth condition; if current temp is higher than temp1Max, but lower than temp1OFF, set Fan 1 on
lcd.write(5); // LCD write character 5; bar 80% speed
analogWrite(FAN1PIN, 204);} // Controlling Fan1 output at 204 PWM (80%) out of 255 PWM

if(temp1 >= temp1OFF){ // Set final condition; if current temp is higher than temp1OFF, set Fan 1 on full
lcd.write(6); // LCD write character 6; bar 100% speed
analogWrite(FAN1PIN, 255);} // Controlling Fan1 output at 255 PWM (100%) out of 255 PWM


lcd.setCursor(6,0); // Placing cursor at line 1 (of 2) at position 6
lcd.print(temp2,0); // Printing temperature 2 on LCD with 0 decimals
lcd.print("C "); // Print celsius after temp2

if(temp2 < temp2Min){ // Set first condition; if current temp is lower than temp2Min, set Fan 2 off
fan2Speed = 0; // Sets fan2speed at 0 PWM
lcd.setCursor(9,0); // Placing cursor at line 1 (of 2) at position 9
lcd.write(1); // LCD write character 1; bar 00% speed
digitalWrite(FAN2PIN, LOW);} // Sets Fan1 pin low (0 volts, 0 PWM)

if((temp2 >= temp2Min) && (temp2 <temp2Mid)){ // Set second condition; if current temp is higher than temp2Min, but lower than temp2Mid, set Fan 2 on
fan2Speed = map(temp2, temp2Min, temp2Mid, 102, 125); // Fan2speed is mapped for controlling PWM
fan2LCD = map(temp2, temp2Min, temp2Mid, 40, 50); // Fan2LCD is mapped for showing percent speed on LCD
lcd.setCursor(9,0); // Placing cursor at line 1 (of 2) at position 9
lcd.write(3); // LCD write character 3; bar 40% speed
analogWrite(FAN2PIN, fan2Speed);} // Controlling Fan2 output from mapping fan2speed

if((temp2 >= temp2Mid) && (temp2 < temp2Max)){ // Set third condition; if current temp is higher than temp2Mid, but lower than temp2Max, set Fan 2 on
fan2Speed = map(temp2, temp2Mid, temp2Max, 125, 204); // Fan2speed is mapped for controlling PWM
fan2LCD = map(temp2, temp2Mid, temp2Max, 50, 80); // Fan2LCD is mapped for showing percent speed on LCD
lcd.setCursor(9,0); // Placing cursor at line 1 (of 2) at position 9
lcd.write(4); // LCD write character 4; bar 60% speed
analogWrite(FAN2PIN, fan2Speed);} // Controlling Fan2 output from mapping fan2speed

if((temp2 >= temp2Max)&&(temp2<temp1OFF)){ // Set fourth condition; if current temp is higher than temp2Max, but lower than temp2OFF, set Fan 2 on
lcd.setCursor(9,0); // Placing cursor at line 1 (of 2) at position 9
lcd.write(5); // LCD write character 5; bar 80% speed
analogWrite(FAN2PIN, 220);} // Controlling Fan2 output at 204 PWM (80%) out of 255 PWM

if(temp2 >= temp2OFF){ // Set final condition; if current temp is higher than temp2OFF, set Fan 2 on full
lcd.setCursor(9,0); // Placing cursor at line 1 (of 2) at position 9
lcd.write(6); // LCD write character 6; bar 100% speed
analogWrite(FAN2PIN, 255);} // Controlling Fan2 output at 255 PWM (100%) out of 255 PWM


lcd.setCursor(11,0); // Placing cursor at line 1 (of 2) at position 11
lcd.print(temp3,0); // Printing temperature 3 on LCD with 0 decimals
lcd.print("C"); // Print celsius after temp3

if(temp3 < temp3Min){ // Set first condition; if current temp is lower than temp3Min, set Fan 3 off
fan3Speed = 0; // Sets fan3speed at 0 PWM
lcd.setCursor(14,0); // Placing cursor at line 1 (of 2) at position 14
lcd.write(1); // LCD write character 1; bar 00% speed
digitalWrite(FAN3PIN, LOW);} // Sets Fan3 pin low (0 volts, 0 PWM)


if((temp3 >= temp3Min) && (temp3 <temp3Mid)){ // Set second condition; if current temp is higher than temp3Min, but lower than temp3Mid, set Fan 3 on
fan3Speed = map(temp3, temp3Min, temp3Mid, 102, 125); // Fan3speed is mapped for controlling PWM
fan3LCD = map(temp3, temp3Min, temp3Mid, 40, 50); // Fan3LCD is mapped for showing percent speed on LCD
lcd.setCursor(14,0); // Placing cursor at line 1 (of 2) at position 14
lcd.write(3); // LCD write character 3; bar 40% speed
analogWrite(FAN3PIN, fan3Speed);} // Controlling Fan3 output from mapping fan3speed

if((temp3 >= temp3Mid) && (temp3 < temp3Max)){ // Set third condition; if current temp is higher than temp33Mid, but lower than tem3Max, set Fan 3 on
fan3Speed = map(temp3, temp3Mid, temp3Max, 125, 204); // Fan3speed is mapped for controlling PWM
fan3LCD = map(temp3, temp3Mid, temp3Max, 50, 80); // Fan3LCD is mapped for showing percent speed on LCD
lcd.setCursor(14,0); // Placing cursor at line 1 (of 2) at position 14
lcd.write(4); // LCD write character 4; bar 60% speed
analogWrite(FAN3PIN, fan3Speed);} // Controlling Fan3 output from mapping fan3speed

if((temp3 >= temp3Max)&&(temp3<temp3OFF)){ // Set fourth condition; if current temp is higher than temp3Max, but lower than temp3OFF, set Fan 3 on
lcd.setCursor(14,0); // Placing cursor at line 1 (of 2) at position 14
lcd.write(5); // LCD write character 5; bar 80% speed
analogWrite(FAN3PIN, 220);} // Controlling Fan3 output at 204 PWM (80%) out of 255 PWM

if(temp3 >= temp3OFF){ // Set final condition; if current temp is higher than temp3OFF, set Fan 3 on full
lcd.setCursor(14,0); // Placing cursor at line 1 (of 2) at position 14
lcd.write(6); // LCD write character 6; bar 100% speed
analogWrite(FAN3PIN, 255);} // Controlling Fan3 output at 255 PWM (100%) out of 255 PWM

lcd.setCursor(1,1); // Placing cursor at line 2 (of 2) at position 1
lcd.print(hum1,0); // Print humidity sensor 1 on bottom line
lcd.print("%"); // Print percent after sensor 1
lcd.setCursor(6,1); // Placing cursor at line 2 (of 2) at position 6
lcd.print(hum2,0); // Print humidity sensor 2 on bottom line
lcd.print("% "); // Print percent after sensor 2
lcd.print(hum3,0); // Print humidity sensor 3 on bottom line
lcd.print("%"); // Print percent after sensor 3
delay(2000); // Delay for 2 second for restarting loop()
}

Alvast bedankt met het meekijken en meedenken.

Vriendelijke groet,

Steef

Advertisement

Terug naar Afgeronde projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 1 gast