كود البحث

Lesson 47: Using K-Type MAX6675 as thermostat with relay | Arduino Step By Step Course

Lesson 47: Using K-Type MAX6675 as thermostat with relay | Arduino Step By Step Course

This project guides you through building a temperature control system using an Arduino, a MAX6675 K-type thermocouple, and a relay. This system can maintain a desired temperature range, making it suitable for various applications. You can use this to build:

  • A temperature-controlled incubator for delicate experiments or seedlings.
  • An automated brewing system for maintaining consistent wort temperatures.
  • A climate-controlled enclosure for reptiles or other temperature-sensitive animals.
  • A simple heating or cooling system for a small space.

The system uses the MAX6675 to read temperatures from a K-type thermocouple, providing accurate temperature readings over a wide range (depending on the thermocouple type, up to 1000°C or more). The Arduino processes these readings and controls a relay to switch a heating or cooling element on or off, maintaining the temperature within a user-defined range. (in video at 00:32)

Hardware/Components

To build this project, you will need the following components:

  • Arduino board (Uno, Nano, etc.)
  • MAX6675 thermocouple amplifier
  • K-type thermocouple
  • Relay module
  • AC bulb (or other load, such as a fan or heater)
  • Jumper wires
  • Breadboard (optional, but recommended)

Wiring Guide

The wiring is explained in detail in the video. (in video at 03:28) Refer to the video for a visual guide. The key connections include connecting the MAX6675 to the Arduino (pins 2-6), the relay module to the Arduino (pin 8 and power), and the relay module to the AC load. A critical aspect is correctly identifying the live and neutral wires of your AC load before connecting them to the relay. Incorrect wiring can lead to dangerous situations.

Code Explanation

