Timers in Arduino
In many tutorials the delay is used to temporize things, so we used a delay of about 250 ms for an LED to turn on and off, quietly. Of course this means that we can not do anything else until the delay is over.
For that we have scheduled interruptions or Timers, so that ring the bell when we have to execute a programmed function, without having to be continually checking if it is the time.
we are going to use the arduino nano to turn on and off a led. the nano has an integrated LED to pin 13 so we will use this pin for more convenience.
Here we are going to see a photo of the arduino nano:
PhotoCredits
Activity
We are going to use an arduino timer, specifically the "TimerOne" library to turn on a led in arduino nano
difficulty
This tutorial is for those who know the basics of Arduino.
Requirement
- Arduino nano with USB Cable
- Laptop with Arduino IDE
- "TimerOne" Library
Steps to follow
- Prepare the equipment needed for the activity.
- Connect the arduino to the Laptop using the usb cable
- Open Arduino IDE
now let's use the blink example and we will modify it to use the timer.
for this open the blink example:
you will see this window:
now we are going to "manage libraries" to install the "TimerOne" library:
Once there we look for TimerOne and then we install it:
After we install the library we look for it to add it to the project:
when we import the library you are ready to use it.
In the following image we will see the code to turn on the built-in led to the nano using timers, the code is explained. remember that you must have basic arduino notions.
Program
Using the interruptions gives us the advantage that we can do anything else while we wait for the event to happen, simply when the event occurs it alters the natural flow of the program to address that interruption, basically it is an order of priorities.
Collaborations
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved because it does not follow the Utopian Rules.
You can contact us on Discord.
[utopian-moderator]