General Commands
Let us see a list of commands that are used in almost every project.
setup()
It is used to configure the program.
void setup() {
//Programs like including libraries
}
loop()
It includes the programs that will run when the board is in an “ON” state.
void loop() {
//main program here
}
delay()
This is used to add a pause in the function for a certain millisecond as required. The code snippet shows the use of the delay function.
void loop() {
digitalWrite(LED, HIGH); //turn on an LED
delay(1000); //paused for 1 second(1000 milliseconds)
digitalWrite(LED, LOW); //the LED is turned off
}
millis()
Not used very often but this function can allow you to run multiple functions consecutively without putting anything to a halt. It uses intervals to store the time since the last operation or function was running. Here is a code snippet.
// Record the time of the first event
unsigned long firstEventTime = 0;
// Record the time of the second event
unsigned long secondEventTime = 0;
// Set the interval for the first event to occur
const long firstEventInterval = 5000;
// Set the interval for the second event to occur
const long secondEventInterval = 1000;
void setup() {
// Any necessary setup can be done here
}
void loop() {
// Record the current time since the program started
unsigned long currentTime = millis();
// Check if it’s time for the first event
if (currentTime – firstEventTime >= firstEventInterval) {
// Update the time of the first event
firstEventTime = millis();
// Execute code for the first event every 5 seconds
}
// Check if it’s time for the second event
if (currentTime – secondEventTime >= secondEventInterval) {
// Update the time of the second event
secondEventTime = millis();
// Execute code for the second event every 1 second
}
}
Getting Started With Arduino
Arduino is an important device used in electronics engineering for creating mini-projects or for integrating large projects. Arduino itself consists of various components that can be programmed according to the project requirements using some assembly languages like C/C++.
Arduino is the first choice of many professionals due to the ease with which it can be programmed and how it allows interactive features for user experience. Arduino is programmed to include both hardware and software components which account for its use in different fields like designing, sensing, and testing.
Since Arduino is an open-source platform, it is used globally by users all across the globe. Let us study what is an Arduino, what functionalities it has and how can we use it in daily life.
Table of Content
- What is Arduino?
- Arduino Hardware
- Basic Operation
- Circuit Basics
- Electronic Signals
- Arduino API
- Libraries
- Why choose Arduino?
- Structure of Arduino
- Components of Arduino