Intermittent power problems on declared const int HIGH

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);
}

Arduino's I/O pins are not power pins. Don't try to use them in that way unless you have very good reasons for it (looking at the code you obviously don't).

Lets get you started. First power down everything, Get a book on basic electronics and read it so you understand some of the terms you are using. Then be sure all the grounds are connected together in your project. Your question: "Why aren't the declared GND and VCC pins not staying constant?" is a classic indication that the power and grounds are not properly connected. Looking at your code you are making a super BoBo by powering the sensor with the I/O pins of the arduino. Your question is answering your question? "how do I get stable readings WITHOUT having to daisy-chain Vcc and Gnd to each sensor?" answer you do not. I am assuming daisy-chain indicates each VCC is connected the +5 and each GND is connected to the power supply ground. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

I'll rephrase that.

I want to noobishly power each sensor with I/O pins and not have said I/O pins being called to interrupt.

I want to use I/O pins AS POWER pins because that's what I want.

If the Arduino Mega is not capable of that, then please politely let me know.

Feel free to virtually slap me upside the head with an electronics book if it makes you feel good.

Can Arduino I/O pins from the Atmega328 be used to provide continuous +5V and Gnd for low power applications without any interrupts to the "emulated power rails" as it were?

Read the datasheet of the ATmega2560 and understand the limits of pins and the package, and read the datasheet of your sensors.

Then you will know whether it's feasible for you to even do what you want.

If you think you can limit wiring this way, you're wrong. It doesn't. It just exposes you to a whole lot of new and issues.

Using I/O to power external modules is generally speaking bad practice.
The output fets of a pin (that pull the pin HIGH or LOW) have an 'on' resistance of about 25 ohm.
You effectively are powering your module through a ~50ohm resistor (VCC + GND).
That could drop supply voltage of the module if it requires short high current peaks.
It will then try to get power through it's I/O pins (phantom-powering), which could be bad too.
Leo..

Thank you very much for giving me those valuable details.

I suppose I should stick to I/O pins for toggling logic ONLY.

I suppose I should rely on the +5 net and Gnd net ONLY when it comes to powering accessories as long as I stay within the limits of the voltage regulator.

Since each pin operates at 5V and can provide or receive a maximum of 40mA current, and has an internal pull-up resistor of 20-50 KOhms which are disconnected by default.

For standard 5mm diameter LEDs the maximum current is usually 20mA, so 10mA or 15mA are suitable values for many circuits. The current must be in amps (A) for the calculation, to convert from mA to A divide the current in mA by 1000.

In other words, I best not try to power more than 2 "regular" LEDs per I/O pin!

It depends on what you mean by "continuous". The pins default to inputs. So if you reset the microcontroller, the power will be lost during the reset and also for the short time when the bootloader is running and before you set the pin mode and state in your sketch code.

Other than that, it should certainly be continuous. If you are not finding that to be the case, you should provide us with more information so we can help with the problem.

Arduino_n00b:
I suppose I should rely on the +5 net and Gnd net ONLY when it comes to powering accessories as long as I stay within the limits of the voltage regulator.

Don't rely on this regulator. Use a 5V power supply instead.

Since each pin operates at 5V and can provide or receive a maximum of 40mA current,

That's the absolute maximum! Design to draw no more than 20 mA per pin. LEDs van be operated at 1-5 mA, usually bright enough. Experiment a bit with different resistor values.

Basically I made a simple project that used an Arduino Mega, 3 MAX6675 thermocouples and a I2C 2004 display.
(The 3 MAX6675 modules are plugged in directly without any wires.)

Problem: The declared GND and VCC pins not staying constant.

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 for "phantom power"
  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);
}

Since each pin I/O operates at 5V and can provide or receive a maximum of 40mA current, and has an internal pull-up resistor of 20-50 KOhms which are disconnected by default, I thought it would work.

The supply current for each thermocouple module falls well within the limits of the I/O pins' current.

Icc of the MAX6675 is 1.2 mA and the onboard module indicator LED is an additional 20 mA at most.

I have been informed that using I/O pins as "phantom-powering" is not the best practice due to the IC's FET on/off impedance and so on but I would like to at least compile some code that can and would do so anyway.

When I run this particular code here, the 3 thermocouple modules are not displaying proper values due to the interrupts on the "phantom-power" pins.

My logic probe clearly indicates this pulsing activity on the pins I declared as Const HIGH as it were.

If the ATmega2560 is not capable of performing this seemingly trivial pursuit, (sigh) then please let me know so that we do not waste each other's time.

Thank you for your input.

Hi,

I have been informed that using I/O pins as "phantom-powering" is not the best practice due to the IC's FET on/off impedance and so on but I would like to at least compile some code that can and would do so anyway.

Why are you using input/output pins as supply to your sensors?
Why not connect the sensor supply pins to 5V and gnd pins of the controller?

Tom.... :slight_smile:

WHY DID I BOTHER!!!!!!!!!!!!!!!!!! :o :o :o :o :o :o

https://forum.arduino.cc/index.php?topic=650773.msg4393721#msg4393721

Why are you cross posting?

WHY DID I BOTHER HERE?????????????????????

https://forum.arduino.cc/index.php?topic=651734.new#new

I've deleted/merged your other cross-post(s) @Arduino_n00b.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Arduino_n00b:
I'll rephrase that.

I want to noobishly power each sensor with I/O pins and not have said I/O pins being called to interrupt.

I want to use I/O pins AS POWER pins because that's what I want.

If the Arduino Mega is not capable of that, then please politely let me know.

Feel free to virtually slap me upside the head with an electronics book if it makes you feel good.

Wow champ, that's a real good way to weed out anyone who might want to help you and reduce the message traffic on your thread...

Just 'cause that's what you want doesn't carry much weight, if it is a really stupid idea and you are a self professed 'noob'. And asking for help and then arguing with the answer (just because you don't want it that way) is really not too bright.

You were politely informed that using I/O for power sources is a bad idea. multiple times... it's not just the Imax of each logic pin, you need to consider the Imax of the chip. And what the heck do you think you are going to do setting the pin to low, isolation? Both source and drain?? hint, the answer is NOTHING useful. If you should need to switch peripheral power for some reason, use the logic pin to drive a FET switch.

Now that I have hammered on you, try the suggestions given you and try to figure out a suitable solution. Don't get too pissed at me. I have been wacked upside the head with the electronics textbook myself from time to time.

Arduino_n00b:
I'll rephrase that.

I want to noobishly power each sensor with I/O pins and not have said I/O pins being called to interrupt.

I want to use I/O pins AS POWER pins because that's what I want.

If the Arduino Mega is not capable of that, then please politely let me know.

Feel free to virtually slap me upside the head with an electronics book if it makes you feel good.

[soapbox]
I would say you want it so all you have to do is plug your breakout PCBs directly into the Mega headers and not use any jumper wires to supply PROPER power to the boards.
I am surprised you didn't ask if there were any "wireless powered" breakout boards.
My answer to you is "What a waste of I/O "
If you make a PCB are you going to do the same thing, or are you going to go to the great effort and place some power supply tracks on the PCB.
Consider yourself slapped...
[/soapbox]
Tom..... :o
PS. Something about this size should do it.