relay blink

hello everyone,
i’m working on a project which i will include its code i just want to switch a relay on when an input pin have 5v and i already did that but now i want the relay to blink on and off till i press a reset pushbutton which makes the blinking relay stay on
here is the code i wrote

FRWNLZWIYYT9FME.ino (16 KB)

Huge amount of work there.

A few things: learn about arrays, avoid the delay() function.

It is best you start with a simple sketch to prove whats needed, then incorporate it into your full project.

What part are you having trouble understanding?

There is a BIG difference between IS PRESSED and HAS BECOME PRESSED. Which is important to you?

By the way, the comments in your code are useless. They are almost all incorrect. Stop wasting effort with comments if you can't be bothered to keep them correct.

And, arrays and for loops are your friends. Use them!

The demo Several Things at a Time is an extended example of Blink Without Delay and illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

thanks guys for your comments

1st I really don't know anything about arrays
2nd about the comments in the code i've been changing the code about some million times
and forgot about them totally
3rd your answers are precious and so helpful i will learn about arrays and for loop

PaulS:
There is a BIG difference between IS PRESSED and HAS BECOME PRESSED. Which is important to you?

HAS BECOME PRESSED
the relay is output for a signal from input signal i want to make the relay blink when it still see the signal and when i press a reset button which is another input for all the relays it stays on till the signal from the input goes off then the relay goes off

mustafamadkour:
2nd about the comments in the code i've been changing the code about some million times
and forgot about them totally

If you use meaningful variable names then many comments are unnecessary. For example button1pin rather than button1. Of course an array called buttonPin would be even better.

And when I need to write a comment to remind me how something works - for example your // PULLUP for add 5v to pin without hardware prevent pin from floating between HIGH and LOW - I would put it on a line separate from my code (probably before the code) and I would not repeat it for every line.

...R

Robin2:
If you use meaningful variable names then many comments are unnecessary. For example button1pin rather than button1. Of course an array called buttonPin would be even better.

And when I need to write a comment to remind me how something works - for example your // PULLUP for add 5v to pin without hardware prevent pin from floating between HIGH and LOW - I would put it on a line separate from my code (probably before the code) and I would not repeat it for every line.

...R

i just dont know about arrays and that will simplify the code when it is more important to make the code simple to me
being new to coding makes me that idiot with the comments
the problem is not about timing the blink cause the blink is depends on the input signal when arrive and the reset button which makes the relay stays on till the input signal is gone

i want to make the relay blink when it still see the signal

That sounds like you want to act when the button IS PRESSED

UKHeliBob:
That sounds like you want to act when the button IS PRESSED

at first yes then relay blink till i press a button then if the signal still there the relay stays on and if its not there the relay goes off

mustafamadkour:
at first yes then relay blink till i press a button then if the signal still there the relay stays on and if its not there the relay goes off

Sorry but I am still confused.

Let's imagine that the relay is off and the button is not currently pressed

  1. What should happen if the button is pressed for a short period of time then released ?
    Presumably the relay should "blink" on and off so what should make it stop ?

  2. What should happen if the button is pressed and held ?
    Presumably the relay should "blink" but should that only happen whilst the button remains pressed ?

UKHeliBob:
Sorry but I am still confused.

Let's imagine that the relay is off and the button is not currently pressed

  1. What should happen if the button is pressed for a short period of time then released ?
    Presumably the relay should "blink" on and off so what should make it stop ?

  2. What should happen if the button is pressed and held ?
    Presumably the relay should "blink" but should that only happen whilst the button remains pressed ?

i prefer to make the relay blink in the 2 conditions if the button released or still held cause it's not a real button it's a signal from sensor
but the reset button will change the act of blinking to one of two ways
1 to set the blinking relay on if the signal is still there
2 to set the blinking relay off if the signal is gone

If you use meaningful variable names then many comments are unnecessary. For example button1pin rather than button1. Of course an array called buttonPin would be even better.

Yes, and you can let the name indicate the pins function.

const byte inputPins = {2,3,4,5,6};

const byte startSwitch = 2;
const byte stopSwitch = 3;
const byte incrementSwitch = 4;
etc.