Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Romi Encoder Pair Kit vs ky-040 rotary encoder


Does the standard encoder like ky-040 work different than Pololu wheel encoders?
when I hook up a volt meter to the output of a ky-040 I can get the 5v pulse when manually turning it. when I do the same to the romi encoder I get nothing or floating type readings. Also it will not work with this code.I’m trying to program an Ardunio.

// read RPM

volatile int rpmcount = 0;//see http://arduino.cc/en/Reference/Volatile
volatile int rpmcount1 = 0;
int rpm = 0;
int rpm1 = 0;
unsigned long lastmillis = 0;
unsigned long lastmillis1 = 0;
void setup(){
 attachInterrupt(0, rpm_fan, FALLING);//interrupt cero (0) is on pin two(2).
attachInterrupt(1, rpm_fan1, FALLING);

void loop(){
 if (millis() - lastmillis == 500){  /*Uptade every one second, this will be equal to reading frecuency (Hz).*/
 detachInterrupt(0);    //Disable interrupt when calculating
 rpm = rpmcount * 10;  /* Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use rpmcount * 30.*/
 Serial.print("RPM =\t"); //print the word "RPM" and tab.
 Serial.print(rpm); // print the rpm value.
 Serial.print("\t RPM1=\t"); //print the word "Hz".
 Serial.println(rpm1); /*print revolutions per second or Hz. And print new line or enter.*/
   rpmcount = 0; // Restart the RPM counter
 lastmillis = millis(); // Uptade lasmillis
 attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
if (millis() - lastmillis1 == 500){  /*Uptade every one second, this will be equal to reading frecuency (Hz).*/
 detachInterrupt(1);    //Disable interrupt when calculating
  rpm1 = rpmcount1 * 10; 
// Serial.print(C); //print the word "RPM" and tab.
// Serial.print(rpm1); // print the rpm value.
// Serial.print("\t Hz=\t"); //print the word "Hz".
// Serial.println(rpmcount1);
 rpmcount1 = 0; // Restart the RPM counter
 lastmillis1 = millis(); // Uptade lasmillis
   attachInterrupt(1, rpm_fan1, FALLING); //enable interrupt

void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
void rpm_fan1(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
// Elimelec Lopez - April 25th 2013



The connections for the Romi encoder might be slightly different that those for the encoder knob you mentioned. VCC on the encoder board needs to be powered. Can you post pictures here that show how you have the board connected (including any soldered connections you made)?



I’ll try and send a pic later. What I did was terminate the A and B output of the encoder to 2 and 3 on an uno Arduino board directly. Im thinking your web site says I need to power the A and B and use a 10k or 20k pull-up resistor. I don’t have any power coming from your A and B.The ky-40 is a mechanical switch that is powered by the vcc. Please correct me if im wrong.


This is how I have it hocked up.


is this the way i should wire it?


The Romi encoder board has pullup resistors on it, so those pins can be connected directly to the I/O pins on an Arduino and another external set is not necessary.

If you power VCC on the encoder board with 9V, the A and B logic outputs will also be 9V. For a 5V logic microcontroller like the Arduino Uno board, you should connect VCC to 5V. If you tried operating the encoder board with the connections you show in your first picture, it is possible that the I/O pins you had A and B connected to on your Arduino Uno are damaged. You should test those pins to verify that they are still capable of registering 0V and 5V logic signals as LOW and HIGH.



I’ll bet thats it.Well, lessoned learned. It was one of those cheap Uno knocks offs any way. LOL.
Thanks nathanb, your the Man!!! I was about to get so discouraged I was thinking about throwing in the towel.I should have just bought the whole Romi kit. I might just do that.