Here's an example of BlinkWithoutDelay with different on/off times. The new idea from the standard BWOD is to change the interval each time you switch from on to off and off to on. const byte ledPin =  LED_BUILTIN;// the number of the LED pin byte ledState = LOW;            unsigned long previou… Answer from cattledog on forum.arduino.cc
🌐
GitHub
github.com › taromorimoto › interval-timer
GitHub - taromorimoto/interval-timer: A simple interval timer for Arduino
#include "IntervalTimer.h" void setup() { Serial.begin(9600); } void myFunctionA() { Serial.println("Hello A!"); } void myFunctionB() { Serial.println("Hello B!"); } IntervalTimer timerA(1000, myFunctionA); IntervalTimer timerB(3000, myFunctionB); void loop() { timerA.update(); timerB.update(); } You can just make a zip of the IntervalTimer folder and add as a library in Arduino IDE.
Forked by 2 users
Languages   C++ 100.0% | C++ 100.0%
Discussions

interrupt - Interval timer on Arduino: Doubt about TimerOne library - Arduino Stack Exchange
I want to synchronize a timer interrupt from a button is pressed. I want to read a button state 3 seconds later from the first pulse moment (to identify long pressed button, 3 seconds for this exam... More on arduino.stackexchange.com
🌐 arduino.stackexchange.com
Looking for a timer interrupt library that can change intervals
I can use micros() to get some good information about how long between incoming pulses but have been having trouble finding the right library to handle multiplying that interval using an interrupt timer for better accuracy. I tried the "arduino-timer" library to try this out but based on searching ... More on forum.arduino.cc
🌐 forum.arduino.cc
5
0
April 23, 2023
Finished interval timer project on GitHub
This is that project with the AMAZING case! Can I ask what 3D printer you have? More on reddit.com
🌐 r/arduino
5
5
April 4, 2023
Interval timer on Arduino: Doubt about TimerOne library
I want to synchronize a timer interrupt from a button is pressed. I want to read a button state 3 seconds later from the first pulse moment (to identify long pressed button, 3 seconds for this example). I'm trying to do with this code: #include #define pinButton 3 #define POWER_ON_TIME 3 //Long ... More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
February 15, 2022
🌐
Kasper Kamperman
kasperkamperman.com › home › codelog › arduino programming – interval
Arduino Programming - Interval ⋆ Kasper Kamperman
April 22, 2021 - Wil namelijk een afgeleide (5v dc) van de netspanning meten op een inputpin en na 25 seconden nog een keer om zeker te weten dat het geen spike was, en dan een generator starten via de Arduino en zodra de netspanning weer terug is de generator stoppen. Using timer0, write a program (without using interrupts) that prints the time every 0.015 seconds. Use timer0 to ensure the 0.015 second interval as closely as possible.
🌐
PJRC
pjrc.com › teensy › td_timing_IntervalTimer.html
Delay and Timing Functions
This functions returns true if successful. False is returned if all hardware resources are busy, used by other IntervalTimer objects. myTimer.priority(number); Set the interrupt priority level, controlling which other interrupts this timer is allowed to interrupt.
Top answer
1 of 1
4

Don't know if I understand what you want to do. IMHO TimerOne is a good library for repetitive tasks, not for one shot events.

You should use Timer1.stop and Timer1.resume() to start the 3 seconds count whenever you press the button. But TimerOne has a known issue: when you use restart or start the ISR is fired immediatly

Here is my version of your code. It waits for button press and then starts timer. After 3 seconds pressed_check is fired and the longPressDetected flas is set. I hope I have correctly interpreted your question

#include <TimerOne.h>
#define pinButton 3
#define POWER_ON_TIME 3UL //Long press in seconds

volatile unsigned long pressed_Time = 0;
volatile unsigned long myTime_button = 0;
volatile unsigned long myTimeOn_button = 0;
volatile unsigned long myTime_pressed = 0;

volatile bool firstISR_Call = true;
volatile bool longPressDetected = false;

unsigned long holdTime = 0;
bool button_state = false;

void setup() {
    // put your setup code here, to run once:
    pinMode(pinButton, INPUT_PULLUP);
    pinMode(LED_BUILTIN, OUTPUT);

    Timer1.initialize();
    // Create an ISR that is called every POWER_ON_TIME seconds
    Timer1.attachInterrupt(pressed_check, POWER_ON_TIME * 1000000UL);
    // Stop Timer1 now
    Timer1.stop();  
    
    //Timer1.attachInterrupt(pressed_check);

    attachInterrupt(digitalPinToInterrupt(pinButton), button_act, CHANGE);
    Serial.begin(9600);
}

void loop() {
    if (longPressDetected) {
        longPressDetected = false;
        Serial.println("Long press detected");
    }
    delay(100);
}

void button_act() {
    if (!digitalRead(pinButton)) {
        myTime_button = micros(); //Flanco de bajada
        firstISR_Call = true;       // Set to true toprevent "phantom" interrupt
        longPressDetected = false;  // Clear long press detection flag
        Timer1.restart();           // Restart timer from 0 - ISSUE: this fires immediatly an interrupt
                                    // causing a so called "phantom" interrupt
    }
    else { 
      myTimeOn_button = micros() - myTime_button; 
      Timer1.stop();
    } //Flanco de subida
}

void pressed_check() {
    // Detect "phantom" interrupt
    if (firstISR_Call) {
        firstISR_Call = false;
        return;
    }
    longPressDetected = true;
    myTime_pressed = micros() - myTime_button;
    Timer1.stop();
}
🌐
Instructables
instructables.com › circuits › arduino
Arduino Timer Interrupts : 6 Steps (with Pictures) - Instructables
November 10, 2021 - Arduino Timer Interrupts: Timer interrupts allow you to perform a task at very specifically timed intervals regardless of what else is going on in your code. In this instructable I'll explain how to setup and execute an interrupt in Clear Timer ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Looking for a timer interrupt library that can change intervals - Programming - Arduino Forum
April 23, 2023 - I can use micros() to get some good information about how long between incoming pulses but have been having trouble finding the right library to handle multiplying that interval using an interrupt timer for better accuracy. I tried the "arduino-timer" library to try this out but based on searching ...
Find elsewhere
🌐
Readthedocs
png-arduino-framework.readthedocs.io › timer.html
Arduino Timer — .PNG Arduino Framework 1.0 documentation
Timer(unsigned long int ms, CallBackType callback, bool isSingle); Create a Timer with time, callback and set if is single shot · void setInterval(unsigned long int ms); - Set callback interval
🌐
Arduino
docs.arduino.cc › libraries › intervaltimerex
Arduino
The Arduino environment can be extended through the use of libraries. Libraries provide extra functionality for use in sketches. To use a library in a sketch, select it from Sketch > Import Library.
🌐
Draeger IT
draeger-it.blog › startseite › interval execution made easy: timer for arduino
Interval execution made easy: Timer for Arduino - draeger-it.blog
In conclusion, there are significant advantages to using the “Timer” library for Arduino. The precise interval of execution allows for more accurate timing while maintaining code efficiency. With this streamlined solution, we can say goodbye to the traditional approaches, such as using delay, and take our projects to a new level.
Published   January 8, 2026
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Interval timer on Arduino: Doubt about TimerOne library - Programming - Arduino Forum
February 15, 2022 - I want to synchronize a timer interrupt from a button is pressed. I want to read a button state 3 seconds later from the first pulse moment (to identify long pressed button, 3 seconds for this example). I'm trying to do with this code: #include #define pinButton 3 #define POWER_ON_TIME 3 //Long press in seconds volatile unsigned long pressed_Time = 0; volatile unsigned long myTime_button = 0; volatile unsigned long myTimeOn_button = 0; volatile unsigned long myTime_pressed = 0; u...
🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
7 day interval timer using millis(). General guidance sought. - General Guidance - Arduino Forum
June 5, 2019 - Hello forum. I am relatively new to microcontrollers, and definitely confused by the syntax of the Sketch language; but understanding will come with practice, and practice is what this current project is all about. I am trying to incorporate a 7 day interval timer within other code.
🌐
Reddit
reddit.com › r/arduino › update rgb led matrix interval timer for crossfit/circuit training
r/arduino on Reddit: Update RGB LED matrix interval timer for crossfit/circuit training
March 29, 2023 -

My first arduino project is almost finished, a wall mounted interval timer. I have 3D a case toount it on the wall. I intend to post the project on github if anyone is interested. Inside is an arduino mega 2560 controllers the 64x64 led matrix and a MP3 FN M16P sound module powering a 3W speaker. The only thing left to do is to finish the wiring of the sound module.

🌐
Adafruit
learn.adafruit.com › multi-tasking-the-arduino-part-2 › timers
Timer Interrupts | Multi-tasking the Arduino - Part 2 | Adafruit Learning System
December 1, 2014 - The timer will actually call us to let us know it is time to check the clock! The Arduino Uno has 3 timers: Timer0, Timer1 and Timer2. Timer0 is already set up to generate a millisecond interrupt to update the millisecond counter reported by ...
🌐
Forward
forward.com.au › pfod › ArduinoProgramming › TimingDelaysInArduino.html
How to code Timers and Delays in Arduino
Unfortunately many of the standard Arduino libraries use delay() or introduce pauses, such as AnalogRead and SoftwareSerial. Usually the delays these introduce are small but they can add up so I suggest you add a monitor at the top of your loop() to check how quickly it runs. This loop timer can be either the hardware one shown below OR the loopTimer class (also in the SafeString library), used in the Simple Multi-tasking in Arduino tutorial, that prints out the time your loop takes to execute.
🌐
DeepBlue
deepbluembedded.com › home › blog › arduino timer interrupts tutorial & examples
Arduino Timer Interrupts Tutorial & Examples
August 17, 2023 - The timer module in timer mode ... It’s generally used to generate fixed time interval interrupts to insert time delays between events or to execute periodic events at fixed time intervals....
🌐
DeepBlue
deepbluembedded.com › home › blog › arduino timers [ultimate guide]
Arduino Timers [Ultimate Guide]
August 17, 2023 - The timer module in timer mode ... It’s generally used to generate fixed time interval interrupts to insert time delays between events or to execute periodic events at fixed time intervals....
🌐
Arduino Forum
forum.arduino.cc › projects › programming
How to change timer interval in interrupt routine? - Programming - Arduino Forum
October 23, 2022 - Hi I am running an ESP32 Timer interrupt where I want the timer interval to change between two values every time the interrupt-routine is called. Hence, when toggle0 = true I want one interval and when toggle0 = false I…
🌐
DroneBot Workshop
forum.dronebotworkshop.com › forums › inside the workshop › components & progra... › arduino
[Solved] Arduino Timers – no pain and all gain!
March 6, 2022 - } tick_count++; // move tick counter on by 1 second - timer1 interrupt frequency } You will also see that the built in led on an Arduino (LED_BUILTIN) switches state each time the process code is entered at the process_interval frequency to provide a visual indicator that is operating.