The N20 Motor with Encoder is a compact DC gearmotor featuring a built-in quadrature encoder that provides feedback on the motor's rotational position or speed. This motor is widely used in robotics, precision motion control, and hobbyist projects due to its small size, low power consumption, and precise control capabilities.
Pin Number | Description | Notes |
---|---|---|
1 | Motor Power (+) | Connect to positive voltage |
2 | Motor Power (-) | Connect to ground |
3 | Encoder Output A | Quadrature encoder output A |
4 | Encoder Output B | Quadrature encoder output B |
5 | Encoder Vcc (optional) | Encoder power supply (if separate from motor power) |
6 | Encoder GND (optional) | Encoder ground (if separate from motor power) |
// Example code for controlling an N20 Motor with Encoder using an Arduino UNO
const int motorPin1 = 3; // Motor power pin connected to Arduino pin 3 (PWM capable)
const int motorPin2 = 4; // Motor power pin connected to Arduino pin 4
const int encoderPinA = 2; // Encoder output A connected to Arduino pin 2
const int encoderPinB = 5; // Encoder output B connected to Arduino pin 5
volatile long encoderCount = 0; // Variable to store encoder count
// Interrupt service routine for encoder A
void encoderISR() {
if (digitalRead(encoderPinA) == digitalRead(encoderPinB)) {
encoderCount++;
} else {
encoderCount--;
}
}
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);
// Attach interrupt for encoder pin A (interrupt 0 is pin 2 on UNO)
attachInterrupt(digitalPinToInterrupt(encoderPinA), encoderISR, CHANGE);
}
void loop() {
// Set motor direction and speed
analogWrite(motorPin1, 128); // Set speed (0-255)
digitalWrite(motorPin2, LOW); // Set direction
// Do something with the encoder count
// For example, stop the motor after a certain number of counts
if (encoderCount > 1000) {
analogWrite(motorPin1, 0); // Stop the motor
// Reset the encoder count for the next run
encoderCount = 0;
}
}
Remember to adjust the example code to fit the specific technical specifications of your N20 motor with encoder, as these can vary between models and manufacturers.