搜尋程式碼

使用MAX6675 K型熱電偶配合繼電器同顯示屏

使用MAX6675 K型熱電偶配合繼電器同顯示屏

呢個項目示範咗點樣將MAX6675 K型熱電偶同Arduino連接,加入繼電器做控制同顯示屏顯示溫度讀數。呢個設置對於需要精確溫度監控同自動化響應嘅各種應用嚟講係好有價值。以下係一啲項目構思:

MAX6675 Thermocoupler module
  • 敏感電子產品嘅過熱保護
  • 用於生物實驗嘅恆溫培養箱
  • 咖啡或啤酒嘅自動沖泡系統
  • 工業過程監控同控制
  • 溫室或其他受控環境嘅環境監測

硬件/組件

要建造呢個項目,你需要以下組件:

  • Arduino Uno(或兼容板)
  • MAX6675 K型熱電偶模組(影片00:58位置)
  • 繼電器模組
  • TM1637 4位LED顯示模組
  • 杜邦線
  • 連接線

接線指南

接線方法喺影片入面有解釋(影片05:36位置)。具體嘅連接取決於你係用表面貼裝晶片定係PCB模組。請參考影片了解詳細嘅接線圖。

Arduino wiring for MAX6675 Thermocoupler module
Arduino wiring for MAX6675 Thermocoupler module

程式碼解釋

Arduino程式碼使用MAX6675函式庫嚟讀取熱電偶嘅溫度值。程式碼入面主要可配置嘅部分包括:

  • 熱電偶引腳定義:thermoDOthermoCSthermoCLK(影片[03:53]位置)。呢啲引腳需要根據你嘅接線方案嚟調整。
  • 繼電器控制引腳:引腳10用嚟控制繼電器(影片[05:36]位置)。如有需要可以更改。
  • 顯示屏配置(如果使用):程式碼包含配置TM1637顯示屏嘅部分。如有需要,調整CLK同DIO引腳(影片[03:53]位置)。

程式碼包含讀取攝氏同華氏溫度嘅函數。程式碼入面一個關鍵部分係條件判斷,檢查溫度係咪超過閾值(呢個例子係80.0°C)。如果超過,繼電器就會啟動(引腳10變為LOW)。


// 如果溫度超過80.0C,打開繼電器
if(thermocouple.readCelsius() > 80.00){
  digitalWrite(10, LOW);// 將引腳10設為LOW
} else {
  digitalWrite(10, HIGH);// 將引腳10設為HIGH
}

實際項目/示範

影片示範咗項目嘅實際運作(影片06:59位置)。感測器準確讀取環境溫度,加熱時溫度會上升。繼電器功能亦有展示。

章節

  • [00:00] 簡介
  • [00:39] 感測器概述
  • [01:40] 引腳連接
  • [02:22] 函式庫安裝
  • [03:53] 程式碼解釋(設定)
  • [04:06] 程式碼解釋(循環)
  • [05:36] 接線
  • [06:59] 實際示範

圖片

MAX6675 Thermocoupler module
MAX6675 Thermocoupler module
K-Type Thermocoupler module with wire
K-Type Thermocoupler module with wire
K-Type thermocoupler connector
K-Type thermocoupler connector
Arduino wiring for MAX6675 Thermocoupler module
Arduino wiring for MAX6675 Thermocoupler module
MAX6675 Thermocoupler module
MAX6675 Thermocoupler module
24-Arduino code for a MAX6675 K-type thermocouple (without relay and display)
語言: C++
/*
 * This is the Arduino code for MAX6675 Thermocouple K-Type with Relay and Display.
 * This code has been explained in our video at https://youtu.be/cD5oOu4N_AE.

 * 
 * Written by Ahmad Shamshiri for Robojax Video
 * Date: December 9, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */

 // This example is public domain. Enjoy!
// 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);
  // Use Arduino pins 
  pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
  
  Serial.println("Robojax: MAX6675 test");
  // Wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // Basic readout test, just print the current temperature


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

   // If temperature goes above 80.0C, turn the relay ON
   if(thermocouple.readCelsius() > 80.00){
    digitalWrite(10, LOW);// Set pin 10 LOW
   }else{
    digitalWrite(10, HIGH);// Set pin 10 HIGH
   }
    
 
   delay(1000);
}
25-Arduino code for a MAX6675 K-type thermocouple with relay (no display)
語言: C++
/*
 * This is the Arduino code for MAX6675 Thermocouple K-Type with Relay and Display
 * The output pin 10 is connected to the relay.
 * When the temperature reaches the desired value, pin 10 turns the 
 * relay ON.

 * This code has been explained in our video at https://youtu.be/cD5oOu4N_AE

 * 
 * Written by Ahmad Nejrabi for Robojax Video
 * Date: December 9, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */

 // This example is public domain. Enjoy!
