MATLAB Answers

Read rotary encoder from Arduino Uno in Simulink

242 views (last 30 days)
Apostolos Vrontos
Apostolos Vrontos on 20 Mar 2020
Edited: Phan Du on 7 Apr 2021
I can easily read the counts in Matlab (like this:, but not in Sumulink! Can someone tell me how it is the correct way to read the counts in real-time in Simulink?

Accepted Answer

Pranav Murali
Pranav Murali on 23 Mar 2020
I understand that you are trying to read the counts from a rotary encoder using Simulink. Although Simulink doesn't have a block to interface a rotary encoder at present, it can possibly be achieved in two ways:
  1. Write your code on MATLAB and import the function as a Simulink block. See how that is done here.
  2. Attach External Interrupt block to pins 2 and 3 to call an Interrupt Service Routine (ISR) function. The ISR will then perform bitwise comparison of the two inputs to increment/decrement the counts.
The idea behind the second approach is to implement the rotaryEncoder function through existing Simulink blocks.
Phan Du
Phan Du on 7 Apr 2021
Hi! You can follow the attach file.(Version Matlab 2020a)

Sign in to comment.

More Answers (1)

Hasan Falah
Hasan Falah on 30 Jun 2020
Hello friends,
I’m using arduino Due to read incremental rotary encoder by simulink, there is no block in sinulink to do that.
I tried with external interrupt example in matlab 2020a but it is reading only in one direction and just increasing, so it should be readings in clockwise and counterclockwise.
Aslo I tried with encoder S-Function in Device Driver examples but also does not work.
Your help please .....
Harshil Jani
Harshil Jani on 29 Mar 2021
Hi Yago menezes, If you are able to use it using simulink please send me to

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!