Arduino Elektronik Örnekler ve Projeler

MAX6675 K-Termokupl – Dijital Dönüştürücü IC kullanan Arduino PID Sıcaklık Kontrol Cihazı

Bu yazıda , 3D yazıcının sıcak ucunun sıcaklığını kontrol etmek için kullanılabilecek bir PID Kontrolör tabanlı Isıtıcı yapmaya karar verdik veya cihazı biraz değiştirerek DC Havya sıcaklığını çok verimli ve biraz kontrol edebilir. daha fazla ince ayar ve bir TRIAC’ı kontrol edebilirsiniz ve bu, bir AC motorun veya bir AC ısıtma elemanının RPM’sini kontrol edebilir, PID kontrolü ile olasılıklar sınırsızdır.

Sıcaklık PID Denetleyicisi Nedir?


Adından da anlaşılacağı gibi, bir sıcaklık PID denetleyicisi sıcaklıkla ilgilenir, PID sıcaklık kontrolü, işlemin doğruluğunu artıran kapalı döngü bir kontrol algoritmasıdır. PID sıcaklık kontrolü, mevcut sıcaklık ve ayar noktası arasındaki farkı hesaplamak için matematiksel bir formül kullanarak çalışır. Ardından, hedef sıcaklığın sabit kalmasını sağlamak için gerekli gücü sağlamaya çalışır , bu sadece çevresel etkiyi azaltmakla kalmaz, aynı zamanda geleneksel açma-kapama kontrol mekanizmasında bulunabilen aşırılıkları da azaltır.

Sıcaklık PID Kontrolörü nasıl çalışır?

İlk önce herhangi bir PID kontrolünde olduğu gibi, çıktının veya kontrolörün ne yapmasını istediğimizin farkında olmamız gerekir, bu proje için ısıtma elemanının belirli bir sıcaklığını korumak istiyoruz (o sıcaklığı döner yardımıyla ayarlayacağız) enkoder) bu nedenle sıcaklığı korumak için sıcaklıktan okumamız gerekiyor, bunun için MAX6675 Soğuk Bağlantılı Kompanzasyonlu K-Termokupl – Dijital Dönüştürücü IC ile birlikte  K tipi bir termokupl kullanıyoruz  yüzlerce santigrat dereceyi herhangi bir sorun olmadan ölçebilir. Ve termokupldan gelen sıcaklık okuması geri besleme görevi görür. Şimdi ulaşmak istediğimiz sıcaklığı ayarladığımıza ve sıcaklık değerinin gerçek zamanlı bir okumasına sahip olduğumuza göre, kontrolör hata değerini hesaplayabilir ve orantısal integral ve türev kontrolü yardımıyla sistem bu proje için hedefine ulaşabilir. hesaplanan çıkış değeri ile bir PWM sinyalini kontrol edeceğiz. Bir böyle olduğu  Sıcaklık Tabanlı PID kontrolör  çalışır.

MAX6675 K-Termokupl IC Çalışması 

MAX6675 K-Termokupl IC Çalışması
MAX6675 K-Termokupl IC Çalışması

İşlevi  termokupl  için  iki ucu arasında bir sıcaklık farkı algılamak  termokupl teller. Termokuplun sıcak bağlantısı 0°C ile +1023.75°C arasında okunabilir. Soğuk uç (MAX6675’in monte edildiği kartın ortam sıcaklığı) sadece -20°C ile +85°C arasında değişebilir. Soğuk uçtaki sıcaklık dalgalanırken, MAX6675 karşı uçtaki sıcaklık farkını doğru bir şekilde algılamaya devam eder. MAX6675 , soğuk bağlantı telafisi ile ortam sıcaklığındaki değişiklikleri algılar ve düzeltir . Cihaz, sıcaklık algılayıcı diyot kullanarak ortam sıcaklığı okumasını bir voltaja dönüştürür. Gerçek termokupl sıcaklık ölçümünü yapmak için MAX6675, termokuplun çıkışından ve algılama diyottan voltajı ölçer. Cihazın dahili devresi, termokuplun sıcak bağlantı sıcaklığını hesaplamak için diyotun voltajını (ortam sıcaklığını algılama) ve termokupl voltajını (uzak sıcaklığı algılama eksi ortam sıcaklığını algılama) ADC’de depolanan dönüştürme işlevine geçirir. MAX6675’ten optimum performans, termokupl soğuk bağlantısı ve MAX6675 aynı sıcaklıkta olduğunda elde edilir. MAX6675, termokuplun sinyalini ADC’nin giriş kanallarıyla uyumlu bir voltaja dönüştürmek için sinyal koşullandırma donanımı içerir. T+ ve T girişleri, termokupl tellerinden kaynaklanan gürültü hatalarının girişini azaltan dahili devrelere bağlanır. Daha fazla bilgi şurada bulunabilir:

