Introducing: Arduino Simple Task Scheduler


Get the code here:

Introducing the Arduino Simple Task Scheduler.  This is part of the balloon flight computer code I wrote for White Star, with some more polish. This library allows you to create a schedule queue of functions to be executed at specified times, on specified intervals.  For example, say you’re trying to log some sensor data and update a display in the same program. With the task scheduler, you can simply write a function to gather sensor data, write a function to update the display, add them to your queue, and let the library handle the rest.

This isn’t really useful for blinking LEDs, but it’s great for complex systems. For example, the balloon computer was gathering sensor data, sending short reports, sending long reports, monitoring vertical speed, monitoring GPS Status, monitoring flight state, managing ballast, and managing a backup high-frequency radio at the same time.  Halfway through development, it was obvious that we would need to integrate a watchdog timer to keep other systems from freezing the flight computer.  If all of these tasks had been occurring simultaneously, spread throughout spaghetti code, it would have been very difficult to add watchdog resets in all the right places.  With the task queue, I simply defined another function that reset the watchdog, and put it in the queue.  Two minutes, tops!

You can find extensive documentation and examples in the Github project.  To install, just copy the “Arduino” directory contents to the “Libraries” folder of your Arduino IDE install.  Restart your IDE, and it should pop right up.  Here’s a really simple example program:


 This will print “Hello: X” where X is the number of milliseconds since startup, starting 5 seconds after startup, and repeating every 1 second.
The Arduino library has some limitations, so I’ve also included an AVR “library” (just a couple of source files to include in your project).  This one’s a little easier to tweak to your specific application, and doesn’t suffer some of the same drawbacks as the Arduino library.  That said, the Arduino library will be find for almost every project out there!  The limitations are listed in more detail at the Github site.
If you find any bugs, let me know! Submit a Github issue, fork, fix and submit a pull request, or contact me directly!  If you find this useful, let me know!  It isn’t a lot, but I hope it’s well documented, and easy to use/read/understand.


  • Hello Brad,

    I tried the example, but I will only get the following error message:

    Queue.cpp: In function ‘void setup()’:
    Queue.pde:-1: error: ‘class Queue’ has no member named ‘run’

    Can You please help and fix it?


  • Try “myQueue.Run(millis());” with a capital R.
    Then you get another error about function “loop”. Just add a loop in the code, after the setup() function, something like “void loop() { delay(10); }”

  • Thanks for tips above. The example as given has a couple of capitalisation typos, and slips random milliseconds apparently due to the delay(10) in void setup().

    This worked perfectly for me:

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

    Queue myQueue;
    myQueue.scheduleFunction(testFunction, “Test”, 5000, 1000);

    while(1) {

    int testFunction(unsigned long now)
    Serial.print(“Hello: “);

    void loop() {


  • Hi,

    I’ve downloaded the Arduino IDE. I looked under the Arduino directory which is located under the Library directory on my Mac. I downloaded your Arduino folder, moved its contents the MY arduino directory. When I started the Arduino IDE again and ran the sample code I got the error message

  • What error message are you getting? Are you using the Arduino 1.x IDE? What does your Arduino folder directory structure look like?

  • On my Mac /dharr19/Library/Arduino/ at this point I created a directory called Library


    The error I get is “Queue was not declared in this scope”. Oh I did capitalize the r in run

  • these were the files from your Arduino directory that I put into my library folder

    Examples directory
    Test directory

  • David, you shouldn’t have needed to create the Library directory. This error indicates that the arduino IDE couldn’t find the library. If you could, email me with a complete file listing for your arduino tree. Screenshots or terminal copy-paste is fine. My email address is

  • Useful !
    For the polish, if you want it ? :)

    Queue KEYWORD1
    queuedFunction KEYWORD1

    scheduleFunction KEYWORD2
    scheduleRemoveFunction KEYWORD2
    scheduleChangeFunction KEYWORD2
    Run KEYWORD2

  • I tried this code tonight and after getting the baseline test working, I added a couple more tasks, but found that the myQueue.scheduleRemoveFunction doesn’t seem to actually stop the function from working.
    int test1Count = 3;

    … in Loop:
    int testFunction1(unsigned long now) {
    Serial.print(“Test1Count: “);Serial.println(test1Count–);
    if (test1Count <= 0) {
    int r1 = myQueue.scheduleRemoveFunction(test1);
    Serial.print("Removing Test1: "); Serial.print(r1);
    return 1;