Im still new to setting up and using arduino and understanding how everything interacts, with that said,
I have an Arduino Uno R3 board and I have a rotational encoder wired to it along with an 16x2 lcd screen. The screen's function is to output the rpm of the motor.
At the moment when the board is powered by usb from a computer port the code is working correctly and displaying the rpm as i calculated it should but when the board is connected to power using the barrel jack the rpm on the screen increases without touching/switching anything else.
The code i have below is without the LCD screen code because its not messing up the code calculating rpm
Notes:
- Barrel Jack is 9V output
- Encoder PPR is 180
#define encoder0PinA 2
#define encoder0PinB 3
volatile unsigned int encoder0Pos = 0;
void setup()
{
pinMode(encoder0PinA, INPUT);
digitalWrite(encoder0PinA, HIGH); // turn on pull-up resistor
pinMode(encoder0PinB, INPUT);
digitalWrite(encoder0PinB, HIGH); // turn on pull-up resistor
attachInterrupt(0, doEncoder, RISING); // encoder pin on interrupt 0 - pin 2
Serial.begin (9600);
Serial.println("start"); // a personal quirk
}
void loop() {
encoder0Pos=0; // counts clicks per revolution on encoder
delay(1000); // delys the count one second
float rpm=encoder0Pos/(3); // claculates rpm
Serial.println(rpm); // displays rpm
}
void doEncoder()
{
encoder0Pos++;
}
The question i have is, with coding, do you have to accommodate the code with respect to the power source used to power the board or is there something else needed like a resistor ?


