- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add delay in Arduino
In order to add time delays in Arduino, you can use the delay() function. It takes as an argument the value of the delay in milliseconds. An example execution is given below −
Example
void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: Serial.print("Hello!"); delay(2000); }
The above code prints "Hello!" every 2 seconds. As you may have guessed, the minimum delay you can introduce using the delay function is 1 milli-second. What if you want an even shorted delay? Arduino has a delayMicroseconds() function for that, which takes in the value of the delay in microseconds as the argument.
Example
void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: Serial.print("Hello!"); delayMicroseconds(2000); }
The above code prints "Hello!" every 2 milliseconds (2000 microseconds).
- Related Articles
- How to add delay in a loop in JavaScript?
- Add a new board in Arduino
- Add new header files in Arduino IDE
- Bandwidth Delay Product
- Sleep in JavaScript delay between actions?
- Generation of time delay in 8085
- How to set delay in android?
- CSS animation-delay property
- jQuery delay() with Examples
- What is Delay distortion in computer networks?
- How to schedule tasks in Java to run for repeated fixed-delay execution, beginning after the specified delay
- Arduino Uno vs Arduino Leonardo
- Arduino Uno vs Arduino Micro
- Arduino Uno vs Arduino Mega
- Arduino Uno vs Arduino Nano

Advertisements