Stopping a program

how do i stop a program running on my arduino uno

Turn it off.

does it save the program

Yes. You can turn the arduino on and off as many times as you like. When you turn it on it starts running your software just as it did when you first uploaded it from the IDE.

Like Goofballtech said, a sketch gets saved in the program memory (PROGMEM), when you turn the Arduino off then on again it will begin running from the start of the program.

So, turning it off then on again will reset everything, as if you were running the program for the first time.

(If you wanted to "save" variables between resets, you can put them in EEPROM or in PROGMEM, but this requires fancy programming stuff. See if you're interested, but it's a mid-to-advanced level programming method.)

An arduino program will keep repeating the code in the loop() function, again and again forever. But, you can control the flow of code inside the loop. Here's an example:

If you want a program to run once then "quit", you could trap it in a while loop like this. I'm not sure why you would want this to happen. This example blinks an LED once, then does nothing. When you reset the Arduino, it will blink once then do nothing again. Try it out. Also try deleting the while loop and see what happens.

void setup() {                
  pinMode(13, OUTPUT);     

void loop() {
  //Blink the LED on pin 13 once
  digitalWrite(13, HIGH);
  digitalWrite(13, LOW); 

  //The program will get trapped in this while(1) loop forever.
  while(1) {
    //do nothing in here
  //This line will never be reached, because the program is stuck in the while(1) loop

ok but how do i stop a program, but keep the arduino on and save the program

What do you mean by "stop the program" ? As explained, once programmed the Arduino will retain the program and it will still be there when you power it up again. You do not need to save ithe program as it exists on the Arduino, but you might want to save the source code from the IDE.

Please explain what you want to do and why then we can suggest how to do it.

i thought that you could abort a program, like on an NXT brick so then how do you choose what program you want to run if there are multiple, if there can be multiple on the uno

There can only be one program on the UNO.

But that one program could run different sections of code which would effectively be different programs. Lack of memory would be the biggest limitation.

You still only get one entry point. If you want to be able to choose amongst several programs then you'd have to code that yourself in the setup function.

Some options for halting the processor...

Normally you don't halt the processor unless you put it to sleep.

I don't know what happens if you [u]break;[/u] out of the main loop... I don't know if it starts the whole program over at setup(), or if the processor goes into a NOP loop, or goes-off and gets lost somewhere, or what...

Normally.... We'll I can't say "normally" because it depends on what you're doing, but normally if you don't need the processor to do anything in particular at the moment, you'd run a "do nothing" loop with some way of breaking-out of the loop. Or, maybe you put it to sleep.

Calling break in the main loop would have the same effect as calling it in any other function. It would do nothing.

You can return from the main loop, but that will just start it over again.

i think that most of us have misunderstood the question

there is no save function on arduino per se,

an arduino is more like a cell phone or a similar device ... you turn it on (apply power), and it runs the program that is in its flash memory

the arduino program stays in its memory (for 20 years or so, with power off (or on)) until the program is reloaded

it seems to me that you want to pause the program without powering off

here is a rough idea for code that may work for you

// for this example, put a switch on pin 12 and use it to stop the program

void setup() {                
  // ........  all the setup code   

void loop() {
  if (pin12 == 0)  pauseCode();    // this line jumps to pause service routine

  // main program continues here


void pauseCode() {
  // put code here for saving status and turning off motors/lights ... whatever should be off when paused

  while( pin12 == 0 ) { }      // The program will get stopped in this while() loop as long as pin 12 is low

  // put code here to restore status after pause

jsotola: i think that most of us have misunderstood the question

I disagree, the question was answered with as much detail as it was asked. The question was asked as below. So the reader was forced to make up the rest of the question in order to provide a relevant answer. You cannot misunderstand information that doesn't exist.

THE_AWSM_CODING_CODY: how do i stop a program running on my arduino uno

THE_AWSM_CODING_CODY: i thought that you could abort a program, like on an NXT brick so then how do you choose what program you want to run if there are multiple, if there can be multiple on the uno

You can have only 1 actual program stored in the rduino program memory, but it can have many subprograms, which can be called individually and do different things, and easily accessed via the keyboard, or alternately via reading an I/O pin.

void loop()
  if( Serial.available() ) read_keypress();

void read_keypress()
  int ch =;

  switch( ch ) {
    case '1':  subprogram1();  break;
    case '2':  subprogram2();  break;
    default:   break;

void subprogram1()
  while( !Serial.available() ) {
    ... do something ...
  };   // discard key entered.

Any keypress will bail out of the subprogram, and wait for a new keypress in the main loop.

The same thing will work via reading an I/O pin rather than a keypress. D2 is high -> select subprogram1() in the switch statement, on and on.

thank you for the feed back