Hi, I have connected a 1k potentiometer to the arduino using A0 port.
I need to get clear values from 0-100 and these values should not change if I do not turn the knob, however the potentiometer shows +-60 values without me touching the knob.
What can I do? I need it to be precise to control volume.
Thanks a lot.
Show code (in code tags)
Show schematic.
Show results.
TheMemberFormerlyKnownAsAWOL:
Show code (in code tags)
Show schematic.
Show results.
Code: Serial.println(AnalogRead(A0))
Shematics: simple potentiometer: vcc, ground, A0
Results: When I do not rotate the knob the values jump. I can move it to 430 and leave the knob and the values will jump from 350-500 sometimes even higher.
What I am asking is which component should I use to get clear values without getting any noice
What components are used to control audio
Your code doesn’t compile for a number of reasons.
I can’t see your schematic.
Please try harder.
What I am asking is which component should I use to get clear values without getting any noice
Sounds like you have a faulty pot.
You will never get a steady reading from an A/D due to the way they work, but you can get a +/- 1 least significant bit repeatability.
You want to quantify the potentiometer, learn about hysteresis, a core scientific concept!
You pot may indeed be at fault, or dirty. You’ll still need a bit of the old hysteresis to get 100 levels that are stable.
@6v6gt lays it out, see this thread for a start.
https://forum.arduino.cc/?topic=695917#msg4678500
edit: the tutorial here: https://forum.arduino.cc/index.php?topic=526806.0
HTH and a tip of the hat to 6v6gt
a7
You didn’t say which Arduino.
Jumping values could be connection/wiring/breadboard/pot problems.
Post a picture of the setup.
Try this sketch (after you have fixed the problems).
Leo…
// converts the position of a 10k lin(B) pot to 0-100%
// pot connected to A0, 5volt and ground
int rawValue;
int oldValue;
byte potPercentage;
byte oldPercentage;
void setup() {
Serial.begin(9600);
}
void loop() {
rawValue = analogRead(A0);
// ignore bad hop-on region of a pot by removing 8 values at both extremes
rawValue = constrain(rawValue, 8, 1015);
// add some deadband
if (rawValue < (oldValue - 4) || rawValue > (oldValue + 4)) {
oldValue = rawValue;
// convert to percentage
potPercentage = map(oldValue, 8, 1008, 0, 100);
// Only print if %value changes
if (oldPercentage != potPercentage) {
Serial.print("Pot percentage is: ");
Serial.print(potPercentage);
Serial.println(" %");
oldPercentage = potPercentage;
}
}
}
Thank you all for the elaborate response.
I am kind of new to Arduino and I am very happy to see such supportive community.
I'll try the things you sent and give you an update once done.
Thank you all!!!