Compare commits

..

No commits in common. "0b8e4d3a5c86c4692087c7644e474f1da8e50e48" and "7c12ac40f84360a5181f87a76daf74f700fc88fe" have entirely different histories.

View file

@ -2,67 +2,28 @@
#include <LiquidCrystal_I2C.h> // Support for PCF8574 --> LCD
#include <OneWire.h> // 1-Wiresupport for DS18B20
#include <DallasTemperature.h> // Easy reading of DS18B20
#include <PID_v1.h> // PID-Controller
#define ONE_WIRE_BUS 10 // Enable 1-Wirebus on digital 10 (PB2 - Pin16)
#define fan 8
#define wecktopf 9
LiquidCrystal_I2C lcd(0x3F,20,4); // declare LCD
OneWire oneWire(ONE_WIRE_BUS); // declare 1-Wirebus
DallasTemperature sensors(&oneWire); // declare sensors
// Define variables PID is connected to
double pidset, watertemp, output;
// PID adjustment
double Kp=2, Ki=5, Kd=1;
PID myPID(&watertemp, &output, &pidset, Kp, Ki, Kd, DIRECT);
int WindowSize = 5000;
unsigned long windowStartTime;
// Temp adjustment
int tempset;
float tempset;
float watertemp;
int poti;
// time
int onesecond = 1000;
unsigned long previousMillis;
// °C for LCD
byte customChar[8] = {
0b01110,
0b01010,
0b01010,
0b01110,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup() {
// Setup GPIO
pinMode(wecktopf, OUTPUT); // Output "Wecktopf"
pinMode(fan, OUTPUT); // Fan
pinMode(9, OUTPUT); // Output "Wecktopf"
pinMode(8, OUTPUT); // Fan
// Setup sensors
sensors.begin();
// Setup I2C-LCD
lcd.init();
lcd.backlight();
lcd.clear();
lcd.createChar(0, customChar);
lcd.setCursor(1, 0);
// Setup PID
windowStartTime = millis();
myPID.SetOutputLimits(0, WindowSize); //tell the PID to range between 0 and the full window size
myPID.SetMode(AUTOMATIC); //turn the PID on
// Greetings
lcd.print("Weckkubator 0.0.1");
delay(3000);
@ -71,34 +32,23 @@ void setup() {
}
void loop() {
//
settemp();
readtemp();
lcdoutput();
delay(100);
if (tempset >= watertemp) {
digitalWrite(9, HIGH);
// run pid
pid();
// update LCD
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= onesecond) {
settemp();
readtemp();
lcdoutput();
}
}
else {
digitalWrite(9, LOW);
//------------------------------------------
// PID-Controller
void pid() {
myPID.Compute();
/************************************************
* turn the output pin on/off based on pid output
************************************************/
if (millis() - windowStartTime > WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if (output < millis() - windowStartTime) digitalWrite(wecktopf, LOW);
else digitalWrite(wecktopf, HIGH);
}
//------------------------------------------
@ -118,32 +68,18 @@ void readtemp() {
void lcdoutput() {
// Output temperatureset
lcd.setCursor(0, 1);
lcd.print("set: ");
lcd.print("s:");
lcd.print(tempset);
lcd.write((byte)0);
lcd.print("C");
// Output watertemp
lcd.setCursor(0, 2);
lcd.print("temp: ");
lcd.setCursor(9, 1);
lcd.print("t:");
lcd.print(watertemp);
lcd.write((byte)0);
lcd.print("C");
lcd.print(" ");
// output PID
lcd.setCursor (0, 3);
lcd.print("output: ");
lcd.print(output);
lcd.print(" ");
}
//------------------------------------------
// Read Poti
void settemp() {
poti = analogRead(A3);
tempset = (18+(poti*0.07)); // range between 18°C and 18+1024*0,07 (~89°C)
pidset = tempset;
tempset = (poti*0.1);
}