Go Down

Topic: Programing help with temperature  (Read 867 times) previous topic - next topic

cattledog

Quote
But still an issue with temperature
What do you mean. What problems are you seeing with the revised code?

tobielepine

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 :

Code: [Select]


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.



tobielepine

Code: [Select]


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

Code: [Select]


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

client.print(digitalRead(Vaccum_relay_Pin));

I get either a 0 or 1 on the website

does LOW and HIGH work?

T

cattledog

#18
Mar 18, 2017, 09:24 pm Last Edit: Mar 18, 2017, 09:25 pm by cattledog
LOW == 0
HIGH == 1

Relays are often active LOW.

tobielepine

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

tobielepine

does the following make sense?

Code: [Select]


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("too cold!");
     }

  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("too hot!");
   }
   if (((T) >= -1 ) &&
 (digitalRead(Vaccum_relay_Pin) == HIGH)) //vaccum has to be off to turn on
  {
    digitalWrite(Vaccum_relay_Pin, LOW); //turn on the vacuum!
    Serial.println("vaccuum is on");
   }




Paul_KD7HB

does the following make sense?

Code: [Select]


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("too cold!");
     }

  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("too hot!");
   }
   if (((T) >= -1 ) &&
 (digitalRead(Vaccum_relay_Pin) == HIGH)) //vaccum has to be off to turn on
  {
    digitalWrite(Vaccum_relay_Pin, LOW); //turn on the vacuum!
    Serial.println("vaccuum is on");
   }




When you begin to see signs of code lines being used more than once, that tells you to make that piece of code into function.

Call this code:
 digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
    digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump


A function such as:

shut_both_off(){
         digitalWrite(Vaccum_relay_Pin, HIGH); //shut the vacuum off!
         digitalWrite(Pump_relay_Pin, HIGH); //shut off the pump

         };

And replace where these lines are in your code with: shut_both_off();

Soon you complex logic will become much easier to follow.

Paul

tobielepine

I should upload version 5.1.1 so you can see my progress ...

I also cleaned up the code ....

Im looking at the machine right now, as some of you on the website might have noticed, i now have bilingual labels haha.

And the flush counter has reset.


Ill post my new code shortly

tobielepine



changes to 5.1.2 will involve

giving wider margins for temperature to save the relays

give 10ms for the browser to receive data cause the connection is quite sparce.

refresh the browser every 10 seconds instead of 5

log (Startup_Pin) with date and time.

display last 10 time startup pin went LOW on the browser.

T





tobielepine

can I put an

if inside an if?

such as

if (conditions)
 {
do this
if (conditions)
{
also do this
}
 }

such as

if (temp is too low + vaccum is on)
{turn the vaccum off
if (empty_pin is LOW)
 {turn pump on until empty_pin is HIGH}
}

is there such a thing as UNTIL ?

(like do this) UNTIL (this)

how to put in code?

thanks


T


cattledog

Code: [Select]
#include <Bounce2.h>
Bounce debouncer = Bounce();
debouncer.attach(Startup_Pin); //bouncing liquid level could trip it twice


After this point, you never actually use the Bounce2 library to read the pins, but call digitalRead(Startup_Pin) multiple times.   Please take another look at the library examples for Bounce2. You need to be calling debouncer.update() and debouncer.read().

Quote
can I put an if inside an if?
Code: [Select]
if (temp is too low + vaccum is on)
{turn the vaccum off
if (empty_pin is LOW)
 {turn pump on until empty_pin is HIGH}
}


Yes.

Quote
is there such a thing as UNTIL ?
(like do this) UNTIL (this)
how to put in code?
Certainly. How to code this depends on "until what?".  Is a timed event or an input driven event  Please try explain in more detail what you are trying to accomplish.

PaulS

Quote
can I put an

if inside an if?
Yes



you



can.


You need to go inside and warm those fingers up...
The art of getting good answers lies in asking good questions.

tobielepine

Code: [Select]
#include <Bounce2.h>
Bounce debouncer = Bounce();
debouncer.attach(Startup_Pin); //bouncing liquid level could trip it twice


After this point, you never actually use the Bounce2 library to read the pins, but call digitalRead(Startup_Pin) multiple times.   Please take another look at the library examples for Bounce2. You need to be calling debouncer.update() and debouncer.read().
such as ?
put in the loop
Code: [Select]

debouncer.update(Startup_Pin)


then

Code: [Select]

debouncer.read(Startup_Pin)


instead of
Code: [Select]

digitalRead(Startup_Pin)



Code: [Select]
if (temp is too low + vaccum is on)
{turn the vaccum off
if (empty_pin is LOW)
 {turn pump on until empty_pin is HIGH}
}

Yes.

Certainly. How to code this depends on "until what?".  Is a timed event or an input driven event  Please try explain in more detail what you are trying to accomplish.

UNTIL Empty_pin is HIGH.

tobielepine

a few questions to make sure im doing the bounce right

in my setup is


  debouncer.attach(Startup_Pin); //bouncing liquid level could trip it twice
  debouncer.interval(50); // interval in ms


here are the lines I added/modified in the loop section

debouncer.update();

int S_U_P = debouncer.read(); //bounced startup pin

,

if (S_U_P == LOW)

,

 switchState = digitalRead(S_U_P); //flush counter

,





client.print(digitalRead(S_U_P));

instead of

client.print(digitalRead(Startup_Pin));


do I need to use digitalRead with S_U_P ... int ???

do I need
debouncer.update();
every time I use S_U_P ??


thanks

T

cattledog

Quote
such as ? put in the loop
Code: [Select]
debouncer.update(Startup_Pin)
debouncer.read(Startup_Pin)

Yes.

It's interesting to see the website update.  What is the vacuum reading from analogRead of A0 (for example vaccum 0 is -13.73 InHg ) and its relationship to the pressure reading from the BMP sensor.

Code: [Select]
if (temp is too low + vaccum is on)
{turn the vaccum off
if (empty_pin is LOW)
 {turn pump on until empty_pin is HIGH}
}


It's a little tricky to do this in a compound nested if statement because once you turn the vacuum off you don't enter the condition any more. I think you could do something like this where the conditions are not nested

if (temp is too low + vacuum is on)
{
 turn the vacuum off
}

if (temp is too low && digitalRead(empty_pin) == LOW && pump is off)
{
 turn pump on
}
if (temp is too low && digitalRead(empty_pin) == HIGH && pump is on)
{
 turn pump off
}


As a matter of philosophy I'm not sure why you are always placing machine state conditions in your compound conditions. For example, the vacuum is on until you turn it off, and off until you turn it on. I don't see why you need to check that the vacuum is on before turning it off. Why would it not be on?


Go Up