Hello all.
Basically I made a simple project that used an Arduino Mega, 3 MAX6675 thermocouples and a I2C 2004 display.
Problem: Why aren't the declared GND and VCC pins not staying constant?
How can I get them to do so?
If not, how do I get stable readings WITHOUT having to daisy-chain Vcc and Gnd to each sensor?
Simply put: I want to "Plug and pray" my sensors without a rat's nest.
Here's my code...
/*
This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "max6675.h"// this file is part of the library.
// start of settings for LCD2004 with I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>// this file is part of the library.
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
// end of settings for LCD2004 with I2C
// Thermocouple 1
const int gndPin1 = 2;// Gnd = Ground pin
const int vccPin1 = 3;// Vcc = Power pin
int sckPin1 = 4;// SCK = Serial Clock pin
int csPin1 = 5; // CS = Chip Select pin
int soPin1 = 6; // SO = Serial Out pin
MAX6675 thermocouple1(sckPin1, csPin1, soPin1);
// Thermocouple 2
const int gndPin2 = 8;// Gnd = Ground pin
const int vccPin2 = 9;// Vcc = Power pin
int sckPin2 = 10;// SCK = Serial Clock pin
int csPin2 = 11; // CS = Chip Select pin
int soPin2 = 12; // SO = Serial Out pin
MAX6675 thermocouple2(sckPin2, csPin2, soPin2);
// Thermocouple 3
const int gndPin3 = 30;// Gnd = Ground pin
const int vccPin3 = 28;// Vcc = Power pin
int sckPin3 = 26;// SCK = Serial Clock pin
int csPin3 = 24; // CS = Chip Select pin
int soPin3 = 22; // SO = Serial Out pin
MAX6675 thermocouple3(sckPin3, csPin3, soPin3);
void setup() {
// use Arduino pins
pinMode(vccPin1, OUTPUT); digitalWrite(vccPin1, HIGH);
pinMode(gndPin1, OUTPUT); digitalWrite(gndPin1, LOW);
pinMode(vccPin2, OUTPUT); digitalWrite(vccPin2, HIGH);
pinMode(gndPin2, OUTPUT); digitalWrite(gndPin2, LOW);
pinMode(vccPin3, OUTPUT); digitalWrite(vccPin3, HIGH);
pinMode(gndPin3, OUTPUT); digitalWrite(gndPin3, LOW);
pinMode(51, OUTPUT);// set pin 51 as output
pinMode(52, OUTPUT);// set pin 52 as output
pinMode(53, OUTPUT);// set pin 53 as output
// MAX6675 video with LCD2004
lcd.begin();// initialize the LCD2004
lcd.backlight();// turn the backlight ON for the LCD
lcd.print("MAX6675");
lcd.setCursor(0, 1);
lcd.print("Thermocouples");
Serial.begin(9600);// initialize serial monitor with 9600 baud
Serial.println("MAX6675");
delay(3000);// give time to user to read the display at the beginning
}
void loop() {
// basic readout test, just print the current temp
Serial.print("C = ");
Serial.println(thermocouple1.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple1.readFahrenheit());
lcd.clear();// clear previous values from screen
lcd.setCursor(0, 0); // set cursor at character 0, line 0
lcd.print("Temperature");
lcd.setCursor(0, 1); // set cursor at character 0, line 1
lcd.print(thermocouple1.readCelsius());
lcd.setCursor(5, 1); // set cursor at character 5, line 1
lcd.print((char)223);
lcd.setCursor(6, 1); // set cursor at character 6, line 1
lcd.print("C");
lcd.setCursor(7, 1); // set cursor at character 7, line 1
lcd.print(" ");
lcd.setCursor(8, 1); // set cursor at character 8, line 1
lcd.print(thermocouple1.readFahrenheit()); // print temperature in Fahrenheit
lcd.setCursor(14, 1); // set cursor at character 14, line 1
lcd.print((char)223);
lcd.setCursor(15, 1); // set cursor at character 15, line 1
lcd.print("F");
// basic readout test, just print the current temp
Serial.print("C = ");
Serial.println(thermocouple2.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple2.readFahrenheit());
lcd.setCursor(0, 2); // set cursor at character 0, line 2
lcd.print(thermocouple2.readCelsius());
lcd.setCursor(5, 2); // set cursor at character 5, line 2
lcd.print((char)223);
lcd.setCursor(6, 2); // set cursor at character 6, line 2
lcd.print("C");
lcd.setCursor(7, 2); // set cursor at character 7, line 2
lcd.print(" ");
lcd.setCursor(8, 2); // set cursor at character 8, line 2
lcd.print(thermocouple2.readFahrenheit()); // print temperature in Fahrenheit
lcd.setCursor(14, 2); // set cursor at character 14, line 2
lcd.print((char)223);
lcd.setCursor(15, 2); // set cursor at character 15, line 2
lcd.print("F");
// basic readout test, just print the current temp
Serial.print("C = ");
Serial.println(thermocouple3.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple3.readFahrenheit());
lcd.setCursor(0, 3); // set cursor at character 0, line 3
lcd.print(thermocouple3.readCelsius());
lcd.setCursor(5, 3); // set cursor at character 5, line 3
lcd.print((char)223);
lcd.setCursor(6, 3); // set cursor at character 6, line 3
lcd.print("C");
lcd.setCursor(7, 3); // set cursor at character 7, line 3
lcd.print(" ");
lcd.setCursor(8, 3); // set cursor at character 8, line 3
lcd.print(thermocouple3.readFahrenheit()); // print temperature in Fahrenheit
lcd.setCursor(14, 3); // set cursor at character 14, line 3
lcd.print((char)223);
lcd.setCursor(15, 3); // set cursor at character 15, line 3
lcd.print("F");
// if temprature goes above xF, turn the relay ON
if (thermocouple1.readFahrenheit() > 85.00) {
digitalWrite(51, HIGH);// set pin 51 HIGH
} else {
digitalWrite(51, LOW);// set pin 51 LOW
}
// if temprature goes above xF, turn the relay ON
if (thermocouple2.readFahrenheit() > 85.00) {
digitalWrite(52, HIGH);// set pin 52 HIGH
} else {
digitalWrite(52, LOW);// set pin 52 LOW
}
delay(1000);
}
