I have 2 programs made for my arduino.The first one is for solving a maze automatically and the second one is for controlling the robot with a android app.I wanted to control the robot with the app I made as soon as it has finished solving the maze. Is it possible to upload both the program in the arduino and run it one at a time?If so can you tell me how?

  • Why don't you make just one program to run all?
    – Butzke
    Oct 28 '15 at 9:25
  • Never mind I just found the solution.Thank you for your reply though. Oct 28 '15 at 9:35
  • If you know the solution you should post it as an answer.
    – Majenko
    Oct 28 '15 at 9:53
  • The answer is a little bit complicated.I'll post it as soon as possible. Oct 28 '15 at 13:35

Once I made a sketch to run multiple programs. I wrote a setup and loop function for every different "program", (e.g. setup_p1, setup_p2, ... loop_p1, ...) and then wrote a simple main sketch to handle them all.

In my application I choose the program at startup with a 3-dipswitch, but you can easily switch this to allow "on the fly" switching.

I choose to use a callback because it's faster than just checking the mode every time, at least in my case

// callback for loop function
typedef void (*loopfunction)();
loopfunction currentloop;

void setup()
  // Set dip-switch pins as input

  // Concatenate the dip-switch values
  byte mode = 7 - ((digitalRead(MODE_PIN2) << 2) | (digitalRead(MODE_PIN1) << 1) | digitalRead(MODE_PIN0));

  // choose the correct mode
    case 0: // Shutdown - do nothing
    case 1: // Program 1
            currentloop = loop_p1;
    case 2: // Program 2
            currentloop = loop_p2;

  // Not a valid program: halt
  if (!currentloop)

void loop()
  // Execute the current loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.