Help programming a 3 pin rotary encoder??

Hello!

So I am REALLY new to coding but I am currently trying to program a rotary encoder

http://uk.rs-online.com/web/p/mechanical-rotary-encoders/7295924/?searchTerm=729-5924&relevancy-data=636F3D3126696E3D4931384E525353746F636B4E756D6265724D504E266C753D656E266D6D3D6D61746368616C6C26706D3D5E5C647B337D5B5C732D2F255C2E2C5D5C647B332C347D2426706F3D313426736E3D592673743D52535F53544F434B5F4E554D4245522677633D4E4F4E45267573743D3732392D35393234267374613D3732393539323426

using an arduino nano.

I have wired it up to 5v, GND and the centre pin to A0.

going off of coding that I have seen previously for a potentiometer, I have come up with the following

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

}

void loop() {

  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(1);
  // put your main code here, to run repeatedly:

}

I thought that I had cracked it.

but I really had not.

when you look at the serial monitor it will display a value, but when you spin the encoder it goes a bit crazy and just doesn't display anything.

I have been searching the depths of the internet for days now to no avail, all the other examples seem to be different encoders.

As I am new to this I am really unsure of what information I need to include,

Any help/advice would be greatly welcomed!

Thanks,

T

I have been reading up/googling for days, I wouldn't of posted this unless I had. I do understand that they are different, however all examples that I had seen for encoders were either the 5 pin versions or the wrong type of encoder, hence why I though about the potentiometer code. if there are only 3 pins how do I get pulses on two?

One pin will be common. Connect that to ground. The other two will connect to digital pins, with INPUT_PULLUP enabled on both.

5 pin encoders probably have a switch that is activated by pushing on the knob.

Thank you I will give it a shot!

This old thread of mine might help, but as always YMMV.

(It is, by the way, listed in the sticky at the top of this forum.....)

I really am new to programming so no I didn't make that association.

JimboZA:
This old thread of mine might help, but as always YMMV.

(It is, by the way, listed in the sticky at the top of this forum.....)

Thanks, I did come across this earlier but I am still managing to have issues! going to have a bit more of a fiddle with it and go from there :slight_smile: