Start sequence

I would like to start a sequence when an input is cycled 4 times within 4 seconds run sequence then only run again if it sees the same input. I would also like it to abort the sequence if it sees an input on another pin. Both inputs would be toggled low. The abort pin would just be a single toggle.

OK. You have our permission. Was there some part that was giving you trouble? Post what you've written so far and discuss the differences between what it does and what you want it to do.

this is what I have so far. the exit is only in there for now because at this time it will just keep looping.

#define RELAY1 6

#define RELAY2 8

#define RELAY3 9

#define RELAY4 10

int buttonPin;

void setup()

{

pinMode(RELAY1, OUTPUT);

pinMode(RELAY2, OUTPUT);

pinMode(RELAY3, OUTPUT);

pinMode(RELAY4, OUTPUT);

buttonPin = 11;
pinMode(buttonPin, INPUT_PULLUP);

}

void loop()

{

digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
digitalWrite(RELAY3,HIGH);
digitalWrite(RELAY4,HIGH);

{
if(buttonPin = LOW);
}

digitalWrite(RELAY2,LOW);
delay(2000);
digitalWrite(RELAY1,LOW);

delay(2000);

digitalWrite(RELAY1,HIGH);
delay(10000);
digitalWrite(RELAY2,HIGH);
exit(0);

}

{
if(buttonPin = LOW);  
}

Go to the reference sections (This page at the top in the blue, Learning -> Reference). I want you to first learn about the difference between = and ==. Then I want you to look at the page on if statements and the syntax, especially where the braces go and whether or not there should be a semicolon.

Applying autoformat (ctrl-t or Tools menu, Auto Format) to your code would make problems like the misplaced brackets that Delta_G pointed out more obvious as well as improve readability.

ok so this is what I have now but I get an error unqualified id before 'if'

[
#define RELAY1 6

#define RELAY2 8

#define RELAY3 9

#define RELAY4 10

int buttonPin;

void setup()

{

pinMode(RELAY1, OUTPUT);

pinMode(RELAY2, OUTPUT);

pinMode(RELAY3, OUTPUT);

pinMode(RELAY4, OUTPUT);

buttonPin = 11;
pinMode(buttonPin, INPUT_PULLUP);

}

void loop()

{

digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
digitalWrite(RELAY3,HIGH);
digitalWrite(RELAY4,HIGH);

}
if(buttonPin == LOW);
{

digitalWrite(RELAY2,LOW);
delay(2000);
digitalWrite(RELAY1,LOW);

delay(2000);

digitalWrite(RELAY1,HIGH);
delay(10000);
digitalWrite(RELAY2,HIGH);
exit(0);

}
]

I am still not sure where I can find what to do when I only want it to run when 11 is cycled low 4 times within a certain amount of time but it seems like I have a lot more to figure out before I try that

  1. Put your code in code tags, like I'm sure you read in this Sticky Read this before posting a programming question ... - Programming Questions - Arduino Forum

  2. You cannot have code outside of functions. Your if(buttonPin == Low); is not in any function.

  3. The ; at the end of above mentioned if statement would end that if statement. Read this: https://www.arduino.cc/en/Reference/If

  4. Figure out how (and why) to replace delay() with millis(). millis() - Arduino Reference, Arduino State Management Explained (BlinkWithoutDelay) - YouTube

if(buttonPin == LOW);

Is 11 ever going to equal zero?

so this is where I'm at now I tested the delay before and it worked as it should without a command function. pin 11 will only be toggled low. with this current sketch the program still runs on its own but only works relay1 for some reason.

[

#define RELAY1 6

#define RELAY2 8

#define RELAY3 9

#define RELAY4 10

int buttonPin = 11;

void setup()

{

pinMode(RELAY1, OUTPUT);

pinMode(RELAY2, OUTPUT);

pinMode(RELAY3, OUTPUT);

pinMode(RELAY4, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);

}

void loop()

{
digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, HIGH);
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, HIGH);
if (buttonPin == LOW)
digitalWrite(RELAY2, LOW);
delay(2000);
digitalWrite(RELAY1, LOW);

delay(2000);

digitalWrite(RELAY1, HIGH);
delay(10000);
digitalWrite(RELAY2, HIGH);
exit(0);

}
]

  if (buttonPin, LOW)

That is equivalent to if(LOW), which means if(false). The code of that statement is not executed.

It is not obvious why you think that does a comparison, or why you want to compare the pin number to LOW. The state of the pin might be LOW, but the pin number certainly isn't,

  if (buttonPin == LOW)

I believe we've already discussed this.
It is still is very not possible

 if (buttonPin == LOW)

You obviously did not read reply #7. Why do you expect people to help you if you do not pay any attention to what they say.

I did read post 7 and I don't understand what he is getting at. if you don't want to help then don't. I have read everything every one has requested and I am trying to learn. there is no reason to mock me for it.

int buttonPin = 11;
 pinMode(buttonPin, INPUT_PULLUP);

You have set buttonPin to 11, and it looks like the button is wired to pin 11 set with INPUT_PULLUP.

To know if the button has been pressed or not, you have to use

if( digitalRead(buttonPin) == LOW)

I did read post 7 and I don't understand what he is getting at.

