If I am correct in my understanding of what you want in my reply #19 then something like the following will work:
Note the following suggestion is based on blocking code, something I am usually at pains to avoid. Also I am using a tablet to type, so I can't test anything and there might be errors.
void setup () exactly as you have it in reply #9, but note my comment about using unsigned int instead of float.
Loop:
void loop() {
// put your main code here, to run repeatedly:
//Read sensor values
SensorReading1 = analogRead(sensor1);
SensorReading2 = analogRead(sensor2);
SensorReading3 = analogRead(sensor3);
if ( SensorReading1 > ValueHigh) {
digitalWrite(R1, HIGH); //on
while (SensorReading1 >ValueLow) {
// This is the blocking part, having started pump 1
// The pump runs until sensor 1 reports the temperature has dropped sufficiently
// The other 2 sensors are not read, there is no point if you don't want their pumps to run
} // End of while loop
digitalWrite(R1,LOW); //off
}
if ( SensorReading2 > ValueHigh) {
digitalWrite(R2, HIGH); //on
while (SensorReading2 >ValueLow) {
// This is the blocking part, having started pump 2
// The pump runs until sensor 2 reports the temperature has dropped sufficiently
// The other 2 sensors are not read, there is no point if you don't want their pumps to run
} // End of while loop
digitalWrite(R2,LOW); //off
}
if ( SensorReading3 > ValueHigh) {
digitalWrite(R3, HIGH); //on
while (SensorReading3 >ValueLow) {
// This is the blocking part, having started pump 3
// The pump runs until sensor 1reports the temperature has dropped sufficiently
// The other 2 sensors are not read, there is no point if you don't want their pumps to run
} // End of while loop
digitalWrite(R3,LOW); //off
}
}
Thank you @bitherder_57 I have tried that too and gave me the same result.
I noticed that you have not made A0, A1, and A2 inputs. I know they default to inputs on reset but it is good programming practice to define them explicitly.
@xfpd I altered my code now to only use a single ValueHigh and ValueLow to simplify things. All sensors are on a single roof so they will actually all experience the same heat, hence it makes more sense to use a single ValueHigh and ValueLow for all. But thanks for trying to make the previous code work
Thank you @PerryBebbington I will correct the float to int as you recommended and try this code. I also wanted to avoid using a while loop as I like to constantly run through the entire program rather than potentially getting stuck in an infinite loop, but its a good start and if its the correct solution so be it. Thanks again
I agree with not using while loops as you say. I am on holiday using a tablet so I don't want to try writing something better without having access to my computer and the IDE. I can certainly write something better without the while loop, but it will have to wait, sorry. Try that, let me know if it does what you want. A proper solution would need a state machine.