Have an issue trying to run two fans on a relay controlled by thermistor

This is only my third project and I am not that familiar with coding.

I have searched and search but can’t find an answer to this. I thought maybe a “for loop” but I can’t figure out how I could make it work. My thought is that both variables that turn on the fans are stuck in the same loop and need to be separated. But I am not sure…

I have two 12VDC fans connected to two separate relays. They are to be controlled by seperate thermistors.

This is just rough, the temp isn’t the issue I just set a range I want them to work in.

The problem is no matter which relay is is high, if I cool one thermistor off the other fan also shuts off. but the LED on the relay board indicating the fan that should still be on is still lit telling me it is still receiving a high signal.

if I pull either data line 10 or 11 from the relay board they both shut off but the one line I didn’t pull off keeps the LED lit as it is receiving a high signal.

#include <LiquidCrystal.h>  // load this library file
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);  // Sets the interface pins up in the library

int val=0;                  // starts val equal to zero
int val2=0;                 // starts val2 equal to zero
int val3=0;                 // starts val3 equal to zero
int val4=0;                 // starts val4 equal to zero

const int TempS=A5;
const int TempS2=A3;

const int Relay1 = 10;
const int Relay2 = 11;

const int low=492;          // low end of temp
const int high=505;         // high end of temp

const int low2=492;          // low end of temp
const int high2=505;         // high end of temp

byte degree[8] = {
   B00110,
   B01001,
   B01001,
   B00110,
   B00000,
   B00000,
   B00000,
   B00000,
};

  void setup()
    {
      Serial.begin(9600);
      
      pinMode (Relay1,OUTPUT); // set Relay1 as output
      pinMode (Relay2,OUTPUT); // set Relay2 as output
      
      lcd.begin(16, 2);        // sets the LCD up with columns and rows
      lcd.print("FAN 1     FAN 2");  // prints txt at default location 0,0
      lcd.createChar(0,degree);  // set degree special character to 0
      lcd.setCursor(3,1);  // move cursor to second line 3th position
      lcd.write((byte)0);  // display the degree special character
      lcd.setCursor(4,1);  // set cursor to the second line 4th position
      lcd.print("C");
      
      lcd.setCursor(13,1);  // move cursor to second line 13th position
      lcd.write((byte)0);  // display the degree special character
      lcd.setCursor(14,1);  // set cursor to the second line 14th position
      lcd.print("C");
    }
  void loop()
    {
      val = analogRead(TempS);
      val3 = analogRead(TempS2);
        if (val >= high)  
           {
           digitalWrite(Relay1,LOW);
           }
        else
          {
           digitalWrite(Relay1,HIGH);
          } 
        if (val3 >= high2)
          {
           digitalWrite(Relay2,LOW);
          }
        else
          {
           digitalWrite(Relay2,HIGH);
          }        
          {
        val2 = map(val, low, high, 20, 30);
        val4 = map(val3, low2, high2, 20, 30);
          }
            {
              lcd.setCursor(0,1);    // move cursor to second line, 0 position
              lcd.print(val2);       // sends mapped equiv to LCD
              delay(1000);           // 1 second delay
              
              lcd.setCursor(10,1);    // move cursor to second line, 10th position
              lcd.print(val4);       // sends mapped equiv to LCD
              delay(1000);           // 1 second delay
            }
     }

Your problem is not a software issue, but a wiring or circuit design issue.

Please post a schematic and/or a picture.

Added: You also have unneeded open and closing brackets in your code. See under this line "digitalWrite(Relay2,HIGH);"

   else
          {
           digitalWrite(Relay2,HIGH);
          }        
          {                                                  // <----- remove
        val2 = map(val, low, high, 20, 30);
        val4 = map(val3, low2, high2, 20, 30);
          }                                                  //<----- remove

You are correct, as soon as I read your post I went back and looked at my diagram and retraced my wires and I did have the grounds in the wrong location..

Thank you very much, my haste caused me to overlook the simple issue and blame the problem on the code since I am not as familiar with it.

Thanks again!

Its ok, it happens. Im glad to hear its working now.