I have interfaced a 10k pot to Arduino Uno, one leg of the pot to ground and the other end to 5V. The wiper pin to A3. I have tried this code,
int analogPin = A3;
// variable to store the value read
float val = 0;
void setup() {
Serial.begin(9600); // setup serial
}
void loop() {
Serial.println(val); // read the input pin
val = analogRead(analogPin);
}
The serial monitor only displays values between 1010 to 1023? How do I get a full range? What is going wrong please help!!
I have attached the circuit connections too. The connection shows that I have connected wiper pin to A0. But I have tried both ways.
It's unlikely that the Arduino is defective and your code looks OK.
If you have a multimeter check the voltage at A3. If the pot is working you should read between zero and 5V, depending on the pot setting.
If you don't already have a multimeter, and if electronics is going to be your hobby, get one! If cost is an issue, a cheap meter is better than no meter. I'd say a multimeter is essential.
Meghh:
The serial monitor only displays values between 1010 to 1023? How do I get a full range?
A multimeter might be beneficial here.
It would allow you to measure the voltage of the wiper terminal, relative to ground voltage.
If the multimeter provides a voltage for the wiper terminal that you're satisfied with, then you can try taking some readings with the arduino after that.
Also --- with the pot completely disconnected from everything (not connected to arduino or any voltage source), you can even use the multimeter to see if the resistance between wiper terminal and one end of the pot is able to change (each time you change the wiper position). That will be a nice test with a multimeter too.
I hooked up your circuit and ran your code. Everything worked as expected: Turn the knob all the way ccw, and the result is a stream of 0.0. Turn it the other way and it's all 1023.0. In between it varies linearly with the angle of turn. As expected.
Something is causing A3 (or A0 as shown in your diagram) to read only a noisy high. There could be many reasons for this, but in general it means that your analogPin (A0 or A3?) is connected to Vcc somewhere, apparently through some resistance. If it were directly connected, it would read a solid 1023.
Look at the connection, and the back of the board. Is there dirt, dust or other substance bridging the connections between the analog pin and any source of voltage? Surprisingly hair based dust is quite conductive - same for grease or anything that can carry moisture. Scrub the pot back and forth a few times. Use some canned air and blow at any openings in the device. Swap it for an identical part. Does that fix it? If so, yeah, that was the problem.
If not, remove the pot and connect the wiper and either end to an ohm-meter. Read the ohms as you sweep the pot from one end to the other. Does it change from 0 to 10K smoothly? If not, that may be your problem. Check all the leads to the pot. You may not be correctly identifying the wiper (sometimes the manufacturers are tricky.) Does that solve the problem, if not, try a different pot.
If none of that solves your problem, test the pins by directly shorting it to ground with a jumper between A3 (or A0?) and GND) and read it with Serial.println(analogRead(analogPin)); . Then short it to Vcc. It should read 0 in the former, and 1023 in the latter circuit. Does it? If not, your Arduino (a clone, right?) has a hardware problem. If so, send it back for a replacement.
If not, well, I'm out of ideas. Come back and let us know what you have discovered.
I see you are a first time poster. Hopefully you will realize notifications are broken, and come back to see all the useful advice you have gotten so far. But without you, we can't go much further than speculating about the cause of your problem.