Relais and Temperture

Hi PaulS

This is part of a Amateur Television repeater controller, located on top of a building.

Dont worry, i know what Im doing or creating with electronics.

Half year ago, i have found the Arduino and this is really nice to create projects for my hobby.

It is sometimes only hard to understand how to write some code, but I am doing well so far and most projects are very nice working.

Thats why i have asked here some help, so i can understand how to do.

Any examples are offcourse welcome.

regards,
Ed.

Set a boolean flag, beenLow to false. When the switch is LOW, set the flag to true.

is this what u mean ?

const int Bias_Switch = A5;                                              // the number of the Bias switch analog input pin A5.     
const int Bias_Relais = 2;                                               // the number of the Bias_Relais digital output pin 2.

boolean mySet = false;
boolean Bias;


void setup() {
  pinMode(Bias_Switch, INPUT);                                           // sets analog pin 5 for input.
  digitalWrite(Bias_Switch, LOW);                                        // turn on pullup resistors
  pinMode(Bias_Relais, OUTPUT);                                          // set the digital pin as output.
}
void loop() {
  Bias = digitalRead(Bias_Switch);                                       // read the value DUMMY.
  Bias = digitalRead(Bias_Switch);                                       // read the value from the Bias_Switch.

  if (Bias==true) mySet = true;                                          // set bolean to true     
  else 
    mySet=false;

  digitalWrite(Bias_Relais, mySet); 
}

I have only to add the safety protection in the code

tempC>100

then it must switch off and stay off until i toggle the switch.

but how?

  Bias = digitalRead(Bias_Switch);                                       // read the value DUMMY.
  Bias = digitalRead(Bias_Switch);

Why are you reading the switch twice? Since so little time elapses between readings, the odds are you are going to always get the same value. Does it matter if the readings are different, since the first value is overwritten?

You may be thinking of analogRead(), where, depending on the impedance of the connected device, it may be necessary to read twice, and discard the first value.

Reading a digital device twice, and discarding the first value is never necessary.

  if (Bias==true) mySet = true;                                          // set bolean to true

The digitalRead() function returns HIGH or LOW, not true or false.

No, that is not how I was thinking of using mySet. If the switch becomes HIGH, and mySet is false, ignore the switch. If the switch becomes LOW, and mySet is false, set mySet to true. If the switch becomes HIGH, and mySet is true, then you want to read the temperature and toggle the relay as needed.

Of course, in order to determine that the switch becomes something, rather than is something, you need to keep track of the previous state. Look at the state change detection example.

It sounds like what you want to do is pretty simple, but from the foregoing explanations, I'm not able to understand the requirement. Can you give a bit more detail about what you're switching and why? I'm guessing its a power supply and equipment that heats up and can stay on until the temp is 50 degrees. If 100 degrees is reached (how? because it was turned off at 50) a fan comes on and everything else must be off?

@wildbill

If 100 degrees is reached (how? because it was turned off at 50) a fan comes on and everything else must be off?

the code i had written was >50 and must be original >100 celsius. u right i made a type mistake.

again the explanation where i want to use this for.
I just want to build a safety that it cannot destroy my expansive Amateur TV RF Power Module.
If it reach this very high temp>100 , the problem are the FAN to cool down the RF Power Module.
This is part of a Amateur Television repeater controller, located on top of a building. and not at home.

@ paulS

Why are you reading the switch twice?

i have read more values in my project, when i do not double readings it affecting the actual reading from other inputs / sensors.

ok, i ll now try to change some code to get this protection work.

like this ?

  Bias = digitalRead(Bias_Switch);                                       // read the value DUMMY.
  Bias = digitalRead(Bias_Switch);                                       // read the value from the Bias_Switch.

  if (Bias==HIGH) mySet = false;                                          // set bolean to 
  else  
    mySet=true;
  digitalWrite(Bias_Relais, mySet); 
  
  if (Bias==LOW) mySet = false;                                          // set bolean to 
  else  
    mySet=false;
  digitalWrite(Bias_Relais, mySet);
  
  if (Bias==HIGH) mySet = true && tempC>100;                                          // set bolean to       
  mySet = false;
      digitalWrite(Bias_Relais, mySet);
}

like this ?

Not even close.

You keep saying that the purpose behind this code is to turn a relay, that controls a fan, on when the power supply gets too warm. Fine. But what is this switch for? Why do you want to turn the relay on, to cool off the power supply, only if this switch has been slid back and forth. That's the part I don't understand. That is not any kind of safety.

Does the relay control the "expansive Amateur TV RF Power Module" or does it control the fan?

ok, Im sorry. i try to explain.

This project i am working on is a Hamradio, Amateur Television Transmitter "Radio Frequency Power moduul" that transmit TV signals so people (Hamradio users) can receive it from a large distance.

The equipement are to far away from our hand to control it.
So, to put the device operational it has a switch to turn it on (the relais turn the power on, on the RF moduul). now this part of the equipement is operational. we go home now.

Afther a few day's it seems that the Fan to cool down the RF module, is not working anymore, maybe we have buy a cheap one,,
This Fan is cooling the RF module from the transmitter. When this module is to high temperture it will be destroyed.

