A relay can't change from NO to NC. It can only change from "open" to "closed" (for the contacts), or "on" to "off" (for the coil). "N" stands for "normally", or the non-energized state.
40ms is too short a time for some relays to operate.
A relay can't change from NO to NC. It can only change from "open" to "closed" (for the contacts), or "on" to "off" (for the coil). "N" stands for "normally", or the non-energized state.
40ms is too short a time for some relays to operate.
Hello, i wrote the following code but nothing, my goal is: When input pin 2 is HIGH, output pin 13 has delay 100msec and then HIGH for eg 50msec then turns LOW, when input 2 is LOW, output pin13 is LOW too.
void setup(){
pinMode (13, OUTPUT);
pinMode (2, INPUT);
}
void loop(){
if (digitalRead(2) == HIGH){
delay(100);
else (digitalRead(2) == LOW){
digitalWrite (13, HIGH);
delay(1000);
digitalWrite (13, LOW);
}
}
}
eg for understanding, when i push and keep a button (for my case proximity sensor) delay 100msec and turn on a led for 1000msec then turn off . When release the button start again from begining.
else (digitalRead(2) == LOW)
makes no sense.
When i push button once or hold( that's means pin 2 is HIGH) turn pin 13 HIGH for 5 sec and then turn pin 13 LOW, Could you help me with code?.
The simplest way possible, but not the best
void loop()
{
if (digitalRead(2) == HIGH)
{
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
}
}
I try to explain better. I have a proximity sensor, gives 4.64 Volt to pin 2 if a put it near to metal. So i want a code to do this: Give voltage to pin 2 --> Delay 1sec --> LED turn ON for 5 sec and turn OFF. Once until i give voltage to pin 2 again. I hope you understand me.
Thanks
void loop()
{
if (digitalRead(2) == HIGH)
{
delay(1000);
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
}
}
Still simple. Still not the best way, but try it. You will need to set pinMode()s in setup()
With this code
void setup(){
pinMode (13, OUTPUT);
pinMode (2, INPUT);
}
void loop()
{
if (digitalRead(2) == HIGH)
{
delay(1000);
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
}
}
When i put voltage to pin 2 led flashing. I want to work once
Then (intentionally taking you literally):
void setup(){
pinMode (13, OUTPUT);
pinMode (2, INPUT);
while (digitalRead(2) == LOW);
delay(1000);
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
}
void loop(){}
if you want it to re-arm:
void setup(){
pinMode (13, OUTPUT);
pinMode (2, INPUT);
}
void loop(){
while (digitalRead(2) == LOW);
delay(1000);
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
}
What is the purpose of the 1 second delay?
Yes, i want to work once when i have pin 2 HIGH for 2 sec, then stop until i put again voltage on pin 2
i want to work once when i have pin 2 HIGH for 2 sec
Did you mention this before ?
I wrote this (Give voltage to pin 2 --> Delay 1sec --> LED turn ON for 5 sec and turn OFF. Once until i give voltage to pin 2 again) but you are right, it is not clear for you, i am sorry.
gioujazz3902:
Yes, i want to work once when i have pin 2 HIGH for 2 sec, then stop until i put again voltage on pin 2
Good. My second example does that.
Delay 1 sec is for adjustment. With second code led flashing.
i want to work once when i have pin 2 HIGH for 2 sec, then stop until i put again voltage on pin 2
With second code don't stop, flashing.
gioujazz3902:
i want to work once when i have pin 2 HIGH for 2 sec, then stop until i put again voltage on pin 2
With second code don't stop, flashing.
Whoa! Now you say that it has to be held down for a minimum of 2 seconds? Is this another surprise requirement? I hope not, because it wastes everyone's time.
What should happen if pin 2 goes HIGH but does not stay HIGH for 2 seconds ?
The sensor is connect with pin 2 . Works if i turn ON sensor and OFF. I want to stop after 2 sec if have sensor ON. How upload video?
Dear aarg,
I am sorry if you have that opinion, i try to explain what i want to do, that's all. I can't explain very well because i don't know nothing about code, but i try to learn. I don't want to spend your time.
I have a proximity sensor for switch, connected to pin2 (black wire). When i give voltage (thats mean pin 2 is HIGH) i want pin 13 (which is connect with LED) turn in HIGH after 1sec (delay). PIN2 still has voltage but pin13 turn to LOW after 2 sec. to re arm, must be pin 2 to LOW (no voltage).
its clear? how can i upload video?
gioujazz3902:
Dear aarg,
I am sorry if you have that opinion, i try to explain what i want to do, that's all. I can't explain very well because i don't know nothing about code, but i try to learn. I don't want to spend your time.
I have a proximity sensor for switch, connected to pin2 (black wire). When i give voltage (thats mean pin 2 is HIGH) i want pin 13 (which is connect with LED) turn in HIGH after 1sec (delay). PIN2 still has voltage but pin13 turn to LOW after 2 sec. to re arm, must be pin 2 to LOW (no voltage).
its clear? how can i upload video?
You shouldn't need to with my second example. I will double check it for a mistake, but I think it should do that. With six seconds of total delay happening after the button press, I don't see any relevance to the state of pin 2 after 2 seconds. The sequence would be in the middle of the "LED on" part at that time. Can you clarify that?
I don't see how a video can help. You could upload it to YouTube and give us a link.
You really must answer reply #36.