0% found this document useful (0 votes)
5 views7 pages

Code

The document contains an Arduino code for controlling temperature and motors using a MAX6675 thermocouple. It defines constants for temperature units, relay control parameters, and pin assignments for various components. The main functions include reading temperature, controlling a relay based on temperature thresholds, and adjusting motor speeds based on potentiometer inputs.

Uploaded by

Oladimeji Yusuf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Code

The document contains an Arduino code for controlling temperature and motors using a MAX6675 thermocouple. It defines constants for temperature units, relay control parameters, and pin assignments for various components. The main functions include reading temperature, controlling a relay based on temperature thresholds, and adjusting motor speeds based on potentiometer inputs.

Uploaded by

Oladimeji Yusuf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <max6675.

h>

// Temperature units

Const int TEMPERATURE_UNIT_CELSIUS = 0;

Const int TEMPERATURE_UNIT_FAHRENHEIT = 1;

Const int TEMPERATURE_UNIT_KELVIN = 2;

Int temperatureUnit = TEMPERATURE_UNIT_CELSIUS;

// Relay control parameters

Const float START_TEMPERATURE = 50.0;

Const float STOP_TEMPERATURE = 50.0;

Const float HYSTERESIS = 2.0; // Adjust hysteresis as needed

Const int CONTROL_TYPE = 1;

// Pin definitions

Const int GNDpin = 2;

Const int VCCpin = 3;

Const int thermoCLK = 4;

Const int thermoCS = 5;

Const int thermoDO = 6;

Const int relayPin = 8;

// Motor control pin definitions

Const int motor1_in1 = 9;

Const int motor1_in2 = 10;

Const int motor1_en = 11;

Const int motor2_in1 = 12;


Const int motor2_in2 = 13;

Const int motor2_en = 14;

// Potentiometer pin definitions

Const int pot1 = A0;

Const int pot2 = A1;

// Motor speed variables

Int motor1_speed = 0;

Int motor2_speed = 0;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

// Relay states

Const int relayON = LOW;

Const int relayOFF = HIGH;

Int relayState = relayOFF;

// Temperature variable

Float temperature;

Void setup() {

[Link](9600);

[Link](“MAX6675 test with relay and motor control”);

// Initialize pins

pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, relayState);

pinMode(VCCpin, OUTPUT);

digitalWrite(VCCpin, HIGH);

pinMode(GNDpin, OUTPUT);

digitalWrite(GNDpin, LOW);

// Initialize motor control pins

pinMode(motor1_in1, OUTPUT);

pinMode(motor1_in2, OUTPUT);

pinMode(motor1_en, OUTPUT);

pinMode(motor2_in1, OUTPUT);

pinMode(motor2_in2, OUTPUT);

pinMode(motor2_en, OUTPUT);

// Delay for initialization

Delay(1000);

Void loop() {

readTemperature();

printTemperature();

loadControl();

controlMotors();

// Add custom logic here if needed

Delay(500);
}

// Function to read the temperature from the thermocouple

Void readTemperature() {

Temperature = [Link]();

// Convert temperature to desired unit if necessary

If (temperatureUnit == TEMPERATURE_UNIT_FAHRENHEIT) {

Temperature = (temperature * 9.0 / 5.0) + 32.0;

} else if (temperatureUnit == TEMPERATURE_UNIT_KELVIN) {

Temperature += 273.15;

// Function to print the temperature value

Void printTemperature() {

[Link](“Current Temperature: “);

[Link](temperature);

Switch (temperatureUnit) {

Case TEMPERATURE_UNIT_CELSIUS:

[Link](“ °C”);

Break;

Case TEMPERATURE_UNIT_FAHRENHEIT:

[Link](“ °F”);

Break;

Case TEMPERATURE_UNIT_KELVIN:
[Link](“ K”);

Break;

Default:

[Link](“ (Invalid unit)”);

Break;

[Link]();

// Function to control the relay based on temperature

Void loadControl() {

If (temperature >= START_TEMPERATURE + HYSTERESIS && relayState ==


relayOFF) {

relayState = relayON;

digitalWrite(relayPin, relayON);

[Link](“Relay turned ON”);

} else if (temperature <= STOP_TEMPERATURE – HYSTERESIS && relayState


== relayON) {

relayState = relayOFF;

digitalWrite(relayPin, relayOFF);

[Link](“Relay turned OFF”);

// Function to control the DC motors based on potentiometer values

Void controlMotors() {
// Read potentiometer values

Motor1_speed = analogRead(pot1) / 4;

Motor2_speed = analogRead(pot2) / 4;

// Set motor directions and speeds

If (motor1_speed > 0) {

digitalWrite(motor1_in1, HIGH);

digitalWrite(motor1_in2, LOW);

} else if (motor1_speed < 0) {

digitalWrite(motor1_in1, LOW);

digitalWrite(motor1_in2, HIGH);

} else {

digitalWrite(motor1_in1, LOW);

digitalWrite(motor1_in2, LOW);

If (motor2_speed > 0) {

digitalWrite(motor2_in1, HIGH);

digitalWrite(motor2_in2, LOW);

} else if (motor2_speed < 0) {

digitalWrite(motor2_in1, LOW);

digitalWrite(motor2_in2, HIGH);

} else {

digitalWrite(motor2_in1, LOW);

digitalWrite(motor2_in2, LOW);

}
// Set motor speeds

analogWrite(motor1_en, abs(motor1_speed));

analogWrite(motor2_en, abs(motor2_speed));

You might also like