Potentiometer hitting max value before it should

I'm building a custom MIDI controller box with 6 faders/potentiometers for a client... Here's my simple code for a 10k ohm linear potentiometer:

 int cc = 0;

void setup() {

void loop() {
  int sensorValue = analogRead(A0);
  cc = sensorValue / 8;

So with MIDI CC values it goes from 0 to 127 However, viewing the serial monitor, the potentiometer reaches it's max value (127) before it should (see pic):


Am I doing something wrong here? Is there a math problem?

This might be of help.....


Linear or log potentiometers? Are you sure the pot isn't connected to a higher voltage than the Arduino? The calculation looks fine but put in a print of sensorValue too so you know exactly what you're dealing with.


Actually, it was a voltage problem...Thanks Steve! I just swapped out the voltage pin to 3.3v and now it's good.

int sensorValue = analogRead(A0); cc = sensorValue / 8;

Why not direct, without the intermediate sensorValue.

byte cc = analogRead(A0) >> 3;

bitshift 3 is the same as divide by 2 three times Leo..