
Unfortunately there wasn’t much on the Arduino web site about them so I did a search and found your web site. What came to mind was using a rotary encoder to set the frequency. I was originally going to use a compiled robot basic app but I wanted a stand-alone set up, preferably battery powered. So far I have been able to use it via the serial port. That said, I am designing an Arduino Uno based direct digital synthesizer using a DDS9850 module I got via Amazon.

I’m a retired EE and amateur radio operator (call N1ABE) with a lot of experience however, as part of that experience I’ve learned not to reinvent the wheel. Or you can use interrupts instead of checking the state of the pins in the loop() to ensure that no step is missed. Then it can’t know, which direction it was turned, so the counter will get slightly incorrect.īut you can counter that by checking, which direction it was turned before and increasing or decreasing the counter accordingly by 2. But if you turn it too fast or you do other stuff in your loop() that takes longer time you will miss a step and it will jump from 11 to 00 or from 10 to 01.

This works really great if you turn the rotary encoder at a normal speed. Example code (not easy to read but efficient and compact):īool A = digitalRead(pin_rotaryA), B = digitalRead(pin_rotaryB) To get the full resolution, you have to check every change. This method only uses half the resolution of the rotary encoder as there are four different states per cycle (11, 10, 00, 01) but you only check for TWO changes in each direction (if from 10 to 00 or from 01 to 11 –> counter++ if from 11 to 01 or from 00 to 10 –> counter–). Categories Arduino Tutorials, Electrical Engineering Reads the initial state of the outputAĪState = digitalRead(outputA) // Reads the "current" state of the outputA // If the previous and the current state of the outputA are different, that means a Pulse has occured if (aState != aLastState)įeel free to ask any question in the comments section below. */ # define outputA 6 # define outputB 7 int counter = 0 Here’s the Arduino code: /* Arduino Rotary Encoder Tutorial As an Amazon Associate I earn from qualifying purchases.

Arduino Board …………………………… Amazon / Banggood / AliExpress.You can get the components needed for this Arduino Tutorial from the links below:

We can connect the output pins to any digital pin of the Arduino Board.
