Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Relay

Status
Not open for further replies.

chandu13

New Member
Hi

Can you provide code for operating relay with microcontroller? I have written the code for relay please check wither it is Suitable for relay operations or not .Please provide suitable code for Relay operations.


If (temperature>=30C)
{
Relay1=1; //Relay ON//
}

Else

If (temperature>=60C)
{
Relay1=1; //Relay OFF/
}




Thank you

Regards
chandu
 
Looks like a lot of the code is missing.

Maybe.

Code:
If (temperature>=30C)
{  
    Relay1=1;   //Relay ON//
}
 
If (temperature>=60C)
{  
Relay1=0; //Relay OFF//
}
 
Last edited:
Coding problems.

Say the temperature is 61C, so the relay turns OFF.

Then program loops again from the top down.

As "temperature>=30C" is now true, relay turns ON again then it turns OFF again as temperature>=60C is now true. You have a chattering relay.
 
chandu13: What is the goal of this code as far as temp?

You need something like:
Code:
while 1=1 
  if temp<=60 and temp>=30 
     relay on
  else 
     relay off
  endif
  delay minutes
wend
 
chattering

Thanks for the reply

Sorry for my post there I made one mistake in the code.
The code is

If (vacuum<=1.6E-2)
{
Relay1=1; //Relay ON//
}

Else
If (vacuum>=1.8E-8)
{
Relay1=0; //Relay OFF/
}


In chamber generating the high vacuum is very slow processes. Due this aim facing chattering problem.

How to avoid the relay chattering problem using software or Hardware.

Regards
chandu
 
If that's real MCU code the relay isn't going to chatter, the I/O change is going to occur so fast it won't have a chance to turn the relay on. It's still better to code it like Mramos said suggested though.
 
Sceadwian said:
If that's real MCU code the relay isn't going to chatter, the I/O change is going to occur so fast it won't have a chance to turn the relay on. It's still better to code it like Mramos said suggested though.

So 50% PWM on the relay coil then. How about turning the relay OFF if it is already ON?

It might not chatter but what happens with half the voltage across the relay coil?

It could stay ON forever.
 
Pulsing a rulay is a pretty common way of saving power; you use a long pulse to turn it on, then <50% duty cycle to keep it on but only use half the amount of power.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top