The site for those who love tinkering with Arduino, Raspberry Pi & Co.

The first project with Arduino


Let's create our first Arduino program and run it on the board with our first project

Now that we have a general idea of what arduino is and how it is made and we have correctly installed our IDE, we can start to start our first project.

To carry out our project we need:

  • An Arduino Uno board
  • One LED diode in the color of your choice
  • A computer with the Arduino IDE installed

What we are going to do is to correctly connect a led to Arduino and turn it on and off at an interval set by us.

A LED is a special diode (electronic component to control the flow of current) which, when subjected to a passage of current, in addition to performing its normal function as a diode, that is to pass the current in one direction only, emits a beam of light of various colors and intensity depending on the type of LED.

Due to their nature of diodes, to use them you need to recognize the "pins" that are not interchangeable with each other: there is in fact the cathode which is the shortest terminal (pin) and which must normally be connected to ground because it is the negative terminal. The other terminal instead, the positive one is called Anode and has the longest terminal.

In the image below we can see a typical LED diode depicted

Led: Recognize Anode and Cathode
Recognize Anode and Cathode

So let's take our LED and insert the shorter terminal (the Cathode) to the ground pin (GND) of Arduino and the longer terminal (Anode) to pin 13 (I recommend 13!) Of Arduino and our circuit is already ready! Once the circuit is assembled the result should be something like this:

Arduino Blink - Example
Arduino Blink – Example

The ground pin and pin 13 are close, the connection is convenient. Now we can write our first program, indeed for our project we will use an example already present in the Arduino ide and we will not need to write anything.

We then go to the file menu and select "Examples" then "Basics" and finally "Blink", once this is done in the editor area the code shown in the box below should appear which will be the code that we are going to insert in our Arduino board for the our first project.

/ *
  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
* /
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup () {                
  // initialize the digital pin as an output.
  pinMode (led, OUTPUT);     

// the loop routine runs over and over again forever:
void loop () {
  digitalWrite (led, HIGH); // turn the LED on (HIGH is the voltage level)
  delay (1000); // wait for a second
  digitalWrite (led, LOW); // turn the LED off by making the voltage LOW
  delay (1000); // wait for a second

This program taken from the Arduino examples is one of the simplest but it is great for starting, its purpose is to continuously turn on and off the led that we connected to pin 13 at a predetermined interval (in our case one second, or 1000 milliseconds ).

For the microcontroller this means supplying current and removing it on pin 13 as it does not really care what we have attached to it: for example, you could put a relay and our LED could become a 220 volt light bulb of those we use at home. (but please don't do it! to put a relay there are other things to consider in the circuit and components to add that we haven't talked about and with the 220V current it's easy to get hurt !!).

Now we can take our Arduino board and connect it to the pc via the USB cable.

Generally, when connecting the board to the PC for the first time, it is necessary to wait a few seconds for the system to recognize the new hardware, it may be necessary to download additional drivers to correctly configure the Arduino connection to our PC.

Fortunately I have never had this problem and every time I connected Arduino to the PC after a few seconds I always had the peripheral configured correctly, I can tell you this for the systems I have tried: linux Ubuntu or Fedora or Windows 7 and even windows XP!

In case this unfortunately does not happen for you, I refer you to the driver pages of the main site for the various operating systems:

If everything is ok we can proceed with the selection of the board and the serial port, these options are the last necessary configurations of which we must ensure the correctness in order to proceed with the programming of the Arduino: then we go to the Tool menu, select board and check that the selected board is our Arduino Uno, finally check the connection this time in the serial port menu.

Well! From the main command bar we can press the button "Compile and load the Sketch", the Arduino ide will start compiling the sketch.

After a few seconds, when the compilation is finished, the transfer to the card will begin. In fact, we will be able to see some LEDs flashing near the USB port which indicate that the transfer of our program is in progress. A few moments later (the transfer should be quite fast) we will almost magically see our led start flashing and I hope you will be happy to have completed your first Arduino project!

Before leaving you one last thing: the choice of pin 13 was not random, to drive a LED from an Arduino digital output in fact normally you would also need a resistor to limit the current, this to avoid overheating of the diode LED that may burn out after a while.

Pin 13 is particular because it already has a resistor inserted by the Arduino circuit: to start with our projects we didn't even need to worry about this!

Arduino Blink
Arduino Blink

Arduino starter Kit
Arduino Starter Kit Ufficiale Per iniziare alla grande con Arduino

Ti è rimasta una domanda o un dubbio?

Iscriviti e chiedi nella community

Leave a Reply

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