Como convertir pulsos a mm

Hola buen dia, soy nuevo en el mundo arduino y empece un proyecto para crear una especie de "odometro" con un encoder y una placa arduino mega. Utilice un codigo de libreria lo que me permitio contar los pulsos y mostrarlos, pero ahora necesito convertir esos pulsos a mm para proyectarlos en un display y no logro entender como hacerlo. Dejo la descripcion de los componentes y codigo:

Arduino mega 2560
Encoder Bourns ECW1J-B24-ACOO24L

La conexion es Pin C a tierra, pin A a entrada 2 y pin B a entrada 3 de arduino.

El codigo que use es el siguiente:

#include <Encoder.h>

// Change these pin numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder knobLeft(4, 5);
Encoder knobRight(2, 3);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("TwoKnobs Encoder Test:");
}

long positionLeft  = -999;
long positionRight = -999;

void loop() {
  long newLeft, newRight;
  newLeft = knobLeft.read();
  newRight = knobRight.read();
  if (newLeft != positionLeft || newRight != positionRight) {
    Serial.print("Left = ");
    Serial.print(newLeft);
    Serial.print(", Right = ");
    Serial.print(newRight);
    Serial.println();
    positionLeft = newLeft;
    positionRight = newRight;
  }
  // if a character is sent from the serial monitor,
  // reset both back to zero.
  if (Serial.available()) {
    Serial.read();
    Serial.println("Reset both knobs to zero");
    knobLeft.write(0);
    knobRight.write(0);
  }
}

El encoder es de 24 pasos y cuenta 4 pulsos por cada paso, el diametro del eje es de 5mm entonces en una vuelta completa que son 96 pulsos deberia tener una medicion de 15.7mm.

Espero puedan ayudarme. Saludos!

Perímetro de la circunferencia: 2PiR o Pi*D = 3.14 * 5 mm = 15.7 mm

Si
96 pulsos son 15.7 mm
01 pulso ----- x = 15.7 mm * 1 pulso / 96 pulsos = 0,163542 mm x pulso

El enconder conectado a pines 4 y 5 eliminalo y todos los objetos con el tmb

Este es un ejemplo apropiado para ti

#include <Encoder.h>

// Change these two numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder myEnc(2, 3);
//   avoid using pins with LEDs attached

#define PasosEnMM 0.163542f  // constante float

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println("Pos : " + String(newPosition));
    float distancia = (float) oldPosition * PasosEnMM:
    Serial.println("mm : " + String(distancia));
  }
}

Si giras en el mismo sentido los mm se iran incrementando.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.