Arduino arduino-timer Non-Blocking Timers: Wiring, Code and Simulator

To build this Arduino arduino-timer Non-Blocking Timers project you need an Arduino Uno and nothing but the board itself. Schedule functions without delay() using the arduino-timer library. Make the 0 connections in the wiring table, upload the Arduino C++ code, and add timer.in(1000, ...) for a one-shot task.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board

Wiring

No wiring: this project uses only the Arduino Uno.

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add nothing but the board itself from the parts palette.
  3. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  4. Run it. Press Run. Add timer.in(1000, ...) for a one-shot task.

Arduino C++ code

// arduino-timer: call functions later or every N ms, without delay().
#include <arduino-timer.h>

auto timer = timer_create_default();
int beats = 0;

bool beat(void *) {
  beats++;
  Serial.print("Beat ");
  Serial.println(beats);
  return true;
}

void setup() {
  Serial.begin(9600);
  timer.every(250, beat);
}

void loop() {
  timer.tick();
}

What to try

Add timer.in(1000, ...) for a one-shot task.

Frequently asked questions

How do I wire the arduino-timer Non-Blocking Timers project on an Arduino Uno?

No extra wiring is needed: it uses only the Arduino Uno itself.

What parts do I need for this Arduino project?

An Arduino Uno and nothing but the board itself.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

Schedule functions without delay() using the arduino-timer library.

More Arduino Uno projects