I have written code to see values of a 5K potentiometer from 0 to 1023. Whenever I rotate the knob, the value should change from 0 to 1023. I have connected the potentiometer to the Arduino's pin A1, but there is a problem with readings. Whenever I am rotating the potentiometer's knob, the serial port is only showing 1023. Please help.
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A1);
Serial.println(sensorValue);
delay(500);
}
-
1Please show your actual wiring.Majenko– Majenko2017年08月28日 12:25:24 +00:00Commented Aug 28, 2017 at 12:25
2 Answers 2
It sounds like it might be a wiring problem. Check that you have the potentiometer connected correctly. Your circuit should look something like this:
single potentiometer circuit
-
I have checked connections there is no problem with them . i dont have an idea why its only showing 1023 value .i interchanged the voltage and gnd then it showed 0 in serial port.shweta S– shweta S2017年08月28日 07:39:28 +00:00Commented Aug 28, 2017 at 7:39
-
2@shwetashrama: If your wiring is correct (which I doubt), then your potentiometer is broken.Edgar Bonet– Edgar Bonet2017年08月28日 07:47:45 +00:00Commented Aug 28, 2017 at 7:47
-
is there any specification which one has to keep in mind while choosing a potentiometer like current rating etc.shweta S– shweta S2017年08月28日 09:34:36 +00:00Commented Aug 28, 2017 at 9:34
-
1@shwetashrama Not for applications like this. Try connecting a multi-meter across the terminals of the potentiometer to check the resistance, and verify that it changes as expected when you rotate the knob.sempaiscuba– sempaiscuba2017年08月28日 10:16:46 +00:00Commented Aug 28, 2017 at 10:16
-
i have checked resistance and voltage both ,there is no problem with themshweta S– shweta S2017年08月29日 08:44:21 +00:00Commented Aug 29, 2017 at 8:44
Disconnect the pot and take some readings. You should get some random values near zero. That would mean you're not connecting the leads right or the swinger is stuck at one end.