// 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);
  // Use Arduino pins 
  pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
    pinMode(10, OUTPUT);// set pin 10 as output
	
  Serial.println("Robojax: MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp


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

   // If temperature goes above 80.0C, turn the relay ON
   if(thermocouple.readCelsius() > 80.00){
    digitalWrite(10, LOW);// set pin 10 LOW
   }else{
    digitalWrite(10, HIGH);// set pin 10 HIGH
   }
    
 
   delay(1000);
}
26-Arduino code for a MAX6675 K-type thermocouple with relay and display
語言: C++
/*
 * This is the Arduino code for MAX6675 Thermocouple K-Type with Relay and Display
 * The output pin 10 is connected to the relay.
 * When the temperature reaches the desired value, pin 10 turns the 
 * relay ON.
 * The temperature is also displayed on the display.
 * You must include the TM1637 library to make the display work. 
 * You can download the TM1637 from http://robojax.com/learn/library
 * This code has been explained in our video at https://youtu.be/cD5oOu4N_AE

 * 
 * Written by Ahmad Nejrabi for Robojax Video
 * Date: December 9, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */

 // This example is public domain. Enjoy!
// www.ladyada.net/learn/sensors/thermocouple

#include "max6675.h"
#include <Arduino.h>
#include <TM1637Display.h>

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

// Code for display 
#define CLK 2
#define DIO 3
#define TEST_DELAY   2000
TM1637Display display(CLK, DIO);
// Code for display end

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 3;
int gndPin = 2;
  
void setup() {
  Serial.begin(9600);
  // Use Arduino pins 
  pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
  pinMode(10, OUTPUT);// set pin 10 as output
	
  Serial.println("Robojax: MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // Basic readout test, just print the current temp

	// Code for display
  display.setBrightness(0x0f);
    // All segments on
  uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
  display.setSegments(data);
  delay(1);
  int temp = (int) thermocouple.readCelsius();
  display.showNumberDec(temp, true, 3, 0);
  // Code for display end
   Serial.print("C = "); 
   Serial.println(thermocouple.readCelsius());
   Serial.print("F = ");
   Serial.println(thermocouple.readFahrenheit());

   // If temperature goes above 80.0C, turn the relay ON
   if(thermocouple.readCelsius() > 80.00){
    digitalWrite(10, LOW);// set pin 10 LOW
   }else{
    digitalWrite(10, HIGH);// set pin 10 HIGH
   }
    
 
   delay(1000);
}
27-Arduino code for two MAX6675 K-type thermocouples with relay (no display)
語言: C++
/*
 * This is the Arduino code for MAX6675 Thermocouple K-Type with Relay and Display
 * The output pin 10 is connected to the relay.
 * When the temperature reaches the desired value, pin 10 turns the 
 * relay ON.

 * This code has been explained in our video at https://youtu.be/cD5oOu4N_AE

 * 
 * Written by Ahmad Shamshiri for Robojax Video
 * Date: June 02, 2018, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */

 // This example is public domain. Enjoy!
// www.ladyada.net/learn/sensors/thermocouple

#include "max6675.h"


int thermoDO1 = 4;
int thermoCS1 = 5;
int thermoCLK1 = 6;

int thermoDO2 = 7;
int thermoCS2 = 8;
int thermoCLK3 = 9;


MAX6675 thermocouple1(thermoCLK1, thermoCS1, thermoDO1);// first thermocouple
MAX6675 thermocouple2(thermoCLK2, thermoCS2, thermoDO2);// 2nd thermocouple
int vccPin1 = 3;
int gndPin1 = 2;
int relayPin1 =10;

int vccPin2 = 11;
int gndPin2 = 12;
int relayPin2 =13;
  
void setup() {
  Serial.begin(9600);
  // use Arduino pins 
  pinMode(vccPin1, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin1, OUTPUT); digitalWrite(gndPin, LOW);
    pinMode(relayPin1, OUTPUT);// set pin 10 as output for thermocouple1
	
  pinMode(vccPin2, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin2, OUTPUT); digitalWrite(gndPin, LOW);
    pinMode(relayPin2, OUTPUT);// // set pin 13 as output for thermocouple2
	
  Serial.println("Robojax: MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp

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

   // if temperature goes above 80.0C, turn the relay ON
   if(thermocouple1.readCelsius() > 80.00){
    digitalWrite(relayPin1, LOW);// set pin relayPin1 LOW
   }else{
    digitalWrite(relayPin1, HIGH);// set pin relayPin1 HIGH
   }
// thermocouple1 end

// for thermocouple 2
   Serial.print("C2 = "); 
   Serial.println(thermocouple2.readCelsius());
   Serial.print("F2 = ");
   Serial.println(thermocouple2.readFahrenheit());

   // if temperature goes above 80.0C, turn the relay ON
   if(thermocouple2.readCelsius() > 80.00){
    digitalWrite(relayPin2, LOW);// set pin relayPin2 LOW
   }else{
    digitalWrite(relayPin2, HIGH);// set pin relayPin2 HIGH
   }   
// thermocouple2 end
 
   delay(1000);
}

文件📁

其他文件