Servo Motor Control
Zur Navigation springen
Zur Suche springen
Two examples for connecting:
1) a classic servor motor to Arduino
2) a stronger servo motor, the Dynamixel AX-12A, to Arduino
Example 1: Servo Motor Basics with Arduino
https://docs.arduino.cc/learn/electronics/servo-motors
Example 2: Using Dynamixel AX-12A Servo with Arduino
https://www.youtube.com/watch?v=JQSY8jlgW90
Wiring Diagram
AX-12A pin1: GND ---> DC -12V
AX-12A pin2: VDD ---> DC +12V
AX-12A pin3: DATA ---> Tx pin of Arduino
- Connect the two grounds together ***
pinout diagram: https://github.com/makertut/ax12-arduino
Arduino Library
Download ZIP and install this library in Arduino:
Ax-12A Library https://github.com/jumejume1/AX-12A-servo-library
Code Example
/*
* Example showing how to send position commands to AX-12A
*/
#include "Arduino.h"
#include "AX12A.h"
#define DirectionPin (10u)
#define BaudRate (1000000ul)
#define ID (1u)
int initial_pos = 512;
int max = initial_pos + 350;
int min = initial_pos - 350;
int pos = initial_pos;
int delta = 1;
void setup()
{
ax12a.begin(BaudRate, DirectionPin, &Serial);
}
void loop()
{
pos = pos + delta;
if (pos > max)
{
pos = max;
delta *= -1;
}
if (pos < min)
{
pos = min;
delta *= -1;
}
ax12a.move(ID, pos);
delay(20);
}