PID Etkinleştirilmiş Sıcaklık Kontrol Cihazı oluşturmak için Gerekli Bileşenler
PID Malzemeler
PID Malzemeler

MAX6675 tabanlı PID Kontrollü Isıtıcıyı oluşturmak için gereken bileşenler   aşağıda listelenmiştir, bu devreyi çok genel bileşenlerle tasarladık, bu da çoğaltma işlemini çok kolaylaştırıyor.

  • Arduino Nano – 1
  • 128 X 64 OLED Ekran – 1
  • Genel Döner Kodlayıcı – 1
  • MAX6675 Modül – 1
  • K-tipi Termokupl – 1
  • Ekmek tahtası – 1
  • Jumper Telleri – 1
PID Etkin Sıcaklık Kontrol Cihazı Devre Şeması
Devre Şeması
Devre Şeması

Bu projemizde  MAX6675 K tipi Termokupl sensörünü  kullanarak termokupldan gelen sıcaklık verilerini okuyacağız ve bu bölümde şema yardımıyla tüm detayları anlatacağız. Size bu devrede neler olduğuna dair kısa bir genel bakış vereyim. MAX6675, Soğuk Bağlantı Dengelemeli K- Termokupl – Dijital Dönüştürücü  modülüdür ve şemaya göre Arduino’ya  bağlanır. Arduino’nun +5V beslemesi ile devreye güç sağlanmaktadır. Ayrıca sıcaklığı ayarlamak ve modları değiştirmek için genel bir Döner kodlayıcı kullanıyoruz.

Bağlanmış Hali
Bağlanmış Hali
MAX6675 tabanlı PID Etkin Sıcaklık Kontrol Cihazı Arduino Kodu

Bu projede kullanılan kodun tamamı bu sayfanın altında bulunabilir. Gerekli başlık dosyalarını ve kaynak dosyalarını ekledikten sonra Arduino kodunu hatasız bir şekilde doğrudan derleyebilmelisiniz. Sen indirebilirsiniz  PID kontrolör kütüphane, MAX6675 Kütüphanesi, AAdafruit_SSD1306 Kitaplığı  aşağıda verilen bağlantıdan, yoksa kütüphane kurmak tahta yöneticisi yöntemini kullanabilirsiniz.

Kodun basit bir açıklaması yorum olarak verilmiştir ve bu bölümde bu konuda biraz daha derinlemesine gideceğiz. Öncelikle gerekli tüm kütüphaneleri dahil ederek başlıyoruz, ardından enkoderi okumak, OLED ve MAX6675 Termokupl sıcaklık sensörünü sürmek için gerekli tüm pinleri tanımlıyoruz. Bu yapıldıktan sonra, Kp, Ki ve Kd için tüm değerleri tanımlarız ve gerekli tüm değişkenleri dahil ederiz.

Ardından, kodumuz için  __Kp ,  __Ki  ve  __Kd değerlerini tanımladık  . Bu üç sabit, kodumuz için çıktı yanıtını ayarlamaktan sorumludur. Lütfen bu proje için sabitleri ayarlamak için deneme yanılma yöntemini kullandığımı unutmayın, ancak projeniz için gerekliyse değerleri hesaplayabilirsiniz.

/*In this section we have defined the gain values for the
 * proportional, integral, and derivative controller I have set
 * the gain values with the help of trial and error methods.
*/
#define __Kp 30 // Proportional constant
#define __Ki 0.7 // Integral Constant
#define __Kd 200 // Derivative Constant

