Arduino: bedieningsservomotor met potentiometer
In deze praktische tip leggen we uit hoe u een servomotor bestuurt met een potentiometer met behulp van een Arduino.
Regelservomotor met potentiometer - De vereiste componenten
Om dit beginnersvriendelijke project te kunnen implementeren, hebt u uiteraard een servomotor, een Arduino en een potentiometer van 10 kΩ nodig. U hebt ook een breadboard en enkele startkabels nodig om verbinding te maken.
Arduino: bouw circuit
- Plaats de potentiometer op het broodbord. Verbind de pen uiterst links met de plustaaf. De pin uiterst rechts is verbonden met de min balk. Sluit ook de middelste pin aan op Analog 0 op de Arduino.
- Verbind de rode kabel van de servomotor met de plusbalk en de bruine kabel met de minbalk. De sinaasappel is verbonden met pin 9 op de Arduino.
- Eindelijk is het enige dat u hoeft te doen de min-balk met een aarde en de plus-balk met de 5V-pin op de Arduino te verbinden.
Arduino: bedieningsservomotor met potentiometer - de code
Hieronder hebben we u voorzien van een eenvoudige code die u eenvoudig in de Arduino kunt laden.
- #include
- Servo myservo;
- int pot = 0;
- int waarde;
- void setup () {
- myservo.attach (9);
- }
- void loop () {
- value = analogRead (pot);
- waarde = kaart (waarde, 0, 1023, 0, 180);
- myservo.write (value);
- delay (15);
- }
In de volgende praktische tip laten we u zien hoe u een LCD kunt bedienen met de Arduino.