# Programing help with temperature

Hi all

I have an arduino uno with network shield, a twin relay board, an ultrasonic level sensor and a BMP180.

The whole thing works perfect. It controls a fairly complex machine that sucks out maple sap out of maples under vacuum.

Maples sugar !

Anyways, temperature is the game with maples.

With the bmp180 i can read and control a relay based on temperature.

Right now, i only make it run between -5C -20C.

That works fine.

My issue becomes the introduction of this new issue.

I want the machine to RUN until FALLING temperature reach -5C.

But i dont want it to restart until RISING temperature reaches 1C.

I have been using

If ((T) > -5) {then do this}

It works but makes no distinction between falling and rising temperature.

Any clue on where to start?

Thanks

T

Btw the machine is at

Http://macabanasuc.ddns.net:81

The only thing i could find is something like this.

Magician:
I’ll calculate average “1 hours” value, summing up 12 digit and divide a sum by 12. S(i) = ( T1 + T2 +…+T12 ) / 12.
Than trend is a differential of two S, current and previous:
if ( S(i-1) > S(i) ) trend = “Down”;
if ( S(i-1) < S(i) ) trend = “Up”;
if ( S(i-1) == S(i) ) trend = “Steady”;

But i cannot put it in the perspective ofvariables …

Im unexperimented and learning

T

Well, first you need to determine how fast the temperature can change 1 degree C. That tells you how often you need to check the temperature value. Then each time period, compare the new temperature to the previous temperature. If old temp < new temp, then temp is going up. If old temp > new temp, then temp, then temp is going down. After comparing, move new temp value to old temp value.

Paul

So basically create a

Int trend.

If ((trend = rising) &&
((T) > 1))
{Start the machine}

If ((trend = falling)&&
(Machine is on)&&
((T) < -5))
{Shut down the machine}

I just cannot comprehend how to create the falling and rising variables in a way to program the arduino.

Any help with this basics?

T

Put your sketch or part of it.so we can help u.

How are you measuring T ?
Make an array where you store some values. Apply required delay between each T measure.
Calculate the slope of T.
To implement you can use the idea for blink without delay ...a state machine

I want the machine to RUN until FALLING temperature reach -5C.
But i don’t want it to restart until RISING temperature reaches 1C.

I just cannot comprehend how to create the falling and rising variables in a way to program the arduino.

Instead of needing to define a rising or falling trend, I think you can just add hysteresis to the turn on and turn off with something like this.

``````if(T<= -5)
{turn machine off}

if(T>=1 && T<=18)
{turn machine on}

if(T>=20)
{turn machine off}
``````

This code will run the machine if the temperature was greater than 1 but then varies up and down between 1 and -5 but doesn’t actually reach -5.

If the temperature does reach -5, the machine will not be running if the temperature varies up and down between -5 and 1 but doesn’t actually reach 1.

Is that what you want?

Hi,
I wrote small routine that will do what I thinking it is what you are looking for. The only you need to do it is add the temperature variable and see it is work. Again I do not know if this is what you are looking.

byte pinxx = 0;//turn on mchine pin output
int T ; //temperature variable
void setup() {
// put your setup code here, to run once:
pinMode(pinxx , OUTPUT); //nachine turn on pin
}

void loop() {
// put your main code here, to run repeatedly:
//instruction here to get the temperature T=xxxx
if (T >= 1) {
temp_falling(); //wait until temperature reach 1 degree +
}
delay(1000);
}
//***************************************************
void temp_falling() {
digitalWrite(pinxx, HIGH); //turn the machine ON
do {
//loop here until temperature drop to -5
//instruction to get the temperature T= xxxx
} while (T < -4);
digitalWrite(pinxx, LOW); //turn the machine OFF
}
//****************************************************

Hi,

if (Machine On and temp < -5)
{ turn Machine OFF}

if (Machine OFF and temp > 1)
{ turn Machine ON}

Any simpler than that?
Takes care of trending.

Try it.

Tom…

here is the whole code.

it is too large to copy/paste so ive attached extracteurmaisonv4.ino

extracteurmaisonv4.ino (13.5 KB)

my relays have to be low to turn on my circuits.

Vacuum_relay_pin powers a relay that then sends 120v to another huge relay. the vacuum compressor runs on 240V

that’s the output that needs a different shut-down temperature than start-up temp.

it needs to run until falling temps go under -5C

it needs to stay off until rising temp go over 1C

that’s the part of code that deals with temperature, level sensors and relays.

``````char status;
double T,P,p0,a;

Serial.println(T);
//check to see the state of the float switches.
//empty
((T) < 20)
)
{
digitalWrite(Pump_relay_Pin, HIGH); //Keep pump off
digitalWrite(Vaccum_relay_Pin, LOW); //Start Vacuum

Serial.println("empty, vaccum started");

}

//startup
)
{
digitalWrite(Pump_relay_Pin, LOW); //start pump
digitalWrite(Vaccum_relay_Pin, LOW); //Keep vacuum running
Serial.println("Pumping");
}
//safety shut-off

{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, LOW); //keep pump running for:
Serial.println("ERREUR EXTRACTEUR!");
delay(90000);
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
delay(500000000000000);

}
// temperature shut off

