Poti value problems with ultrasonic sensor

Hey Guys,

hope you can help me out. I run a ultrasonic sensor mit the arduino uno and control the distance of the sensor with a poti. and send the distance as a MIDI Signal to my pc into Max/Msp.
everything works fine.

then i bought a second poti to adjust the MIDI channel with it. you turn the poti and the MIDI channel is switching.
but i found out on the serial monitor that the value of the poti is jumping even if i dont touch the poti.
so the problem is that the value jumps and so does the MIDI channel -.-

i guess there could be 3 reasons.

  1. the poti isnt good or broken.
  2. something in my code is wrong
  3. i'm not able to put 3 things into the 5V on the Arduino Uno Board.

I have my 2 potis and the MIDI out jack pluged into the 5V of the Arduino Board. Is this too much ?
is there something i just dont get?

Here the part of my code

................
if(realTime>potiDist)
{
int sensorValue = analogRead(A1);

if( (sensorValue >= 0) && (sensorValue < 129) )
{

velocityOn(144,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}else if( (sensorValue > 128) && (sensorValue < 257) )
{

velocityOn(145,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}else if( (sensorValue > 256) && (sensorValue < 385) )
{

velocityOn(146,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}else if( (sensorValue > 384) && (sensorValue < 513) )
{

velocityOn(147,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}else if( (sensorValue > 512) && (sensorValue < 641) )
{

velocityOn(148,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}else if( (sensorValue > 640) && (sensorValue < 769) )
{

velocityOn(149,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}else if( (sensorValue > 768) && (sensorValue < 897) )
{

velocityOn(150,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}else if( (sensorValue > 896) && (sensorValue <= 1023) )
{

velocityOn(151,1,0);
pitchBendOn(224,0,0);
analogWrite(LEDPin,0);

}
}
else
{

int sensorValue = analogRead(A1);

if( (sensorValue >= 0) && (sensorValue < 129) )
{

analogWrite(LEDPin,80);
velocityOn(144,1,sendVal);
pitchBendOn(224,0,sendVal);

}else if( (sensorValue > 128) && (sensorValue < 257) )
{

analogWrite(LEDPin,80);
velocityOn(145,1,sendVal);
pitchBendOn(224,0,sendVal);

}else if( (sensorValue > 256) && (sensorValue < 385) )
{

analogWrite(LEDPin,80);
velocityOn(146,1,sendVal);
pitchBendOn(224,0,sendVal);

}else if( (sensorValue > 384) && (sensorValue < 513) )
{

analogWrite(LEDPin,80);
velocityOn(147,1,sendVal);
pitchBendOn(224,0,sendVal);

}else if( (sensorValue > 512) && (sensorValue < 641) )
{

analogWrite(LEDPin,80);
velocityOn(148,1,sendVal);
pitchBendOn(224,0,sendVal);

}else if( (sensorValue > 640) && (sensorValue < 769) )
{

analogWrite(LEDPin,80);
velocityOn(149,1,sendVal);
pitchBendOn(224,0,sendVal);

}else if( (sensorValue > 768) && (sensorValue < 897) )
{

analogWrite(LEDPin,80);
velocityOn(150,1,sendVal);
pitchBendOn(224,0,sendVal);

}else if( (sensorValue > 896) && (sensorValue <= 1023) )
{

analogWrite(LEDPin,80);
velocityOn(151,1,sendVal);
pitchBendOn(224,0,sendVal);

}
}
lastTime=realTime;
newVal=0;
}
}
...............

Hope someone could help me :slight_smile:
greetings from Austria

Timo

Does "poti" mean potentiometer? If so what values are you using? The Arduino adc works better if the value is 10k or less.

Your code snippet is too long for me to be able to relate it to your description of the problem.

I would write a short sketch that just reads the values of the potentiometer and displays them on the serial monitor so you can see what is happening. If there is just a small amount of uncertainty you could make a few readings and take an average.

You haven't provided enough information to form a view about whether you are overloading the 5v pin.

...R