検索コード

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++
/*
 * これは、リレーとディスプレイを使用したMAX6675サーモカップルKタイプのArduinoコードです。出力ピン10はリレーに接続されています。温度が設定値に達すると、ピン10がリレーをONにします。
 * 
 * このコードについては、https://youtu.be/cD5oOu4N_AEで説明しています。
 * 
 * ロボジャックスビデオのためにアハマド・ネジェラビによって書かれました。 日付:2017年12月9日、カナダのオンタリオ州アジャックスにて。 このコードを共有する際はこのメモをコードと共に保持することを条件に許可が与えられました。 免責事項:このコードは「現状のまま」で、教育目的のみのものです。
 * 
 * /
 * 
 * この例はパブリックドメインです。お楽しみください!
 * // 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);
 // Arduinoピンを使用する
  pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
    pinMode(10, OUTPUT); // ピン10を出力として設定する

  Serial.println("Robojax: MAX6675 test");
 // MAXチップが安定するのを待つ
  delay(500);
}

void loop() {
 // 基本的な読み取りテスト、現在の温度を表示するだけです。


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

 // 温度が80.0℃を超えた場合、リレーをONにしてください。
   if(thermocouple.readCelsius() > 80.00){
    digitalWrite(10, LOW); // ピン10をLOWに設定
   }else{
    digitalWrite(10, HIGH); // ピン10をHIGHに設定
   }


   delay(1000);
}
757-Arduino code to measure a MAX6675 K-type thermocouple
言語: C++
++
/*
 * ライブラリの出典: // www.ladyada.net/learn/sensors/thermocouple
 * 
 * これは、MAX6675 熱電対 Kタイプセンサーを測定し、リレーをヒーターまたはクーラーとして制御するための Arduino コードです。
 * 
 * このコードの動画説明を視聴してください: https://youtu.be/dVh77wT-4Ao
 * 
 * 著者: アフマド・シャムシリ 2020年5月20日、カナダ・オンタリオ州アジャックスにて
 * www.robojax.com
 * 
 * このコードおよび他の Arduino コードは Robojax.com から入手できます。
 * すべての教材、配線図、およびライブラリが一か所に揃った構造化されたコースで Arduino を段階的に学びましょう。
 * Udemy.com で私のコースを購入してください http://robojax.com/L/?id=62
 * 
 * このチュートリアルが役立った場合、私がこのようなコンテンツを作り続けるためにサポートしてください。Patreon でサポートできます http://robojax.com/L/?id=63
 * 
 * または、PayPal を使用して寄付することもできます http://robojax.com/L/?id=64
 * 関連動画:
 * MAX6675 Kタイプの紹介: https://youtu.be/VGqONmUinqA
 * LED ディスプレイを使用した MAX6675 Kタイプ熱電対: https://youtu.be/cD5oOu4N_AE
 * LCD1602-I2C とともに使用する MAX6675 Kタイプ熱電対: https://youtu.be/BlhpktgPdKs
 * 2つ以上の MAX6675 Kタイプ熱電対を使用する: https://youtu.be/c90NszbNG8c
 * ヒーターまたはクーラーのコントローラーとしての MAX6675 Kタイプ熱電対の使用: [この動画]
 *  * このコードは「現状のまま」で、保証または責任はありません。この注意書きを保持する限り、自由に使用できます。*
 * このコードは Robojax.com からダウンロードされました。
 * このプログラムは無料ソフトウェアです: GNU 一般公衆ライセンスの条件に従って再配布や修正が可能です。
 * ライセンスのバージョン3、または(あなたの選択で)それ以降のバージョンが適用されます。
 * 
 * このプログラムは有用であることを期待して配布されていますが、いかなる保証もありません。特定の目的への適合性や商業性についての暗示的な保証も含まれません。詳細は GNU 一般公衆ライセンスを参照してください。
 * 
 * このプログラムには GNU 一般公衆ライセンスのコピーを受け取っているはずです。受け取っていない場合は <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");
 // Arduinoピンを使用する
  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 state は relayON または relayOFF のいずれかです
 * @return 何も返しません
 * robojax.com のためにアハマド・シャムシリが作成
 * 2020年5月20日 15:23 アジャックス, オンタリオ, カナダ
 */
void loadControl()
{
 // Robojax.com ヒーター/クーラー MAX6675 サーモカップル付き
 // 始め: 
 // シリアル.print(START_TEMPERATURE);
 // シリアル.print(" 停止: ");
 // Serial.println(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()


/*
 * リレコントロール(int state))
 * @brief リレーをONまたはOFFにします
 * @param state はコードの先頭で定義された「relayON」または「relayOFF」です
 * @return 返り値はありません
 * 著者: Ahmad Shamshiri, robojax.comのために
 * 2020年5月20日、カナダのオンタリオ州アジャックスで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 TEMPERATURE_UNITに基づいて温度を読み取ります
 * @param 平均温度
 * @return 上記のいずれかの値を返します
 * ahmad shamshiriによってrobojax.comのために書かれました
 * 2020年5月20日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 サーモカップル付き
} // 温度を読み取る()

/*
 * 温度を印刷します。
 * @brief シリアルモニターに温度を表示します。
 * @param charactタイプ
 * @param "タイプ"は文字です。
 *  C = セルシウス
 *  K = ケルビン
 *  F = ファーレンハイト
 * @return なし
 * robojax.comのアハマド・シャムシリによって作成されました
 * 2020年5月8日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 サーモカップル付き
} // 温度を表示する()

/*
 * @brief シリアルモニタに度の記号を印刷します  
 * @param なし  
 * @return 何も返しません  
 * アハマド・シャムシリによって2019年7月13日に書かれました  
 * ロボジャックスチュートリアルのため Robojax.com
 */
void printDegree()
{
    Serial.print("\\xC2");
    Serial.print("\\xB0");
}

必要かもしれないもの

リソースと参考文献

ファイル📁

ファイルは利用できません。