- Fri Nov 23, 2018 8:30 am
#201126
Hey There
I would like to Convert the Output from my Rotary Encoder into a proportion voltage output using the MCP4725.
Here's the Encoder I own: http://www.encoderonline.com/Data-Sheet ... ata-07.htm
Outout AB / 1,000ppr
I'm able to read the change in state on the serial with the code below.
I however need to be able to output a voltage range to correspond with the RPM the encoder is spinning at.
My Shaft's MAX RPM is 100, hence I'd like 100RPM to equate to 5v, RPM to 0v, 50RPM to 2.5v. Ect (IE clear range from 0v - 5v)
Can someone please write the code for me to accomplish this on the Arduino UNO
I would like to Convert the Output from my Rotary Encoder into a proportion voltage output using the MCP4725.
Here's the Encoder I own: http://www.encoderonline.com/Data-Sheet ... ata-07.htm
Outout AB / 1,000ppr
I'm able to read the change in state on the serial with the code below.
I however need to be able to output a voltage range to correspond with the RPM the encoder is spinning at.
My Shaft's MAX RPM is 100, hence I'd like 100RPM to equate to 5v, RPM to 0v, 50RPM to 2.5v. Ect (IE clear range from 0v - 5v)
Can someone please write the code for me to accomplish this on the Arduino UNO
Code: Select all
/* Arduino Rotary Encoder Tutorial
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
*/
#define outputA 6
#define outputB 7
int counter = 0;
int aState;
int aLastState;
void setup() {
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
Serial.begin (9600);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
}
void loop() {
aState = 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){
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
counter ++;
} else {
counter --;
}
Serial.print("Position: ");
Serial.println(counter);
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}