Daha sonra, gerekli tüm değişkenleri bildiririz ve biri PID için biri OLED için diğeri termokupl için sonuncusu olmak üzere üç örnek oluştururuz. Değişken  clockPin  ve  clockPinState ,  filtreleme ve  encoder_btn_count  Kodlayıcınızdan veri okumak için kullanılan dört  temperature_value_c  termokupl gelen sıcaklık okuma tutan, nihayet  encoder_btn_count  kodlamak düğmeye basıldığında kaç kez tutar.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <PIDController.h>
#include "max6675.h"
// Define Rotary Encoder Pins
#define CLK_PIN 3
#define DATA_PIN 4
#define SW_PIN 2
// MAX6675 Pins
#define thermoDO 8
#define thermoCS 9
#define thermoCLINE 10
// Mosfet Pin
#define mosfet_pin 11
// Serial Enable
#define __DEBUG__
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
int clockPin; // Placeholder por pin status used by the rotary encoder
int clockPinState; // Placeholder por pin status used by the rotary encoder
int set_temperature = 1; // This set_temperature value will increas or decreas if when the rotarty encoder is turned
float temperature_value_c = 0.0; // stores temperature value
long debounce = 0; // Debounce delay
int encoder_btn_count = 0; // used to check encoder button press
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO); // Create an instance for the MAX6675 Sensor Called "thermocouple"
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);// Create an instance for the SSD1306 128X64 OLED "display"
PIDController pid; // Create an instance of the PID controller class, called "PID"

Ardından, kurulum işlevine sahibiz. Kurulum işlevinde, önce seri monitörü hata ayıklama için etkinleştiririz, ancak  Serial.begin()  yöntemi, kodumuz tamamlandıktan sonra seri monitörü kolayca devre dışı bırakabilmemiz için bir #ifdef  ve  #endif  ifadesiyle sarılır.

void setup() {
#ifdef __DEBUG__
  Serial.begin(9600);
#endif

Ardından, projemizin çalışması için gerekli olan tüm pinlerimizi giriş ve çıkış olarak ayarladık.

pinMode(mosfet_pin, OUTPUT); // MOSFET output PIN
  pinMode(CLK_PIN, INPUT); // Encoer Clock Pin
  pinMode(DATA_PIN, INPUT); //Encoder Data Pin
  pinMode(SW_PIN, INPUT_PULLUP);// Encoder SW Pin

Ardından, PID örneğinin start()  yöntemini çağırarak PID denetleyicisini  başlatıyoruz. Daha sonra setpoint()  yöntemini kullanarak setpoint ekliyoruz  , PID algoritması çıktıyı kontrol ederek değere ulaşmaya çalışacak. Sonra  tune()  yöntemini çağırırız ,  burası __Kp , __Ki  ve  __Kd için tüm değerleri  koyduğumuz yerdir. Son olarak, PID denetleyicisi için bir sınır belirledik, bu sınırlayıcı hesaplanan çıktının sınır içinde kalmasına izin verecek, bu da hesaplanan çıktının PWM değerimiz için 255 olan belirli bir seviyenin ötesine geçmemesini sağlar.

pid.begin();          // initialize the PID instance
pid.setpoint(150);    // The "goal" the PID controller tries to "reach"
pid.tune(__Kp, __Ki,__Kd);    // Tune the PID, arguments: kP, kI, kD
pid.limit(0, 255);    // Limit the PID output between 0 and 255, this is important to get rid of integral windup!

Daha sonra ekranın müsait olup olmadığını kontrol ediyoruz, ekran mevcutsa kod devam edecek ve ekran mevcut değilse bir hata yazdıracak.

if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
#ifdef __DEBUG__
    Serial.println(F("SSD1306 allocation failed"));
#endif
    for (;;); // Don't proceed, loop forever
}

Ardından, ekranı ayarlıyoruz ve ekranı döndürerek ve ekrana bir açılış ekranı ekerek başlıyoruz , ardından ekranı  temizliyoruz , setTextSize ve  setTextColour’u  beyaza ayarlıyoruz . Ardından imleci farklı bir konuma ayarlayıp ekrana PID Temperatur Control  yazdırıyoruz  ve 2 saniyelik gecikme ile bitiriyoruz.

display.setRotation(2); //Rotate the Display
display.display(); //Show initial display buffer contents on the screen -- the library initializes this with an Adafruit splash screen.
display.clearDisplay(); // Cleear the Display
display.setTextSize(2); // Set text Size
display.setTextColor(WHITE); // set LCD Colour
display.setCursor(48, 0); // Set Cursor Position
display.println("PID"); // Print the this Text
display.setCursor(0, 20);  // Set Cursor Position
display.println("Temperatur"); // Print the this Text
display.setCursor(22, 40); // Set Cursor Position
display.println("Control"); // Print the this Text
display.display(); // Update the Display
delay(2000); // Delay of 200 ms

