Professional Documents
Culture Documents
MATERIALI: servo motore, Arduino, potenziometro, breadboard, pulsante, led, cavo USB, cavi per eseguire i
collegamenti.
CENNI TEORICI:
1)The components that we are going to use in this two experiences are:
- USB cable: to connect our Arduino at the computer. Moreover the USB cable provides the correct power
source tension to Arduino’s card;
- light emitting diode: component that emit light when it is crossing by current. It has two pins: anode (+)
and cathode (-). We connect anode to one of the Arduino’s digital pin and cathode at the GND. Anode is the
longer pin, and cathode is the shorter;
- potentiometer: is a variable resistor, that changes value, when its handle is turned. It is composed of
three pins. The extremes pins are connected at the 5V pin and the other one at the GND. The middle pin is
connected at one of Arduino analogical pin;
- servomotor: a device system who is able to make mechanical movement in function of the signal
applicated at his entrance. He is composted by 3 pins: the yellow one at Arduino digital pin, the red one at
the 5V and the brown one at the GND;
- resistance: an electrical component that oppose the passage of current. The unit of measurement is Ohm
(Ω). The coloured stripes represent the value of the resistance;
- #include: to insert the library to create programs. In this case we are going to use: #include<Servo.h> to
insert some functions of servomotor;
- instruction if …. else : if the condition is respected the program can do the instructions inside it, otherwise
it skips the block of instruction moving on the following in the else part;
- pinMode : composed by two parts, the first configurates one of Arduino’s pins, while in the second part
we put INPUT or OUTPUT. The structure of pinMode is: (pin, INPUT/OUTPUT);
- digitalWrite: composed by two part: the first indicated the pin and the second indicates the status of the
pin. HIGH or LOW. the structure of digitalWrite is (pin, status). For example digitalWrite (9,HIGH); is this
case the light emission diode is turn off. if we put LOW the light emission diode is turn off;
- delay : stops the program for a period of time expressed in milliseconds. for example: delay(1000); the
program in this case waits one second;
- map: transforms a number from one variable to another variable by using a proportion. the structure of
map is : map(var, var min, var max, in min, in max):
var min and var max: are the minimal and the maximal number of the variable var in entrance.
in min and in max: are the minimal and the maximal number of the new variable in exit.
1) Procedimento e funzionamento del programma per quanto riguarda la gestione del servomotore con il
potenziometro.
1)collegamento motore
2)collegamento potenziometro
3)collegamento Arduino
Una volta caricato il programma sulla scheda di Arduino e dopo aver girato la manopola del potenziometro,
Arduino andrà a legge il valore del potenziometro sul piedino A0, che verrà assegnato a una variabile
chiamata “pot”. Il valore della variabile “pot” verrà convertito, tramite la funzione “map”, in un valore
adatto al servo motore e il valore trasformato lo salverà in una variabile chiamata “mot”. Il valore di mot
verrà inviato al servo motore che eseguirà il movimento. Il programma aspetterà poi 50 ms prima di
ripetere il ciclo. Questo tempo serve anche al servomotore per poter raggiungere la posizione assegnata.
2) Procedimento e funzionamento del programma per quanto riguarda la gestione del servo motore con
potenziometro, pulsante e led.
1)collegamento motore
2)collegamento potenziometro
3)collegamento Arduino
4) collegamento led
- collegare catodo alla GND, mentre anodo con una resistenze al pin 9 di Arduino. Per riconoscere anodo e
catodo guardare piedini led. Piedino più lungo è l’anodo mentre quello più corto è il catodo.
5)collegamento pulsante:
6)collegare generatore di tensione impostato sui 5 V fissi. Il cavo nero uscente dal generatore posizionarlo
sul – della breadboard, mentre l’altro sul + .
Una volta caricato il programma sulla scheda di Arduino, Arduino controllerà se il pulsante è stato premuto
oppure no. Se il pulsante non sarà stato premuto il motore e il led saranno spenti. Per vedere se lo stato
del pulsante useremo il monitor seriale, dove comparirà 1 se pulsante è premuto e 0 quando non è
premuto. Quando il pulsante è premuto, si accenderà il led e Arduino leggerà il valore del potenziometro
sul pin A0 e assegnerà il valore letto a una variabile chiamata “pot”. Successivamente trasformerà questo
valore in un valore adatto per il servomotore tramite la funzione “map”, che assegnerà il valore trasformato
alla variabile “mot”. Dopo di chè il valore della variabile “mot” verrà mandato al servo motore che eseguirà
il movimento. Prima di ripetere il ciclo il programma aspetterà 50 ms. Questo tempo serve anche al
servomotore per poter raggiungere la posizione assegnata.
int mot=0; //variabile dove viene inserito il valore convertito del potenziometro.
mot=map(pot,0,1023,0,180); //converte il valore del potenziometro che va da 0 a 1023, in valori che vanno
da 0 a 180,tramite una proporzione, che sono i gradi che il servomotore può assumere. Valore mot sarà da
0 a 180.
Myservo.write(mot); //posizione del servo motore in base al valore della variabile mot.
delay(50); // aspetta 50 ms prima di ripartire con il ciclo della funzione loop. Questa pausa serve anche al
servomotore per raggiungere la posizione assegnata dal potenziometro.
}
2)Descrizione del programma del servo motore gestito da potenziometro, pulsante e led.
Serial.begin (9600);// Prepara Arduino a mandare e ricevere i dati tramite la porta seriale. In questo caso
riceve i dati del pulsante.
digitalWrite(9,HIGH);//led si accende.
delay(50);// aspetta 50 ms prima di ripartire con il ciclo della funzione loop. Questa pausa serve anche al
servomotore per raggiungere la posizione assegnata dal potenziometro.
}
}
CONCLUSIONI
To sum up, the project that we had to do today, allowed us to control a servomotor in 2 different ways. The
first was with the potentiometer and the second with a button that turns on or off the servomotor.
The project that we did can be re-used in the future. For example we can create a radar, adding sensors.
The radar task is to observe if there are or not objects and send to Arduino where the object is and its
distance. Al the program are controlled by a potentiometer, who lead the radar. The led we can use to
signal if the radar is moving and buttons to turn on and off or move right or left the sensor.