if ((T) < -5)
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop frette!");

}

if ((T) > 20)
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop chaud!");

}
``````

would this work?

``````char status;
double T,P,p0,a;

Serial.println(T);
//check to see the state of the float switches.
//empty
(digitalRead(Vaccum_relay_Pin) == HIGH) && //vaccum has to be off to start
((T) > 1)
)
{
digitalWrite(Pump_relay_Pin, HIGH); //Keep pump off
digitalWrite(Vaccum_relay_Pin, LOW); //Start Vacuum

Serial.println("empty, vaccum started");

}

//startup
)
{
digitalWrite(Pump_relay_Pin, LOW); //start pump
digitalWrite(Vaccum_relay_Pin, LOW); //Keep vacuum running
Serial.println("Pumping");
}
//safety shut-off

{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, LOW); //keep pump running for:
Serial.println("ERREUR EXTRACTEUR!");
delay(90000);
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
delay(500000000000000);

}
// temperature shut off

if (((T) < -5) &&
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop frette!");

}

if (((T) > 20) &&
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop chaud!");

}
``````

``````if ((digitalRead(Startup_Pin) == HIGH) &&
(digitalRead(Vaccum_relay_Pin) == HIGH) && //vaccum has to be off to start
((T) > 1)
)
{
digitalWrite(Pump_relay_Pin, HIGH); //Keep pump off
digitalWrite(Vaccum_relay_Pin, LOW); //Start Vacuum

Serial.println("empty, vaccum started");
}
``````

and

``````// temperature shut off

if (((T) < -5) &&
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop frette!");

}

if (((T) > 20) &&
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop chaud!");

}
``````

that solves it ? doesn’t it ?

I made a few changes …

I run a pump in the setup section to make sure some float goes high so the loop works no matter what situation it was shut down under.

could you please help me check to make sure the vacuum will turn on at -1C and shut off at -5C or over 20C

T

extracteurmaisonv5.ino (14.2 KB)

``````  double T,P,p0,a;

Serial.println(T);
``````

Create a local variable, but don’t initialize it. Print its contents as though they meant something.

Why?

``````    delay(500000000000000);
``````

Get f**king real.

could you please help me check to make sure the vacuum will turn on at -1C and shut off at -5C or over 20C

Of course it won’t. Would you care to show which line(s) of code actually assign a value to T?

``````status = pressure.getTemperature(T);
``````

I assume this line reads the temperature. Then

``````// temperature variables

if (((T) < -5) &&
(digitalRead(Vaccum_relay_Pin) == LOW)); // vaccum has to be on to shut off
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, LOW);
delay(90000);
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop frette!");

}

if (((T) > 20) &&
(digitalRead(Vaccum_relay_Pin) == LOW)); //vaccum has to be on to shut off
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop chaud!");

}

if (((T) > -1) &&
(digitalRead(Vaccum_relay_Pin) == HIGH)); //vaccum has to be OFF to start
{
digitalWrite(Vaccum_relay_Pin, LOW); //turn on the vacuum
Serial.println("vacuum parti");

}
``````

Where does the pump get turned back on when T>-1?

Why is there no delay time on the pump turn off at hight temp but there is at low?

The pump is tripped by liquid level

Not temperature

Seems to work

But still an issue with temperature

Delay (tons)
Is a safety shut down …

I want to make sure the whole thing quits for a long time. The only way it will restart is with a manual reset.

If the liquid level goes past that safety point, i wreck a vacuum pump.

Liquid will freeze unless i make the pump pump it out before it shuts down. No need for that on a high temp shutdown.

T

But still an issue with temperature

What do you mean. What problems are you seeing with the revised code?

here is a drawing of the machine.

I think I also need help in understanding a few issues my code has.

I think I might have found a few like these:

if the manifold wasn’t empty, then the compressor wouldn’t start.

ive put this in the setup :

``````if (digitalRead(Empty_Pin) == LOW) // if the manifold is not empty
{
digitalWrite(Pump_relay_Pin, LOW); //empty the manifold
}
else
{
digitalWrite(Pump_relay_Pin, HIGH);
}
``````

i removed the vaccum starting from the liquid level variables.

safety is the only level that should make the vacuum turn off

it is up right now …

http://macabanasuc.ddns.net:81

it posts temperature and other useful data.

the only reason the code is this long is so i can monitor it remotely with ETHERNET.

the whole code posted below.

extracteurmaisonv5.1.ino (13.9 KB)

``````if (((T) <= -5 ) &&
(digitalRead(Vaccum_relay_Pin) == LOW)) // vaccum has to be on to shut off
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop frette!");
}
``````

or

``````if (((T) <= -5 ) &&
(digitalRead(Vaccum_relay_Pin) == 0)) // vaccum has to be on to shut off
{
digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump
Serial.println("toute a OFF Trop frette!");
}
``````

when I do a

I get either a 0 or 1 on the website

does LOW and HIGH work?

T

LOW == 0
HIGH == 1

Relays are often active LOW.

I know LOW is 0 and HIGH is one. does the code recognize both codes above? if not , which way is right ?

HIGH or 1 ?

thanks

T