Ardından  set_temp()  fonksiyonumuz var. Bu fonksiyonda ısıtıcının sıcaklığını ayarlıyoruz ve düğme durumunu kontrol ediyoruz, durum iki ise önce ekran setini temizliyoruz metin boyutunu ayarlıyoruz ve ayarlanan sıcaklığı ekrana yazdırıyoruz. Daha sonra , adından da anlaşılacağı gibi ,  read_encoder()  işlevine sahibiz, kodlayıcıyı okuruz ve kodlayıcının saat yönünde veya saat yönünün tersine döndüğünü kontrol ederiz, kodlayıcı saat yönünde dönüyorsa sayacı artırırız, kodlayıcı saat yönünün tersine dönüyorsa sayacı artırırız tezgah. Son olarak enkoder butonunun durumunu da enkoder butonu ile kontrol ediyoruz ve sıcaklık set modu ile monitör modu arasında geçiş yapabiliyoruz.

void set_temp(){
  if (encoder_btn_count == 2) // check if the button is pressed twice and its in temperature set mode.
  {
    display.clearDisplay(); // clear the display
    display.setTextSize(2); // Set text Size
    display.setCursor(16, 0); // set the diplay cursor
    display.print("Set Temp."); // Print Set Temp. on the display
    display.setCursor(45, 25); // set the cursor
    display.print(set_temperature);// print the set temperature value on the display
    display.display(); // Update the Display
  }
}

void read_encoder() // In this function we read the encoder data and increment the counter if it is rotating clockwise and decrement the counter if it's rotating counterclockwise
{
  clockPin = digitalRead(CLK_PIN); // we read the clock pin of the rotary encoder
  if (clockPin != clockPinState && clockPin == 1) { // if this condition is true then the encoder is rotaing counter clockwise and we decremetn the counter
    if (digitalRead(DATA_PIN) != clockPin) set_temperature = set_temperature - 3;  // decrmetn the counter.
    else set_temperature = set_temperature + 3; // Encoder is rotating CW so increment
    if (set_temperature < 1 )set_temperature = 1; // if the counter value is less than 1 the set it back to 1
    if (set_temperature > 150 ) set_temperature = 150; //if the counter value is grater than 150 then set it back to 150
#ifdef __DEBUG__
    Serial.println(set_temperature); // print the set temperature value on the serial monitor window
#endif
  }
  clockPinState = clockPin; // Remember last CLK_PIN state
  if ( digitalRead(SW_PIN) == LOW)   //If we detect LOW signal, button is pressed
  {
    if ( millis() - debounce > 80) { //debounce delay
      encoder_btn_count++; // Increment the values
      if (encoder_btn_count > 2) encoder_btn_count = 1;
#ifdef __DEBUG__
      Serial.println(encoder_btn_count);
#endif
    }
    debounce = millis(); // update the time variable
  }
}

Son olarak, döngü fonksiyonumuz var. Döngü işlevinde read_encoder() ve set_temp() işlevimizi çağırıyoruz , bu işlevler sürekli olarak çağrılacak ve döngüde düğme modunu da kontrol ediyoruz ve eğer bire ayarlanmışsa termokupldan sıcaklığı okuyup koyuyoruz. PID örneğinin hesaplama yöntemi aracılığıyla Hesaplama yapıldıktan sonra, hesaplanan değerleri doğrudan bir PWM sinyali veren analog yazma işlevine koyarız. Her şey bittiğinde, ekranı güncelliyoruz ve bu kod bölümünün sonunu işaret ediyor.

