Arduino Projects

Arduino IDE Tutorial, how to write Your First Program, install libraries

Arduino IDE, Description:


Arduino IDE- the Arduino integrated development environment is a cross-platform application that is written in the programming language Java.

Arduino IDE

It is used to write and upload programs to the Arduino board. It can run on Windows, Mac OS X, and Linux. You can find different versions of the Arduino IDE, but I recommend you should download the latest version of the Arduino IDE. You can Download the Latest Version of the Arduino IDE by clicking on the Download Button below.

Download: Latest Version of the Arduino IDE

In this tutorial, I am going to practically show you how to master the Arduino IDE. In this Tutorial, I will also explain how to define Variables, and what are the rules that we follow while defining any variable. I will also explain what are the common errors and how to fix them. I this tutorial I will also explain how to use a library. In fact, this tutorial explains everything that you need to know. For this tutorial, you will only need the Arduino Uno Board and the USB cable. The Arduino Amazon purchase link is given below.

If you are planning to work on a project in the future then I recommend you should purchase the most common tools used in making the project, you can find the purchase links below. Without any further delay let’s get started.

Amazon Links:

Arduino Uno

Arduino Nano

Mega 2560:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines


Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Arduino IDE:

Arduino IDE

Usually, the Arduino IDE is the first IDE we use when approaching the first time to Arduino. This happens for several reasons: it is easy to use, it supports all the Arduino boards,

Arduino IDE

Which you can find by clicking on the tools menu and then hover your mouse cursor over the Board, this way you can find all the supported board, as you can see in the picture above currently the Arduino Uno board is selected and it has a built-in library manager that is also easy to use.

Arduino IDE

Moreover, the Arduino IDE is very user-friendly without too many options, menus, and so on that could scare an inexperienced user. It is so easy that we do not have to worry about how it works; we can focus only on the development process. We write the Arduino code, and the Arduino IDE compiles it and uploads the compiled code into the Arduino board. That’s it!

Let me practically explain the most basic things that you should know before you start the programming.

  • How to check the COM Port and how to select a board?

First of all, connect the Arduino board with the Laptop or Computer.

Arduino IDE

Now click on the tools menu, go to board and as you can see the right board is selected.

Arduino IDE

Now go to port and select the port to which Arduino is connected.

Arduino IDE

This is how you can check the board and select a port. Now let’s do it for the Mega.

Arduino IDE

while the mega board is connected with the laptop, go to the tools menu and select the mega board.

Arduino IDE

Now go to port and select the desired port to which the mega board is connected.

Arduino IDESo this is how easily we can select different boards and ports. These are the steps which you have to go through before you start the programming, As it’s impossible to upload a program into the Arduino or Mega board unless you select the right board and right com port.

Now I will explain some of the most commonly used functions through a practical example. I will use a push button to control a Led.

How to write your first Program using the Arduino IDE.

Everything that you see has a Name; every person in a family has a unique name, as your name is unique among your brothers and sisters. We use the same concept in the programming when it comes to the variable names. Let’s for example you want to use a led with pin number 12 of the Arduino. You can start by writing

Int led = 12; //so this instruction means that an led is connected with pin number 12 of the Arduino. Never use the same variable name for any other pin. If you want to use another led then you can simply write

Int led2 = 11;  so each time you define a pin use a unique name. let’s also use one push button.

Int push_button = 4;

The variable names follow some rules, like for example

No spaces are allowed in the variable names.

Arduino IDE

no numbers are allowed in the beginning of the variable names.

Arduino IDE

Every Arduino or Mega program has at least two functions, which are the void setup and void loop function. Void means that these functions are not returning any value while the empty parenthesis means that these functions are not taking any arguments as the input.

Void setup function executes only one time when the Arduino or mega board is turned ON.

As you know the led’s are the output devices and the push button is the input device. Now we have to tell this to the Arduino. For this we have a function which is pinMode function. pinmode is a function and it takes two arguments as the input, the pin number or pin name and the status which can be input or output. its use is very simple. we simply write,