1, the on/off switch outside the 19" cabinet must toggle the relais on
2, the fan has it's own control in the code, using for example the LM35

is this clear for u?

is this clear for u?

The parts that you have described, yes.

What kind of switch is it? Momentary contact push button? Toggle switch? Slide switch?

Afther a few day's it seems that the Fan is not working anymore

How is that hardware problem going to be addressed in software?

We're struggling here to understand what the code needs to do.

Hi, PaulS

If i will put the comlete code here, i get to many questions what this is and what for. u will understand.

That can't be your entire code, you need to post all for someone else to find mistakes.

All my other code is working fine, so i dont need to post.

i tought to put a part and working code in the post to get some help how i can solve this protection.

I dont understand all the questions i get.
I just have a simple on / off switch http://www.rc-point.nl/N_frame.html?http://www.rc-point.nl/schakelaar-toggle-2-standen-ON-OFF-6-polig--nr.-70721-Bubble-N_art_65233.php
+5v = HIGH & gnd = LOW (analog input pin 5)

and want to switch on with the code a relais. this is not the issue, toggle the relais on and off.

i just want to switch the relais (digital output pin 5) automatic off and stay off when the temperture reach the >100 celsius. this can only happend when there a problem with the cooling fan.
it must never switch on again unless we manual the switch first off and then back on afther we have repaired the cooling fan. The fan has it's own control in the code, using for example the LM35 and has nothing to do with this relais issue.

i wanna thank u for the help so far. i hope u still can.
if u want i can send u by email the complete project.

Thank u in advange.
ed.

I just have a simple on / off switch

The picture shows a double pole, double throw switch. That is hardly a "simple on/off switch".

A schematic would be good.

i just want to switch the relais automatic off and stay off when there is a problem.
it must never switch on again unless we manual the switch first off and then back on afther we have repaired the cooling fan.

boolean aProblemOccurred = false;

void loop()
{
   if(aProblemOccurred)
   {
      // Turn relay(s) off
   }
   else
   {
   }
}

In the else block, you need to detect a transition from not pressed to pressed to turn the relay on, and a transition from pressed to not pressed to clear the aProblemOccurred flag.

You really must keep track of the previous state of the switch, in order to detect the transitions.

How do you detect that a problem occurred? Is that when the temperature rises over 100 degrees?

Is the fan supposed to be turned on when the temperature is above 50? Is it to be turned off when the temperature is below 50?

The reason that you're getting so many questions is that you have a clear idea of what your hardware is and what you need. We really didn't. I'm still curious about why the system has to stay off once it overheats. Normally, I'd expect to turn it on again when it cools down.

Normally, I'd expect to turn it on again when it cools down.

I think that the idea is that someone goes and looks at the site, to try to determine what caused the system to overheat, before the system is turned back on.

How do you detect that a problem occurred? Is that when the temperature rises over 100 degrees?

yes.

Is the fan supposed to be turned on when the temperature is above 50? Is it to be turned off when the temperature is below 50?

The Fan is seperate controlled by a sensor and speeding from slow to fast when the temperture rises. it will only stop cooling when the temperture is for example <25 celsius

I think that the idea is that someone goes and looks at the site, to try to determine what caused the system to overheat, before the system is turned back on.

Absoluut right

yes.

if(temperature > 100)
  aProblemOccurred = true;

The rest, then, is just a matter of detecting the transition from pressed to released (clear the flag) or from released to pressed (activate the relay(s)) and read the temperature and control the fan.

Without any real data to back this up, I'd be more inclined to software as the cause of your fan problems. From those pictures, the fan appears to be a piece of PC cooling equipment and it looks as though it would be easy enough to swap out to test the theory.

So lets start again, i am a little confused right now.

this is the working code so far. in this code i need to add this protection.

const int Bias_Switch = A5;                                              // the number of the Bias switch analog input pin A5.     
const int Bias_Relais = 2;                                               // the number of the Bias_Relais digital output pin 2.

boolean mySet = false;
boolean Bias;


void setup() {
  pinMode(Bias_Switch, INPUT);                                           // sets analog pin 5 for input.
  digitalWrite(Bias_Switch, LOW);                                        // turn on pullup resistors
  pinMode(Bias_Relais, OUTPUT);                                          // set the digital pin as output.
}
void loop() {
  Bias = digitalRead(Bias_Switch);                                       // read the value DUMMY.
  Bias = digitalRead(Bias_Switch);                                       // read the value from the Bias_Switch.

  if (Bias==HIGH) mySet = true;                                          // set bolean to true     
  else 
    mySet=false;

  digitalWrite(Bias_Relais, mySet); 
}

i have test this sketch and it work!.

Now we need to add the to high temperature protection.

status normal operational:
Bias = HIGH
Bias_Relais = HIGH

My temperture sensor named in the code: tempC

status when there is a "to heat" problem.
tempC>100
Bias = HIGH
Bias_Relais = must be switched automatic to LOW and stay LOW. When the problem on site is fixed, I have to reset manual the BIAS switch to LOW and switsch on back to HIGH.

hope i have explain it a little better now.