Forum >Rotary Encoder RPM?
ArduinoGeneral

Rotary Encoder RPM?

userHead alex 2018-06-12 11:58:40 1833 Views2 Replies
Hello, I have purchased the Incremental Photoelectric Rotary Encoder - 400P/R (SKU:SEN0230)

Do you have sample code for Arduino to find out the RPM of how fast the Encoder is spinning?

Thanks in advance!
2018-06-15 12:57:43 Hi, thank you for the reply. I did see that already and it looks like it just increments depending on the direction the encoder spins. Here is my current solution to detect how fast it is spinning:
Code: Select all
volatile unsigned int flag_A = 0;
unsigned long previousMillis = 0;
const long interval = 50;
void setup() {
pinMode(A_PHASE, INPUT);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt( A_PHASE), interrupt, RISING);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Serial.print(flag_A);
flag_A = 0;
}
}
void interrupt(){
flag_A += 1;
}
userHeadPic alex
2018-06-13 18:11:15 There is a code to count the cylinder number of the encoder in the wiki https://www.dfrobot.com/wiki/index.php/ ... U:_SEN0230 userHeadPic robert.chen