Problem with stopping my program

Hi can someone please help me? I want to program my arduino so it starts the program when i press "ON (S1)" and i want to stop the program at any given moment no matter what step of the program is executed at this moment. To stop it i would like to use a second button "OFF (S0)". Has anyone an idea? If so please let me know. Thank you for your time. Any help is appreciated! :)

Post your code, using code tags.

int SchalterZustandS1; int SchalterZustandS0; int S1_EIN = 4; int S0_AUS = 2; int ZulaufZU = 13; int ZulaufAUF = 12; int VentilStellung_2 = 11; int VentilStellung_1 =10; int MotorEIN = 9; void setup() { Serial.begin(9600); pinMode(ZulaufZU,OUTPUT); pinMode(ZulaufAUF,OUTPUT); pinMode(MotorEIN,OUTPUT); pinMode(S1_EIN,INPUT); pinMode(S0_AUS,INPUT); }

void loop() { SchalterZustandS1 = digitalRead(S1_EIN); SchalterZustandS0 = digitalRead(S0_AUS); Serial.println(SchalterZustandS1,DEC); Serial.println(SchalterZustandS0,DEC); if(SchalterzustandS0 ==0) { if(SchalterZustandS1 ==1) { digitalWrite(ZulaufAUF,HIGH); digitalWrite(VentilStellung_1,HIGH); delay(15000); digitalWrite(ZulaufAUF,LOW); digitalWrite(VentilStellung_1,LOW); delay(500); digitalWrite(MotorEIN,HIGH); delay(20000); digitalWrite(MotorEIN,LOW); delay(500); digitalWrite(VentilStellung_2,HIGH); delay(15000); digitalWrite(VentilStellung_2,LOW); delay(500); digitalWrite(MotorEIN,HIGH); delay(20000); digitalWrite(MotorEIN,LOW); delay(1000); digitalWrite(ZulaufZU,HIGH); delay(15000); digitalWrite(ZulaufZU,LOW); }} }

Get rid of the calls to delay and rewrite the code to be non blocking. You can't do what you want and use delay.

Have a look at how millis() is used to manage timing without blocking in several things at a time.

A simple solution would be an ON/OFF switch on the Arduino power line :)