Three inputs to control single output(led)

having hard time figure out what type of statement id use for what im trying to accomplish.


pot1 value needs to turn on led based on val1 (which i have working with an if statement)
pot2 value needs to keep the led on till Val1 is below the value of pot2

not sure if this makes sense but im trying to build a fan controller that will hit a temp higher than the off temp value and then run till it hits that off temp value.

note: delay is there just to slow down sketch

int ThermistorPin = 0;
int Vo;

const int Pot = 1;
int sensorValue1 = 0;
int outputValue1 = 0;

const int Pot2 = 2;
int sensorValue2 = 0;
int outputValue2 = 0;

const int ledPin = 2;
float R1 = 10000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
void setup() {
pinMode(ledPin, OUTPUT);

void loop() {
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  T = T - 273.15;
  T = (T * 9.0)/ 5.0 + 32.0; 

  sensorValue1 = analogRead(Pot);      //gets pot valve
  outputValue1 = map(sensorValue1, 0, 1023, 0, 1023);

  sensorValue2 = analogRead(Pot2);      //gets pot2 valve
  outputValue2 = map(sensorValue2, 0, 1023, 0, 1023);
  int ThermistorPin = analogRead(Vo);   //sets valve to turn on led (output)
  if (Vo > outputValue1) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);

  Serial.print("Pot: ");

  Serial.print("Pot2: ");

  Serial.print("Temperature: "); 
  Serial.println(" F");

  Serial.print("Raw ");

Pot 1 gives the desired value.
Pot 2 sets the maximum allowed value. Right?

not sure if this makes sense but im trying to build a fan controller that will hit a temp higher than the off temp value and then run till it hits that off temp value.

Not exactly.
Can You try using an other explanation? Pot 2 is max and Pot 1 is the desired value.
The writing about over temperature I don't understand.

What happens and what's wanted?

Pot1 sets on temperature which is higher than the off temperature which is set by pot2

Value is just the thermistor resistance

So example:

On temp is 195f
Turn fan on till off temp of 185f but have it be adjustable by the pots

It would be easier if you have fixed temperatures in the sketch.

Potentiometer 1 sets the high temperature, to turn on the fan when it gets too hot.
Potentiometer 2 sets the low temperature, when the fan can be turned off.

What should happen when potentiometer 2 is set higher than potentiometer 1 ? I suggest to keep the fan on for safety and turn the fan off when the temperature is below both potentiometers.

I would like to add a variable that tells if the fan is on or off. It is not needed, but I think the sketch will be better.

if( temperature > high_temperature_setting)
  if fan is not on, then turn on the fan
else if( temperature < low_temperature_setting && temperature < high_temperature_setting)
  if fan is not off, then turn off the fan

I made a Wokwi simulation for your sketch: It is your sketch, I have only changed the output to the Serial Monitor.

I'm looking to have this project be fully programming without a pc. It's gona have a display and hopefully store the values in the eeprom so they're saved when power is cut


  outputValue1 = sensorValue1;

Try this sketch. You may make some edits to this sketch wrt to your reqiuerements.

#define ProjectName "Three Inputs to control single output(led)"
// you may need to change these constants to your hardware
constexpr byte Temp_[] {A3, A4, A5}; // connection to LowPot, HighPot, InSensor
constexpr byte Output_[] {2};        // connection to indicator
constexpr unsigned long measurementInterval {1000};
enum {One};
enum {LowPot, HighPot, InSensor};
struct TEMP {
  byte pin;
  int   min_;
  int   max_;
} temp [] {
  {Temp_[LowPot], 0, 511},
  {Temp_[HighPot], 512, 1023},
  {Temp_[InSensor], 0, 1013},
struct TIMER {
  unsigned long duration;
  unsigned long stamp;
  bool control_;
TIMER readTemp {measurementInterval, 0, true};
struct LED {
  byte pin;
LED led {Output_[One]};


void setup() {
  Serial.println(F("File   : ")), Serial.println(__FILE__);
  Serial.println(F("Date   : ")), Serial.println(__DATE__);
  Serial.println(F("Project: ")), Serial.println(ProjectName);
  for (auto Output : Output_) pinMode(Output, OUTPUT);
  // check outputs
  for (auto Output : Output_) digitalWrite(Output, HIGH);
  for (auto Output : Output_) digitalWrite(Output, LOW);
void loop () {
  unsigned long currentTime = millis();
  digitalWrite(LED_BUILTIN, (currentTime / 500) % 2);

  if (currentTime - readTemp.stamp >= readTemp.duration && readTemp.control_) {
    readTemp.stamp = currentTime;
    int tempMin =      map(analogRead(temp[LowPot].pin),  temp[InSensor].min_, temp[InSensor].max_, temp[LowPot].min_,   temp[LowPot].max_);
    int tempMax =      map(analogRead(temp[HighPot].pin), temp[InSensor].min_, temp[InSensor].max_, temp[HighPot].min_,  temp[HighPot].max_);
    int tempInSensor = map(analogRead(temp[InSensor].pin), temp[InSensor].min_, temp[InSensor].max_, temp[InSensor].min_, temp[InSensor].max_);
    Serial.print("\nread temp tempInSensor: "); Serial.println(tempInSensor);
    if (tempInSensor < tempMin) {
      digitalWrite(, HIGH);
      Serial.print("read tempMin: "); Serial.println(tempInSensor);
    if (tempInSensor > tempMax) {
      digitalWrite(, LOW);
      Serial.print("read tempmax: "); Serial.println(tempMax);

Have a nice day and enjoy coding.

Will check this out later, thank you.