Arduino deneyi 16
Joystick Servo Control
Intermediate · 50 min · Input mapping
Use a joystick’s horizontal axis to position a servo from 0° to 180°.
Malzemeler
- Arduino Uno
- 2-axis joystick module
- SG90 micro servo
- Jumper wires
- External regulated 5V supply recommended
Bağlantı
- Connect joystick VCC to 5V, GND to GND and VRx to A0.
- Connect servo signal to pin 9 and its power to regulated 5V.
- Join external supply GND to Arduino GND.
Kod
#include <Servo.h>
Servo arm;
const int joyX = A0;
void setup() { arm.attach(9); }
void loop() {
int reading = analogRead(joyX);
int angle = map(reading, 0, 1023, 0, 180);
arm.write(angle);
delay(15);
}
Ne olmalı?
The servo follows horizontal joystick movement.
Meydan okuma
Add a small dead zone around the joystick centre to reduce jitter.
Güvenlik ve sorun giderme
- Bağlantıyı değiştirmeden önce gücü kes.
- Her LED ile direnç kullan.
- Kart ve port seçimini Arduino IDE'de kontrol et.
- Her kablonun koddaki pin numarasıyla eşleştiğini doğrula.
Not: Ders metinleri İngilizcedir. Orijinal Türkçe çalışma kâğıdı PDF olarak indirilebilir.
