This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
random_object_build_challenge_2023:random_build_wouter [2023/11/20 11:35] – wrusman | random_object_build_challenge_2023:random_build_wouter [2023/12/04 12:07] (current) – wrusman | ||
---|---|---|---|
Line 33: | Line 33: | ||
Het plaatje bovenop wordt mooi heet, de binnenkant niet zo koud als gehoopt, maar ik denk dat hij iets koels wel redelijk koel kan houden. | Het plaatje bovenop wordt mooi heet, de binnenkant niet zo koud als gehoopt, maar ik denk dat hij iets koels wel redelijk koel kan houden. | ||
+ | < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #define SENSORTOP_PIN | ||
+ | #define SENSORINSIDE_PIN | ||
+ | |||
+ | #define REFERENCE_RESISTANCE | ||
+ | #define NOMINAL_RESISTANCE | ||
+ | #define NOMINAL_TEMPERATURE | ||
+ | #define B_VALUE | ||
+ | |||
+ | //Define Variables we'll be connecting to | ||
+ | double Setpoint, Input, Output; | ||
+ | //Define the aggressive and conservative Tuning Parameters | ||
+ | |||
+ | double aggKp=4, aggKi=0.2, aggKd=1; | ||
+ | double consKp=1, consKi=0.05, | ||
+ | |||
+ | //Specify the links and initial tuning parameters | ||
+ | PID myPID(& | ||
+ | Thermistor* thermistorTop; | ||
+ | Thermistor* thermistorInside; | ||
+ | LiquidCrystal_I2C lcd(0x27, | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | Setpoint = 50; | ||
+ | |||
+ | thermistorTop = new NTC_Thermistor( | ||
+ | SENSORTOP_PIN, | ||
+ | REFERENCE_RESISTANCE, | ||
+ | NOMINAL_RESISTANCE, | ||
+ | NOMINAL_TEMPERATURE, | ||
+ | B_VALUE | ||
+ | ); | ||
+ | thermistorInside = new NTC_Thermistor( | ||
+ | SENSORINSIDE_PIN, | ||
+ | REFERENCE_RESISTANCE, | ||
+ | NOMINAL_RESISTANCE, | ||
+ | NOMINAL_TEMPERATURE, | ||
+ | B_VALUE | ||
+ | ); | ||
+ | myPID.SetMode(AUTOMATIC); | ||
+ | | ||
+ | lcd.init(); | ||
+ | lcd.init(); | ||
+ | // Print a message to the LCD. | ||
+ | lcd.backlight(); | ||
+ | lcd.setCursor(5, | ||
+ | lcd.print(" | ||
+ | delay(1000); | ||
+ | lcd.clear(); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | // Reads temperature | ||
+ | const double celsiusTop = thermistorTop-> | ||
+ | const double celsiusInside = thermistorInside-> | ||
+ | // Output of information | ||
+ | Serial.print(" | ||
+ | Serial.print(celsiusTop); | ||
+ | Serial.println(" | ||
+ | Serial.print(" | ||
+ | Serial.print(celsiusInside); | ||
+ | Serial.println(" | ||
+ | |||
+ | Input = celsiusTop; | ||
+ | | ||
+ | double gap = abs(Setpoint-Input); | ||
+ | if (gap < 10) | ||
+ | { // | ||
+ | myPID.SetTunings(consKp, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // | ||
+ | | ||
+ | } | ||
+ | | ||
+ | myPID.Compute(); | ||
+ | analogWrite(3, | ||
+ | Serial.print(" | ||
+ | Serial.println(255-Output); | ||
+ | Serial.println("" | ||
+ | | ||
+ | |||
+ | lcd.setCursor(0, | ||
+ | lcd.print(" | ||
+ | lcd.print(celsiusTop); | ||
+ | lcd.print(" | ||
+ | | ||
+ | lcd.setCursor(0, | ||
+ | lcd.print(" | ||
+ | lcd.print(celsiusInside); | ||
+ | lcd.print(" | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | </ | ||