 # How to make a relay on one times stay for 2 second and stop?

I'm a newbie and trying to find a way to make sketch. I need to on normally connected relay on and staying 2 second and then stop. please reply urgently. Its very urgent need for me.

(deleted)

If it was really that urgent I think the OP would have taken a little time to think about what sorts of details someone might need to help him and would have included that from the beginning so as not to waste time. Imagine how much of this precious time we're going to have to waste now asking him what relay, what arduino, what else the code has to do, etc. If it was really so urgent, there would have been more sentences describing the project than there were sentences exclaiming the urgency.

OP, do you know how to connect your relay to the Arduino (something you can google for yourself) or how to write a value to a pin to turn in on or off (read the reference material on this site)? Have you heard of the delay method (again, the ref here or google)? If you know that, then what exactly is stopping you from doing what you want? It's trivial. If you don't know those things then why haven't you taken the time to investigate before coming here with this vague question?

spycatcher2k: You know this is forum speak for 'I want to jump the queue'

and because of that, I'm out! >:(

I like the idea from the Bar about any thread with "urgent" in it gets pinned to the top of the second page.

I like the idea from the Bar about any thread with "urgent" in it gets pinned to the top of the second page.

I'd prefer the bottom of the last page.

Do an if millis minus previousmillis is greater then the interval and within that if statement you can digitalWrite the relay to on. After the digitalWrite you could say previousmillis equals to millis. Then you may want to try and do an else and digitalWrite the relay off. It would then forever turn on and off 2 seconds at a time.

#include <LiquidCrystal.h>
int sump=A0;
int qut=A1;
int hlf=A2;
int thf=A3;
int ful=A4;
int motor=8;
int nvc=9;
int buz=7;
int s;
int q;
int h;
int t;
int f;
int i; //motor status flag
int v=100; //comparison variable(needs some adjustment)
int b=0; //buzzer flag
int m=0; //motor flag
int n=0; //DOL nvc flag
int c=0; //sump flag

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{

pinMode(qut,INPUT);
pinMode(hlf,INPUT);
pinMode(qut,INPUT);
pinMode(ful,INPUT);
pinMode(sump,INPUT);
pinMode(motor,OUTPUT);
pinMode(nvc,OUTPUT);
pinMode(buz,OUTPUT);
lcd.begin(16, 2);
digitalWrite(buz,LOW);
digitalWrite(nvc,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“RoboPump WATER”);
lcd.setCursor(0,1);
lcd.print(“LEVEL CONTROLLER”);
delay(100);

}

void loop()
{

lcd.clear();

if(f>v && t>v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.print(char(255));
lcd.print(char(255));
lcd.print(char(255));
lcd.print(char(255));
lcd.setCursor(5,0);
lcd.print(“TANK FULL”);
m=0;
b=0;
}
else
{
if(f<v && t>v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.print(char(255));
lcd.print(char(255));
lcd.print(char(255));
lcd.print(char(219));
lcd.setCursor(5,0);
lcd.print(“LAVEL 03”);

b=0;
}
else
{
if(f<v && t<v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.print(char(255));
lcd.print(char(255));
lcd.print(char(219));
lcd.print(char(219));
lcd.setCursor(5,0);
lcd.print(“LAVEL 02”);

b=0;
}
else
if(f<v && t<v && h<v && q>v)
{
lcd.setCursor(0,0);
lcd.print(char(255));
lcd.print(char(219));
lcd.print(char(219));
lcd.print(char(219));
lcd.setCursor(5,0);
lcd.print(“LAVEL 01”);

b=0;
}
else
{
if(f<v && t<v && h<v && q<v)
{
lcd.setCursor(0,0);
lcd.print(char(219));
lcd.print(char(219));
lcd.print(char(219));
lcd.print(char(219));
lcd.setCursor(5,0);
lcd.print(“TANK EMPTY”);
m=1;
b=0;
}
else

{
digitalWrite(motor,LOW);
lcd.setCursor(0,0);
lcd.print(“ERROR!”);
b=1;
}
}}}
if(i==HIGH)
{
lcd.setCursor(0,1);
lcd.print(“PUMP ON”);
}
else
{
lcd.setCursor(0,1);
lcd.print(“PUMP OFF”);
}

if(s>v && m==1)
{
digitalWrite(motor,HIGH);
digitalWrite(nvc,LOW);
}
if(s<v)
{
digitalWrite(motor,LOW);
digitalWrite(nvc,HIGH);
lcd.setCursor(10,0);
lcd.print(" Low");
lcd.setCursor(11,1);
lcd.print(" Sump");
c=1;
}
if(s>v)
{
c=0;
}

if(m==0)
{
digitalWrite(motor,LOW);
digitalWrite(nvc,HIGH);
}

if(b==1 || c==1)
{
digitalWrite(buz,HIGH);
delay(500);
digitalWrite(buz,LOW);
}
else
{
digitalWrite(buz,LOW);
}
delay(100);
lcd.clear();
}

This is my code but I want to change some this section.

if(m==0)
{
digitalWrite(motor,LOW);
digitalWrite(nvc,HIGH);
}

I need when nvc is ones HIGH after 2 second its goes low and not repeat HIGH.

There is a lot more in that code than you let on in the initial post. However, if your need is urgent why are you still trying intentionally to slow things down.

If your need is really urgent, then it would have been a good idea to read the "How to use this forum" thread before you started. Now we have to waste the time to tell you to go read it and wait for you to come back and post the code properly.

Before you re-post this code do a few things that will make it more readable and help people to help you. Making it harder for people to read your code only slows things down. Remember, you're the only one who feels the urgency here.

1. Put the code in code tags
2. format the code (control - T in the Arduino IDE)
3. replace all the single letter variable names with descriptive names so it is easy to keep up with what is what in that code. Single letter variable names are the worst. Let the name of the variable tell me what the thing it holds means.