Arduino relay code for 14 in 5 timing

I would like to use an arduino uno to control a relay.

I would like the relay on pin8 to be set HIGH 500 mS
LOW 100 mS
HIGH 200mS
LOW 300mS
HIGH 50mS
LOW 100mS
HIGH 50mS
LOW 100mS
for a sequence of 50 states that is inclusive of the above
Can this be done or will I run out of RAM

regards

Joe
haugheyjoe@yahoo.com

RAM is fine. Chattering the relay with 50mS pulses will destroy a mechanical relay in short order. Use an SSR. But more importantly what are you trying to do?

Welcome to the forum

I suggest that you edit your post and remove your email address to avoid spam

If the code is doing nothing else, then look at the delay() function and research the use of for loops to repeat code for a fixed number of times

Done properly you will not run out of memory

If the code needs to something else at the same time as the HIGH/LOW sequences than please say so now as a different technique will be required

Looking like an XY problem. Give us the "big picture" of your issue and we can help to find a solution.

Read the forum guidelines to get information on what is needed so that we can answer your questions.

yes and no

//for instance

int Relaypin= 8; 

void setup() {
pinMode(Relaypin, OUTPUT); 
}

void loop() {
digitalWrite(Relaypin, HIGH); 
delay(500); 
digitalWrite(Relaypin, LOW);
delay(100);

digitalWrite(Relaypin, HIGH); 
delay(200); 
digitalWrite(Relaypin, LOW);
delay(100);

digitalWrite(Relaypin, HIGH); 
delay(200); 
digitalWrite(Relaypin, LOW);
delay(50);
digitalWrite(Relaypin, HIGH); 
delay(200}; 
digitalWrite(Relaypin, LOW);
delay(50);
digitalWrite(Relaypin, HIGH); 
delay(200); 
digitalWrite(Relaypin, LOW);
delay(100);

digitalWrite(Relaypin, HIGH); 
delay(500); 
digitalWrite(Relaypin, LOW);
delay(100);

//if you can give assistance as to why that does not compile/work, thanks, though point about continuos relay 50mS understood, but there would be the high and low states for the longer durations between

If it does not compile, please edit your post to place the code inside code tags. Then copy and paste the entire compiler error message in a new post.

Not with THAT code it wont. delay(50) is barely time for a mech relay to settle. You toggle too fast & the relay will hang.


Common Arduino blue cube relay settling time.

} instead of ) there.

No curly bracket (}) to close loop().

Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
code tags new

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

The last code you posted compiles with this message line included, once the typos were fixed:

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

I don't think you need to worry about running out of RAM.

Thank you all so much, my eyes are are a bit! and yes the forum has been most helpful, to correct the idea of 50mS for the relay it is only for an initial understanding of difference and overall the code with slightly longer latency shall be of use to me

regards

joe

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.