If you don't understand what someone has suggested, then ask.

Code tags. The first icon in the reply form. Not just '[' and ']'.

What do you see exit(0); doing for you?

exit(0);

To where are you going to exit?

As it stands now, it would be better to put all of the code in the setup() function (which executes once) and leave the loop() function (which executes repeatedly) empty.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

exit(0) is only in there until I get the input correctly it is so the uno does not constantly cycle the relays. my end goal here is to make this a remote starter for a vehicle that starts when the door locks are cycled 4 times within 4 seconds with the factory remote (I intend to connect a relay to the door lock circuit which would send common ground to a certain pin of the uno) once the vehicle is running I would like to interrupt it by pressing the brake pedal (which would have a relay setup in the same fashion as the door locks to a different pin of the uno. I did change what cattle dog recommended but it still runs the program any way. I do appreciate the help. I have tried several different pins and changing from LOW toHIGH with no improvement I may be going about this all wrong. any input would be appreciated!

#define RELAY1  6

#define RELAY2  8

#define RELAY3  9

#define RELAY4  10

int buttonPin = 11;




void setup()

{


  pinMode(RELAY1, OUTPUT);

  pinMode(RELAY2, OUTPUT);

  pinMode(RELAY3, OUTPUT);

  pinMode(RELAY4, OUTPUT);


  pinMode(buttonPin, INPUT_PULLUP);

}



void loop()

{
  
  digitalWrite(RELAY1, HIGH);
  digitalWrite(RELAY2, HIGH);
  digitalWrite(RELAY3, HIGH);
  digitalWrite(RELAY4, HIGH);
  if( digitalRead(buttonPin) == LOW)
  digitalWrite(RELAY2, LOW);
  delay(2000);
  digitalWrite(RELAY1, LOW);

  delay(2000);

  digitalWrite(RELAY1, HIGH);
  delay(10000);
  digitalWrite(RELAY2, HIGH);



}
if( digitalRead(buttonPin) == LOW)
  digitalWrite(RELAY2, LOW);
  delay(2000);

Without brackets after the if, only the digitalWrite will execute conditionally. All other code after the digitalWrite will execute each time through loop(). Is that intended?

Use curly brackets around (to delieate) blocks of code.

that was not inteaded I had it before the brackets before and was getting an error so I thought It could not be there. I will put it back and share the error

#define RELAY1  6

#define RELAY2  8

#define RELAY3  9

#define RELAY4  10

int buttonPin = 11;




void setup()

{


  pinMode(RELAY1, OUTPUT);

  pinMode(RELAY2, OUTPUT);

  pinMode(RELAY3, OUTPUT);

  pinMode(RELAY4, OUTPUT);


  pinMode(buttonPin, INPUT_PULLUP);

}



void loop()

{

  digitalWrite(RELAY1, HIGH);
  digitalWrite(RELAY2, HIGH);
  digitalWrite(RELAY3, HIGH);
  digitalWrite(RELAY4, HIGH);
}
if ( digitalRead(buttonPin) == LOW)
{
  digitalWrite(RELAY2, LOW);
  delay(2000);
  digitalWrite(RELAY1, LOW);

  delay(2000);

  digitalWrite(RELAY1, HIGH);
  delay(10000);
  digitalWrite(RELAY2, HIGH);



}

Arduino: 1.8.1 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\arduino-builder -dump-prefs -logger=machine -hardware C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware -tools C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\tools-builder -tools C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -built-in-libraries C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\libraries -libraries C:\Users\nate\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10801 -build-path C:\Users\nate\AppData\Local\Temp\arduino_build_77586 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -verbose C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\sketch\sketch_relay4\sketch_relay4.ino
C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\arduino-builder -compile -logger=machine -hardware C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware -tools C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\tools-builder -tools C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -built-in-libraries C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\libraries -libraries C:\Users\nate\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10801 -build-path C:\Users\nate\AppData\Local\Temp\arduino_build_77586 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr -verbose C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\sketch\sketch_relay4\sketch_relay4.ino
Using board 'uno' from platform in folder: C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr
Detecting libraries used...
"C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr\cores\arduino" "-IC:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr\variants\standard" "C:\Users\nate\AppData\Local\Temp\arduino_build_77586\sketch\sketch_relay4.ino.cpp" -o "nul"
Generating function prototypes...
"C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr\cores\arduino" "-IC:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr\variants\standard" "C:\Users\nate\AppData\Local\Temp\arduino_build_77586\sketch\sketch_relay4.ino.cpp" -o "C:\Users\nate\AppData\Local\Temp\arduino_build_77586\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\nate\AppData\Local\Temp\arduino_build_77586\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr\cores\arduino" "-IC:\Users\nate\Desktop\arduino-1.8.1-windows\arduino-1.8.1\hardware\arduino\avr\variants\standard" "C:\Users\nate\AppData\Local\Temp\arduino_build_77586\sketch\sketch_relay4.ino.cpp" -o "C:\Users\nate\AppData\Local\Temp\arduino_build_77586\sketch\sketch_relay4.ino.cpp.o"
sketch_relay4:48: error: expected unqualified-id before 'if'

if ( digitalRead(buttonPin) == LOW)

^

exit status 1
expected unqualified-id before 'if'