void loop()
{
  read_encoder(); //Call The Read Encoder Function
  set_temp(); // Call the Set Temperature Function
  if (encoder_btn_count == 1) // check if the button is pressed and it's in Free Running mode -- in this mode, the Arduino continuously updates the screen and adjusts the PWM output according to the temperature.
  {
    temperature_value_c = thermocouple.readCelsius(); // Read the Temperature using the readCelsius methode from MAX6675 Library.
    int output = pid.compute(temperature_value_c);    // Let the PID compute the value, returns the optimal output
    analogWrite(mosfet_pin, output);           // Write the output to the output pin
    pid.setpoint(set_temperature); // Use the setpoint methode of the PID library to
    display.clearDisplay(); // Clear the display
    display.setTextSize(2); // Set text Size
    display.setCursor(16, 0); // Set the Display Cursor
    display.print("Cur Temp."); //Print to the Display
    display.setCursor(45, 25);// Set the Display Cursor
    display.print(temperature_value_c); // Print the Temperature value to the display in celcius
    display.display(); // Update the Display
#ifdef __DEBUG__
    Serial.print(temperature_value_c); // Print the Temperature value in *C on serial monitor
    Serial.print(" "); // Print an Empty Space
    Serial.println(output); // Print the Calculate Output value in the serial monitor.
#endif
    delay(200); // Wait 200ms to update the OLED dispaly.
  }
}
PID Etkin Sıcaklık Kontrol Cihazı Testi 

Devreyi test etmek için aşağıdaki kurulum kullanıldı, gördüğünüz gibi, Arduino’nun pin11’inden gelen çıkış PWM sinyalinin görev döngüsünü görüntülemek için Meco 450B+ Multimetremi bağladım. Ve bir ısıtıcı olarak, 12V ısıtma elemanı içeren bir 3D yazıcı ekstrüderi kullandım, Arduino’ya güç sağlamak için dizüstü bilgisayarımın 5V güç kaynağını kullandım ve ısıtma elemanına güç vermek için harici bir 12V güç kaynağı kullandım.

Test
Test

Şimdi, sıcaklığı ayarlamak için, PID algoritmasının ayar noktasını veya hedef sıcaklığını bir kez ayarlayan döner kodlayıcının düğmesine basmanız gerekir, değişiklikleri kalıcı hale getirmek için düğmeye bir kez daha basın ve ısıtıcı bloğu ısıtmaya başlar ve şunları yapabilirsiniz: bakın görev döngüsü de artıyor, sıcaklığı 64*C olarak ayarladım.

Sıcaklık Testi
Sıcaklık Testi

stenen sıcaklığa ulaşıldığında, PWM görev döngüsü azalır ve kontrolör hatayı telafi etmek ve sıcaklığı artırmak istediğinde görev döngüsünde belirli bir artış gözlemleyebilirsiniz.