The Arduino code (shown in snippets below) utilizes the MAX6675 library to read temperature values from the thermocouple. The user-configurable parts of the code are:

  • relayPin: The Arduino pin connected to the relay module (default: 8). (in video at 07:35)
  • relayON and relayOFF: These constants define the logic levels to turn the relay on and off, respectively. These are usually LOW and HIGH, but might need to be adjusted depending on your relay module. (in video at 07:35)
  • TEMPERATURE_UNIT: Sets the unit for temperature readings (1 for Celsius, 2 for Fahrenheit, 3 for Kelvin). (in video at 08:21)
  • START_TEMPERATURE and STOP_TEMPERATURE: These variables define the temperature range for the control system. The system will turn on the relay when the temperature falls below START_TEMPERATURE and turn it off when the temperature reaches STOP_TEMPERATURE (or vice-versa, depending on whether you're controlling a heater or cooler). (in video at 08:31)
  • CONTROL_TYPE: A variable that determines whether the system acts as a heater (1) or cooler (2). (in video at 08:36)

The code includes functions like readTemperature(), printTemperature(), loadControl(), and relayControl() to handle temperature reading, display, and relay operation. These functions are clearly defined and explained in the video. (in video at 09:37, 10:00, 10:43, 11:30)


const int relayPin =8;
const int relayON = LOW;// do not change
const int relayOFF = HIGH; //do not change 
int relayState = relayOFF;//initial state of relay

const int TEMPERATURE_UNIT =1;//1=Celsius, 2=Fahrenheit, 3=Kelvin
const float START_TEMPERATURE = 80.0;//unit above
const float STOP_TEMPERATURE = 100.0;//unit above
const int CONTROL_TYPE = 1;// 1= heater, 2=cooler

Live Project/Demonstration

The video demonstrates the functioning of the temperature control system for both heating and cooling scenarios. (in video at 13:15 and 15:28) The demonstration clearly shows how the system maintains the temperature within the set range by turning the relay on and off as needed.

Chapters

  • [00:00] Introduction
  • [00:55] Heater/Cooler Control Explanation
  • [03:28] Wiring Diagram
  • [06:26] Code Explanation
  • [13:15] Heater Control Demonstration
  • [15:28] Cooler Control Demonstration
  • [17:29] Conclusion
25-Arduino code for a MAX6675 K-type thermocouple with relay (no display)
اللغة: C++
/*
 * هذا هو كود Arduino لجهاز قياس الحرارة MAX6675 من النوع K مع جهاز تحكم وأDisplay
 * الخرج على الدبوس 10 موصول لجهاز التحكّم.
 * عندما تصل درجة الحرارة إلى القيمة المطلوبة، يقوم الدبوس 10 بتشغيل
 * جهاز التحكّم.
 * 
 * تم شرح هذا الكود في الفيديو الخاص بنا على https://youtu.be/cD5oOu4N_AE
 * 
 * كتب بواسطة أحمد نجرابي لفيديو Robojax
 * التاريخ: 9 ديسمبر 2017، في أجاكس، أونتاريو، كندا
 * تم منح الإذن لمشاركة هذا الكود شريطة الاحتفاظ بهذه
 * الملاحظة مع الكود.
 * إخلاء المسؤولية: هذا الكود "كما هو" ولأغراض تعليمية فقط. 
 * 
 * /
 * 
 * 
 * // هذا المثال في الملكية العامة. استمتع!
 * // www.ladyada.net/learn/sensors/thermocouple
 */
#include "max6675.h"


int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;


MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 3;
int gndPin = 2;

void setup() {
  Serial.begin(9600);
 // استخدم دبابيس أردوينو
  pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
    pinMode(10, OUTPUT); // قم بتعيين الدبوس 10 كإخراج

  Serial.println("Robojax: MAX6675 test");
 // انتظر حتى يستقر شريحة ماكس
  delay(500);
}

void loop() {
 // اختبار قراءة أساسي، فقط اطبع درجة الحرارة الحالية


   Serial.print("C = ");
   Serial.println(thermocouple.readCelsius());
   Serial.print("F = ");
   Serial.println(thermocouple.readFahrenheit());

 // إذا تجاوزت درجة الحرارة 80.0 درجة مئوية، قم بتشغيل المرحل.
   if(thermocouple.readCelsius() > 80.00){
    digitalWrite(10, LOW); // اضبط الدبوس 10 على قيمة منخفضة
   }else{
    digitalWrite(10, HIGH); // ضع الدبوس 10 في الحالة العالية
   }


   delay(1000);
}
757-Arduino code to measure a MAX6675 K-type thermocouple
اللغة: C++
++
/*
 * مكتبة من: // www.ladyada.net/learn/sensors/thermocouple
 * 
 * هذا هو كود أردوينو لقياس حساس الترموكوبل من نوع MAX6675
 * والتحكم في المرحل كمدفأة أو مبرد
 * 
 * شاهد فيديو التعليمات لهذا الكود: https://youtu.be/dVh77wT-4Ao
 * 
 * كتب بواسطة أحمد شمشيري في 20 مايو 2020 في أجاكس، أونتاريو، كندا
 * www.robojax.com
 * 
 * احصل على هذا الكود وغيرها من أكواد أردوينو من Robojax.com.
 * تعلم الأردوينو خطوة بخطوة في دورة منظمة تحتوي على جميع المواد والمخططات الكهربائية والمكتبات
 * كلها في مكان واحد. اشترِ دورتي على Udemy.com http://robojax.com/L/?id=62
 * 
 * إذا كنت قد وجدت هذا الدليل مفيدًا، يرجى دعمي حتى أتمكن من الاستمرار في إنشاء
 * محتوى مثل هذا. يمكنك دعمي على Patreon http://robojax.com/L/?id=63
 * 
 * أو قم بالتبرع باستخدام باي بال http://robojax.com/L/?id=64
 * فيديوهات ذات صلة:
 * مقدمة عن MAX6675 K-Type: https://youtu.be/VGqONmUinqA
 * استخدام MAX6675 K-Type مع شاشة LED: https://youtu.be/cD5oOu4N_AE
 * استخدام MAX6675 K-Type مع LCD1602-I2C: https://youtu.be/BlhpktgPdKs
 * استخدام 2 أو أكثر من MAX6675 K-Type: https://youtu.be/c90NszbNG8c
 * استخدام MAX6675 K-Type كتحكم في المدفأة أو المبرد: [هذا الفيديو]
 *  * هذا الكود "كما هو" بدون ضمان أو مسؤولية. يمكن استخدامه بحرية طالما أنك تحتفظ بهذه الملاحظة سليمة.* 
 * تم تنزيل هذا الكود من Robojax.com
 *  هذا البرنامج هو برنامج مجاني: يمكنك إعادة توزيعه و/أو تعديله
 *  وفقًا لشروط ترخيص جنو العام كما نشرته
 *  مؤسسة البرمجيات الحرة، سواء النسخة 3 من الترخيص، أو
 *  (حسب اختيارك) أي إصدار لاحق.
 * 
 *  يتم توزيع هذا البرنامج على أمل أن يكون مفيدًا، 
 *  ولكن بدون أي ضمان؛ حتى بدون ضمان الضمن
 *  القابلية للتسويق أو الملاءمة لغرض معين. راجع 
 *  ترخيص جنو العام لمزيد من التفاصيل.
 * 
 *  يجب أن تكون قد تلقيت نسخة من ترخيص جنو العام
 *  مع هذا البرنامج. إذا لم يكن الأمر كذلك، فيرجى زيارة <https://www.gnu.org/licenses/>.
 */


#include "max6675.h"
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
int GNDpin = 2;
int VCCpin =3;
int thermoCLK = 4;
int thermoCS = 5;
int thermoDO = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);


const int relayPin =8;
const int relayON = LOW; // لا تغير
const int relayOFF = HIGH; // لا تغير
int relayState = relayOFF; // الحالة الأولية للريليه

const int TEMPERATURE_UNIT =1; // 1=سلسيوس، 2=فهرنهايت، 3=كلفن
const float START_TEMPERATURE = 80.0; // وحدة أعلى
const float STOP_TEMPERATURE = 100.0; // وحدة أعلى
const int CONTROL_TYPE = 1; // 1= سخان، 2= مبرد
float temperature;

