Thank you for the answers.
Let me copy the entire code to avoid any misunderstanding
const byte tempPin[] = {A1, A2, A5, A4}; //defining the LM35 temp sensors input pins as constant byte to avoid changing it. Value from 0 to 255
const byte relayPin[] = {6, 7, 8, 9}; //defining the relay output pins as constant byte to avoid changing it. Value from 0 to 255
// hysteresis = upperLimit - lowerLimit
const byte lowerLimit = 28;
const byte upperLimit = 32;
float tempC[4]; //creating the 4 temp inputs inside an array. Float to deal with decimals
const int numReadings = 25; // defining the number of readings to create an average with
word printInterval = 1000; // 1 second
unsigned long lastPrintTime = 0;
void setup()
{
analogReference(INTERNAL); //Using the internal 1.1v reference for better resolution on the analog pin readings
Serial.begin(115200); // Setting 115200 baud ratio for communication
for (int i = 0; i < 4; i++) { //starting with i = 0 and as long as i is less than 4, go through the loop and then add 1 to i value
pinMode(relayPin[i], INPUT_PULLUP); //Sets the relay pins as pullups. This is to avoid floating state for the pins.
pinMode(relayPin[i], OUTPUT); // sets the relay pins as outputs, defaults state HIGH, relay OFF
}
}
void loop()
{
// readings and control
for (int i = 0; i < 4; i++) {
float raw_temp = analogRead(tempPin[i]) / 9.31;
tempC[i] += (raw_temp - tempC[i]) / numReadings;
if (tempC[i] < lowerLimit) {
digitalWrite(relayPin[i], LOW); //relay ON
}
else if (tempC[i] > upperLimit) {
digitalWrite(relayPin[i], HIGH); // relay OFF
}
}
if (millis() - lastPrintTime >= printInterval) {
for (int i = 0; i < 4; i++) {
Serial.print("tempC");
Serial.print(i + 1);
Serial.print(" ");
Serial.println(tempC[i]);
}
Serial.println();
lastPrintTime = millis(); // reset print timer
}
}
Am I using the input_pullup for nothing, then? Because that is stated in the setup, so there's no reset involved.
Output then doesn't have a floating state and I shouldn't use it?
Thanks in advance.