Son Test
Son Test
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <PIDController.h>
#include "max6675.h"
// Define Rotary Encoder Pins
#define CLK_PIN 3
#define DATA_PIN 4
#define SW_PIN 2
// MAX6675 Pins
#define thermoDO  8
#define thermoCS  9
#define thermoCLK  10
// Mosfet Pin
#define mosfet_pin 11
// Serial Enable
#define __DEBUG__
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
/*In this section we have defined the gain values for the 
 * proportional, integral, and derivative controller I have set
 * the gain values with the help of trial and error methods.
*/ 
#define __Kp 30 // Proportional constant
#define __Ki 0.7 // Integral Constant
#define __Kd 200 // Derivative Constant
int clockPin; // Placeholder por pin status used by the rotary encoder
int clockPinState; // Placeholder por pin status used by the rotary encoder
int set_temperature = 1; // This set_temperature value will increas or decreas if when the rotarty encoder is turned
float temperature_value_c = 0.0; // stores temperature value
long debounce = 0; // Debounce delay
int encoder_btn_count = 0; // used to check encoder button press
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO); // Create an instance for the MAX6675 Sensor Called "thermocouple"
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);// Create an instance for the SSD1306 128X64 OLED "display"
PIDController pid; // Create an instance of the PID controller class, called "pid"
void setup() {
#ifdef __DEBUG__
  Serial.begin(9600);
#endif
  pinMode(mosfet_pin, OUTPUT); // MOSFET output PIN
  pinMode(CLK_PIN, INPUT); // Encoer Clock Pin
  pinMode(DATA_PIN, INPUT); //Encoder Data Pin
  pinMode(SW_PIN, INPUT_PULLUP);// Encoder SW Pin
  pid.begin();          // initialize the PID instance
  pid.setpoint(150);    // The "goal" the PID controller tries to "reach"
  pid.tune(__Kp, __Ki,__Kd);    // Tune the PID, arguments: kP, kI, kD
  pid.limit(0, 255);    // Limit the PID output between 0 and 255, this is important to get rid of integral windup!
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
#ifdef __DEBUG__
    Serial.println(F("SSD1306 allocation failed"));
#endif
    for (;;); // Don't proceed, loop forever
  }
  //
  display.setRotation(2); //Rotate the Display
  display.display(); //Show initial display buffer contents on the screen -- the library initializes this with an Adafruit splash screen.
  display.clearDisplay(); // Cleear the Display
  display.setTextSize(2); // Set text Size
  display.setTextColor(WHITE); // set LCD Colour
  display.setCursor(48, 0); // Set Cursor Position
  display.println("PID"); // Print the this Text
  display.setCursor(0, 20);  // Set Cursor Position
  display.println("Temperatur"); // Print the this Text
  display.setCursor(22, 40); // Set Cursor Position
  display.println("Control"); // Print the this Text
  display.display(); // Update the Display
  delay(2000); // Delay of 200 ms
}
void set_temp()
{
  if (encoder_btn_count == 2) // check if the button is pressed twice and its in temperature set mode.
  {
    display.clearDisplay(); // clear the display
    display.setTextSize(2); // Set text Size
    display.setCursor(16, 0); // set the diplay cursor
    display.print("Set Temp."); // Print Set Temp. on the display
    display.setCursor(45, 25); // set the cursor
    display.print(set_temperature);// print the set temperature value on the display
    display.display(); // Update the Display
  }
}
void read_encoder() // In this function we read the encoder data and increment the counter if its rotaing clockwise and decrement the counter if its rotating counter clockwis
{
  clockPin = digitalRead(CLK_PIN); // we read the clock pin of the rotary encoder
  if (clockPin != clockPinState  && clockPin == 1) { // if this condition is true then the encoder is rotaing counter clockwise and we decremetn the counter
    if (digitalRead(DATA_PIN) != clockPin) set_temperature = set_temperature - 3;  // decrmetn the counter.
    else  set_temperature = set_temperature + 3; // Encoder is rotating CW so increment
    if (set_temperature < 1 )set_temperature = 1; // if the counter value is less than 1 the set it back to 1
    if (set_temperature > 150 ) set_temperature = 150; //if the counter value is grater than 150 then set it back to 150 
#ifdef __DEBUG__
    Serial.println(set_temperature); // print the set temperature value on the serial monitor window
#endif
  }
  clockPinState = clockPin; // Remember last CLK_PIN state
  
  if ( digitalRead(SW_PIN) == LOW)   //If we detect LOW signal, button is pressed
  {
    if ( millis() - debounce > 80) { //debounce delay
      encoder_btn_count++; // Increment the values 
      if (encoder_btn_count > 2) encoder_btn_count = 1;
#ifdef __DEBUG__
      Serial.println(encoder_btn_count);
#endif
    }
    debounce = millis(); // update the time variable
  }
}
void loop()
{
  read_encoder(); //Call The Read Encoder Function
  set_temp(); // Call the Set Temperature Function
  if (encoder_btn_count == 1) // check if the button is pressed and its in Free Running Mode -- in this mode the arduino continiously updates the screen and adjusts the PWM output according to the temperature.
  {
    temperature_value_c = thermocouple.readCelsius(); // Read the Temperature using the readCelsius methode from MAX6675 Library.
    int output = pid.compute(temperature_value_c);    // Let the PID compute the value, returns the optimal output
    analogWrite(mosfet_pin, output);           // Write the output to the output pin
    pid.setpoint(set_temperature); // Use the setpoint methode of the PID library to
    display.clearDisplay(); // Clear the display
    display.setTextSize(2); // Set text Size
    display.setCursor(16, 0); // Set the Display Cursor
    display.print("Cur Temp."); //Print to the Display
    display.setCursor(45, 25);// Set the Display Cursor
    display.print(temperature_value_c); // Print the Temperature value to the display in celcius
    display.display(); // Update the Display
#ifdef __DEBUG__
    Serial.print(temperature_value_c); // Print the Temperature value in *C on serial monitor
    Serial.print("   "); // Print an Empty Space
    Serial.println(output); // Print the Calculate Output value in the serial monitor.
#endif
    delay(200); // Wait 200ms to update the OLED dispaly.
  }
}

Bu makale buradan çevrilmiştir.

Related posts

GSR Tabanlı Yalan Dedektör Cihazı

Ömer Ersin

Çift Kutuplu Tek Konumlu DPST Rölesi

Ömer Ersin

MAX232 Dual Driver/Receiver

Ömer Ersin