Introduction: Arduino Tutorial 1 : Led Blink

Con questo programma andremo ad accendere e spegnere un comune led.


With this program we will turn on and off a common led.

Step 1: Progettazione

Colleghiamo l’anodo (+) alla resistenza , quindi al pin digitale 13 dell’Arduino e il catodo (-) al pin GND.

Materiale occorrente:

  • diodo led.
  • resistenza da 220 Ohm

Connect the anode (+) to the resistance, then to the Arduino digital pin 13 and the cathode (-) to the GND pin.

Material Required:
  • diode led.
  • 220Ohm resistor





Step 2: Programmazione

Dopo aver caricato questo programma sul vostro Arduino, potrete verificare che il diodo led emetterà luce per 1 secondo e rimarrà spento un altro secondo.

In questo programma i tempi e le modalità di funzionamento possono essere modificati a proprio piacimento;sottraendo da 1000ms, il led si accenderà e spegnerà più velocemente e viceversa aggiungendo.

Attraverso la funzione " #define " andremo a definire il nome della porta di arduino che utilizzeremo, utilizzando la seguente sintassi ( nomevariabile, numeropin);

Con "pinMode()" definiamo la funzionalità del pin di arduino,ad esempio, in questo caso, il led è un dispositivo output, quinidi definiamo "pinMode(led,OUTPUT)"; Prestare particolare attenzione al fatto che l'IDE Arduino è sensibile ai caratteri maiuscolo-minoscolo.Queste funzioni vanno scritte all'interno del "void setup()", cioè il menù dell funzioni del programma.

Attraverso la funzione "digitalWrite(nomepin,valore)" andremo appunto a scrivere sul pin digitale, e faremo accendere il led attraverso il comando "digitalWrite(led,HIGH)" nella quale: led è il nome del pin digitale di Arduino, "HIGH" è il livello logico che gli assegnamo, che può variare a "LOW" (led spento).

La funzione "delay()", invece, è utilizzata al fine di mettere in pausa, per il tempo in millisecondi indicato tra le parentesi, il programma: in pratica noi abbiamo detto al programma di accendere il led, di aspettare 1000ms, spegnerlo per poi accenderlo tra altri 1000ms. Questo procedimento viene svolto all'infinito (questo da il nome alla funzione "void loop()").

After loading this program on your Arduino, you can check that the LED diode will emit light for 1 second and will be off another second.
In this program, the timing and operating modes can be changed to your liking;
subtracting from 1000ms, the LED will turn on and off faster and vice versa by adding.
Using the "#define" function, we will define the name of the arduino port that we will use using the following syntax (null variable, numeropin);
With "pinMode ()" we define the functionality of the arduino pin, for example, in this case, the LED is an output device, quinidas define "pinMode (led, OUTPUT)"; Pay special attention to the fact that the Arduino IDE is sensitive to uppercase and lowercase characters. These functions must be written in the "void setup ()", ie the program menu.
Through the function "digitalWrite (namepin, value)" we will write to the digital pin and turn on the led via "digitalWrite (led, HIGH)" command in which: led is the name of the digital pin of Arduino, "HIGH "is the logical level we assign, which may vary to" LOW "(led off).
The "delay ()" function is used to pause, for the time in milliseconds shown in brackets, the program: in practice we told the program to turn on the led, wait 1000ms, turn it off for then turn it on to another 1000ms. This procedure is done infinitely (this is the name of the function "void loop ()").

Code:

#define led 13        //Diamo il nome "led" alla porta 13<br>
void setup() {
pinMode(led,OUTPUT);  //Definiamo la tipologia di funzionamento che dovrà assumere
                      //la porta "led", in questo caso è OUTPUT
}
void loop() {
  digitalWrite(led,HIGH); //Attribuisco al pin "led" un valore logico ALTO
  delay(1000);            //Aspetto 1000ms (1 secondo)
  digitalWrite(led,LOW);  //Attribuisco al pin "led" un valore logico BASSO
  delay(1000);            //Aspetto 1000ms
}