Getting Started with Encoder Sensor Module (SN-ENC-MOD)

Getting Started with Encoder Sensor Module (SN-ENC-MOD)

Last Updated on 6 July 2017
This article is written by internship student Tian Fu Loke


INTRODUCTION

The Encoder Sensor Module (SN-ENC-MOD) is an electro-mechanical device that converts the angular position or motion of a shaft or axle to an analog or digital code. The parameters monitored are determined by the type of application and can include speed, distance, RPM, position and etc. Revolutions per minute (abbreviated rpm, RPM, rev/min, r/min) is a measure of the frequency of rotation, specifically the number of rotations around a fixed axis in one minute. It is used as a measure of rotational speed of a mechanical component.


The RPM can be calculate as:
(60 * 1000 / pulsesperturn )/ (millis() - timeold)* pulses

FEATURES

  • Use imported groove coupler sensor.
  • Groove width:5mm.
  • Output state indicator lights.
  • Obscured output high; unobstructed output low.
  • The comparator output, the signal is clean, the waveform, driving ability, more than 15mA.
  • Operating voltage 3.3V-5V.
  • The output in the form: Digital switching outputs. (0 and 1)
  • A fixed bolt hole for easy installation.
  • Small plates PCB Dimensions: 3.2cm x 1.4cm.
  • Using a wide voltage LM393 comparator.
PINSDESCRIPTION
VCC3.3v-5v available
GNDGround connected to 0v
DODigital output
AOAnalog output

HARDWARE REQUIREMENT

SOFTWARE REQUIREMENT

Arduino IDE

HARDWARE SETUP

  1. Stack up your Arduino UNO/CT-UNO and 3A Motor Driver Shield together.
  2. Connect Dc Motor 12V to motor driver shield (M1A, M2A) to the terminal connector.
  3. Connect your dc encoder sensor Vcc to Arduino Vin, GND to Arduino GND and D0 to Arduino digital pin2. A0(Analog signal of the output pulses. The output signal in real time. (Usually not used).
  4. Connect your potentiometer Vcc to 5V, ground to 0V and Vco to Arduino A1.
  5. Connect USB port between Arduino UNO/CT-UNO to the computer to get the upload program.
  6. Connect your 12v power supply to the 3A motor driver shield.
  7. You can make a simple prototype to take look after upload program.

 

SAMPLE CODE

signed int motor1Speed;
int encoder_pin = 2;  // The pin the encoder is connected           
unsigned int rpm;     // rpm reading
volatile byte pulses;  // number of pulses
unsigned long timeold; 
// The number of pulses per revolution
// depends on your index disc!!
unsigned int pulsesperturn = 20;

 void counter()
 {
    //Update count
      pulses++;    
 }

void setup()
 {
   Serial.begin(9600);
   pinMode(encoder_pin, INPUT);
   pinMode(motor1Speed , OUTPUT); 
   attachInterrupt(0, counter, FALLING);
   pulses = 0;
   rpm = 0;
   timeold = 0;

 }

 void loop()
 {
   if (millis() - timeold >= 1000){  /*Uptade every one second, this will be equal to reading frecuency (Hz).*/
 
  //Don't process interrupts during calculations
   detachInterrupt(0);
   //Note that this would be 60*1000/(millis() - timeold)*pulses if the interrupt
   //happened once per revolution
   rpm = (60 * 1000 / pulsesperturn )/ (millis() - timeold)* pulses;
   timeold = millis();
   pulses = 0;
   
   //Write it out to serial port
   Serial.print("RPM = ");
   Serial.println(rpm,DEC);
   //Restart the interrupt processing
   attachInterrupt(0, counter, FALLING);
   int potvalue = analogRead(1);  // Potentiometer connected to Pin A1
    int motorspeed = map(potvalue, 0, 1023, 255, 0);
  analogWrite(motor1Speed, motorspeed); 
  digitalWrite(motor1Speed, 1);  
   }
  }


VIDEO

Note: For further inquiry, please visit our technical forum as we seldom check the comment here.