void setup() {
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
  Serial.begin(9600);
  Serial.println("MAX6675 test with relay");
 // استخدم دبابيس أردوينو
  pinMode(relayPin, OUTPUT); // دبوس للتتابع
  digitalWrite(relayPin, relayState);

  pinMode(VCCpin, OUTPUT);
  digitalWrite(VCCpin, HIGH);

  pinMode(GNDpin, OUTPUT);
  digitalWrite(GNDpin, LOW);

 // انتظر حتى يستقر شريحة MAX
  delay(500);
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
}

void loop() {
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
   readTemperature();
   printTemperature();
   loadControl();
   if(temperature >=89.5)
   {
 // /
   }
   delay(1000);
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
} // حلقة



/*
 * loadControl()
 * @brief يتحكم في الحمولة بناءً على 
 * @param الحالة يمكن أن تكون إما: relayON أو relayOFF
 * @return لا يُرجع أي شيء
 * كتب بواسطة أحمد شمشيري لموقع robojax.com
 * في 20 مايو 2020 الساعة 15:23 في أجاكس، أونتاريو، كندا
 */
void loadControl()
{
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
 // سيريل.طباعة("ابدأ: ");
 // Serial.print(START_TEMPERATURE);
 // Serial.print(" توقف: ");
 // الطباعة.serial(STOP_TEMPERATURE);
  if(CONTROL_TYPE ==1)
  {
    if(START_TEMPERATURE >= temperature && STOP_TEMPERATURE >=temperature)
    {
      relayControl(relayON);
    }
    if(STOP_TEMPERATURE <=temperature)
    {
      relayControl(relayOFF);
    }
  }else{
    if(START_TEMPERATURE >= temperature && STOP_TEMPERATURE >=temperature)
    {
      relayControl(relayOFF);
    }
    if(STOP_TEMPERATURE <=temperature)
    {
      relayControl(relayON);
    }
  }

 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
} // loadControl()


/*
 * relayControl(int state))
 * @brief يقوم بتشغيل أو إيقاف المرحل
 * @param state هو "relayON" أو "relayOFF" معرف في أعلى الشيفرة
 * @return لا يُرجع شيء
 * كتب بواسطة أحمد شمشيري لموقع robojax.com
 * في 20 مايو 2020 الساعة 15:23 في أجاكس، أونتاريو، كندا
 */
void relayControl(int state)
{
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
  if(state ==relayON)
  {
    digitalWrite(relayPin, relayON);
    Serial.println("Relay ON");
  }else{
   digitalWrite(relayPin, relayOFF);
    Serial.println("Relay OFF");
  }
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675

} // relayControl()


/*
 * readTemperature()
 * @brief يقرأ درجة الحرارة بناءً على وحدة درجة الحرارة
 * @param درجة الحرارة المتوسطة
 * @return يُرجع أحد القيم المذكورة أعلاه
 * كتب بواسطة أحمد شمشيرى لموقع robojax.com
 * في 20 مايو 2020 الساعة 15:23 في أجاكس، أونتاريو، كندا
 */
void readTemperature()
{
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675

  if(TEMPERATURE_UNIT ==2)
   {
   temperature = thermocouple.readFahrenheit(); // تحويل إلى فهرنهايت
   }else if(TEMPERATURE_UNIT ==3)
   {
    temperature = thermocouple.readCelsius() + 273.15; // تحويل إلى كلفن
   }else{
    temperature = thermocouple.readCelsius(); // إرجاع درجة مئوية
   }
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
} // قراءةدرجة الحرارة()

/*
 * printTemperature()
 * @ملخص يقوم بطباعة درجة الحرارة على شاشة السلسلة
 * @param نوع الحرف
 * @param "النوع" هو حرف
 *  C = سيلسيوس
 *  K = كيلفن
 *  F = فهرنهايت
 * @return لا يوجد
 * كتب بواسطة أحمد شمشيري لموقع robojax.com
 * في 08 مايو 2020 الساعة 02:45 في أجاكس، أونتاريو، كندا
 */
void printTemperature()
{
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
   Serial.print(temperature);
    printDegree();
  if(TEMPERATURE_UNIT ==2)
   {
     Serial.print("F");
    }else if(TEMPERATURE_UNIT ==3)
   {
     Serial.print("K");
   }else{
     Serial.print("C");
   }
  Serial.println();
 // مُسخن/مُبرّد Robojax.com مع مقياس حرارة MAX6675
} // printTemperature()

/*
 * @ملخص يطبع رمز الدرجة على شاشة التسلسل 
 * @param لا شيء 
 * @return لا يُرجع شيء 
 * كتب بواسطة أحمد شمشيري في 13 يوليو 2019 
 * لدرس روبو جاكس Robojax.com
 */
void printDegree()
{
    Serial.print("\\xC2");
    Serial.print("\\xB0");
}

الأشياء التي قد تحتاجها

الموارد والمراجع

ملفات📁

لا توجد ملفات متاحة.