pinMode(led, OUTPUT);

as this is a case sensitive language so we have to keep the M capital, any change in the alphabet will result in an error. Now similarly for the led2,

pinMode(led2, OUTPUT);

as you know push button is an input device, so we set this as input.

pinMode(push_button, INPUT);

Arduino IDE

As you can see how easily we can tell the Arduino which device is input and which device is output. Make sure before you start the programming, you know exactly which device is input and which device is output.

If you want to establish the serial communication between the Arduino and Computer, for this we use the Serial.begin() function. Serial.begin() is a built in function unlike the pinMode function. But it takes one argument as the input which is the baud rate. Or in simple words is the communication speed in bits per second. Its use is very simple we simply write


Arduino IDE

9600 is the standard baud rate and is most commonly used. But this is not the only baud rate that you can use, we have different baud rates. But I will be using 9600.

So if you want to send the sensors values or text messages to the computer screen you will need to activate the serial communication using the serial.begin function. So now that the serial communication is activated now we can use the serial.print function to send a message to the computer serial monitor screen.

Serial.print is a function which is used to send numeric values or text messages, its use is very simple, we simply write

Serial.print(“setup  completed”);

So setup  completed is a message that we want to print on the serial monitor.

Arduino IDE

 Digitalread is a built-in function and is one of the most frequently used functions. DigitalRead function is used to read any digital pin of the Arduino or Mega. Or in simple words we can say it is used to check wither the desired digital pin is high or Low. Digitalread function is most commonly used with if condition.

Arduino IDE

If ( digitalread(push_button) == LOW ) this condition means that if the push button is pressed. As the ground is connected with the push button. So when the push button is pressed it will give ground as a signal on pin number 4. So if the push button is pressed then simply turn on the led using the digitalWrite function. To Turn ON the LED we simply write the following instruction.

Digialwrite(led, HIGH);

 digitalwrite is a built-in function and it takes two arguments as the input the pin number or pin name and a high or low signal. Digitalwrite function is used to turn on or turn off any pin. As I am using high so the led will turn ON and also a message will be sent to the computer screen that the led is turned on. Then a delay of 1 second. As 1000 milli seconds are equal to 1 second. When the button is released the LED is turned OFF and a message is send to the computer screen that the LED is turned off and again a delay of 1 second. And keep the push button at logic level high.

After the programming is completed then the next step is to upload the Program by clicking on the Upload button “a button with the Arrow symbol”.

Arduino IDE

As you can see the Arduino is connected with the laptop, make sure that the right port is selected and also make sure that the right board is selected, before you upload the program, first click on the verify button to check for any errors.

Arduino IDE

as you can see this program has no errors now it’s time to upload the program by clicking on the upload button and wait for a while.

Arduino IDE

As you can see the program has been upload. Now click on the serial monitor.

Arduino IDE

Arduino IDE

As you can see we have different Baud rates, but as I have used 9600 in the programming so I will use 9600.

Arduino IDE

Arduino IDE

Now we can Turn ON and turn OFF this led using the Push Button.

Arduino Library How to install and use?

Arduino IDEArduino has some built-in libraries, which you can find by clicking on the Sketch menu, then include library. You will see a complete list of all the available libraries. But these are not the only libraries that we can use, there are thousands of libraries available on the internet created for different sensors and boards. You can find maximum of the libraries on the Github.

You can also install a library by clicking on the manage libraries.

Arduino IDEIt will automatically start updating the libraries. You can search for a library by typing the name of the library in the filter your search box. Let’s say I want to search for the ESP8266 library.

Arduino IDE

You will see all the libraries available for the Nodemcu ESP8266 wifi Module, and then you can select the one you want. After you install the desired Library then all you need is just to include the library and it will be added in the program.

I have hundreds of Arduino-based Projects available on my YouTube channel “ Electronic Clinic “.

Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button