2  Arduino IDE

2.1 What is Arduino IDE?

Arduino IDE (Integrated Development Environment) is a software application that is used to write and upload code to MCU boards. Arduino IDE code is written in C or C++ programming language. It is a free and open-source platform that makes it easy for beginners to get started with Arduino programming.

Arduino IDE comes with a text editor, a code library, and a serial monitor that allows you to communicate with your Arduino board. It is available for Windows, Mac, and Linux operating systems.

2.2 How to Install Arduino IDE?

Follow these simple steps to install Arduino IDE on your computer:

2.3 Step 1: Download

Go to the official Arduino website and download the latest version of the Legacy IDE (1.8.X) for your operating system. Don’t download version 2.0.X, it will work for you but all the tutorials we will be following are in the previouse version (1.8.X).

2.4 Step 2: Install Arduino IDE

Once the download is complete, run the installer and follow the on-screen instructions to install Arduino IDE on your computer.


Congratulations, you have successfully installed Arduino IDE on your computer and you are ready to start programming your MCU! Adruino IDE

2.5 How to use Arduino IDE?

In this guide, we will explain the basics of Arduino IDE code and how to write your own Arduino programs.

2.5.1 The Arduino IDE

The Arduino Integrated Development Environment (IDE) is a software development platform for creating programs that run on Arduino boards. The IDE includes a code editor, a compiler, and a firmware uploader. You can use the IDE to write, edit, and upload your Arduino programs.

2.5.2 The Setup and Loop Functions

In the Arduino IDE, every program must have two functions: setup() and loop(). The setup() function is called only once when the program starts, and it is used to initialize the program and set up any necessary variables. The loop() function, on the other hand, is called repeatedly after the setup() function, and it is used to run the main program logic.

2.5.3 Libraries

Libraries are prewritten pieces of code that you can use in your Arduino programs. Libraries contain functions and variables that you can use to make your programming tasks easier. You can include libraries in your program by using the #include directive at the beginning of your program.

2.5.4 Variables

Variables are used to store values in your program. In Arduino programming, you need to declare your variables at the beginning of your program. To declare a variable, you need to specify its data type and name. For example, int myVariable = 10; declares an integer variable called myVariable and assigns it the value 10.

2.5.5 Functions

Functions are blocks of code that perform a specific task. In Arduino programming, functions can be used to simplify your program and make it easier to read and understand. To create a function, you need to specify its return type, name, and any arguments it requires. For example, int my_function(int arg1, int arg2) creates a function called my_function that takes two integer arguments and returns an integer value.

2.5.6 Putting It All Together

Now that you understand the basic elements of Arduino programming, you can start writing your own programs. To get started, you can follow these steps:

  1. Open the Arduino IDE and create a new sketch.
  2. Write your program code in the setup() and loop() functions.
  3. Declare any variables and functions you need at the beginning of your program.
  4. Include any libraries you need by using the #include directive.
  5. Upload your program to your Arduino board by clicking the upload button in the IDE.

2.6 Conclusion

Arduino IDE code is an essential part of Arduino programming. Understanding the basics of Arduino IDE code, including the setup() and loop() functions, libraries, variables, and functions, is essential for creating your own Arduino programs. With practice and patience, you can become proficient in Arduino programming and develop exciting projects using the Arduino platform.

2.7 Example

// Include the necessary library for controlling the digital pin
#include <Arduino.h>

// Define the pin number for the LED
const int LED_PIN = 13;

void setup() {
  // Set the LED pin as an output
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  // Turn the LED on
  digitalWrite(LED_PIN, HIGH);

  // Wait for 1 second
  delay(1000);

  // Turn the LED off
  digitalWrite(LED_PIN, LOW);

  // Wait for another second
  delay(1000);
}

Let’s break down each part of the program:

#include <Arduino.h>

This line includes the Arduino library, which contains functions for controlling the digital pins on the Arduino board.

const int LED_PIN = 13;

This line defines a constant integer variable called LED_PIN and assigns it the value 13. This is the pin number that the LED is connected to.

void setup() {
  // Set the LED pin as an output
  pinMode(LED_PIN, OUTPUT);
}

This is the setup() function, which is called once when the program starts. In this function, we set the LED pin as an output by calling pinMode(LED_PIN, OUTPUT).

void loop() { ... }

This is the loop() function, which is called repeatedly after the setup() function. In this function, we turn the LED on by calling digitalWrite(LED_PIN, HIGH) and then wait for 1 second by calling delay(1000). We then turn the LED off by calling digitalWrite(LED_PIN, LOW) and wait for another second.

  // Turn the LED on
  digitalWrite(LED_PIN, HIGH);

  // Wait for 1 second
  delay(1000);

  // Turn the LED off
  digitalWrite(LED_PIN, LOW);

  // Wait for another second
  delay(1000);

These two lines turn the LED on and off by setting the voltage of the LED pin to HIGH and LOW, respectively.

delay(1000);

This line causes the program to pause for 1 second (1000 milliseconds) before continuing. The delay() function is used to control the timing of the program.

Overall, this program is very simple, but it demonstrates the basic structure of an Arduino program. The setup() function is used to initialize the program, while the loop() function is used to perform the main program logic. The program uses the digitalWrite() function to turn the LED on and off, and the delay() function to control the timing of the program. By understanding these basic concepts, you can start to build more complex programs on the Arduino platform.