I can't get the a 10K potentiometer to work

I am trying to make the fifth project “Mood Cue” presented in the projects book. I noticed all three potentiometers are returning 1023 no matter how I turn them. I made a circuit to test them alone and wrote some code printing their value.

Here’s the potentiometers data sheet: https://www.arduino.cc/documents/datasheets/Potentiometer.PDF

I changed the picture and code because the forum rules said i should isolate the problem before posting. So no more servo.

![|500x375](https://forum.arduino.cc/index.php?action=dlattach;topic=498660.0;attach=225002 :o)

int potentiometer;
void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  potentiometer = analogRead(A0);
  Serial.println();
  Serial.print("potentiometer: ");
  Serial.print(potentiometer);
  delay(30);
  }

|500x375

If that's a servo connected to the Arduino 5 volt line use and external supply instead.

Cannot see how the potentiometer is wired.

.

Always show us your current compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

.

"Cannot see how the potentiometer is wired." What's wrong with my picture? I thought It was pretty clear? Should I post a better one?

MateoVanDamme: "Cannot see how the potentiometer is wired." What's wrong with my picture? I thought It was pretty clear? Should I post a better one?

A schematic would be better than a picture of a breadboard. That way you could label which pins are which and you wouldn't have the ambiguous wires going out of the picture and coming back in. Just draw it out on a piece of paper and take a pic of that.

You should also post your code. Not a link to what you copied, but the actual code you actually have in your actual IDE to load onto your actual board. Perhaps you made a mistake somewhere.

Done. Added both to original post. Posted code and added nice sketch from the projects book. Also ambiguous wires? There's a red one and a black one going of the screen and a red one and a black one coming back in.

MateoVanDamme: There's a red one and a black one going of the screen and a red one and a black one coming back in.

Yes and that creates a potential ambiguity. Are those the same wires? Probably, but I don't want to waste my time trying to help debug something if it might turn out later that it isn't wired the way I thought. Additionally, the particular pin that wire from the pot is plugged into can't be seen in the picture. It looks all dark on that side and is impossible to tell.

You still have an issue of the servo being powered off the Arduino. That alone can cause issues. I know it probably says to do that in whatever crappy book you got. There are tons of crappy Arduino books out there with stupid things like that in them. I don't know if they're written by people who just don't know or just don't care. There are even pages on this site with stupidity like that. I wish people would take some time to edit these things.

understandable. Any idea why it's not working? I added a nice sketch and my code.

The OP’s code posted the right way by someone who actually took the time to read the forum rules.

/*
  Arduino Starter Kit example
  Project 5 - Servo Mood Indicator

  This sketch is written to accompany Project 5 in the Arduino Starter Kit

  Parts required:
  - servo motor
  - 10 kilohm potentiometer
  - two 100 uF electrolytic capacitors

  created 13 Sep 2012
  by Scott Fitzgerald

  http://www.arduino.cc/starterKit

  This example code is part of the public domain.
*/

// include the Servo library
#include <Servo.h>

Servo myServo;  // create a servo object

int const potPin = A0; // analog pin used to connect the potentiometer
int potVal;  // variable to read the value from the analog pin
int angle;   // variable to hold the angle for the servo motor

void setup() {
  myServo.attach(9); // attaches the servo on pin 9 to the servo object
  Serial.begin(9600); // open a serial connection to your computer
}

void loop() {
  potVal = analogRead(potPin); // read the value of the potentiometer
  // print out the value to the Serial Monitor
  Serial.print("potVal: ");
  Serial.print(potVal);

  // scale the numbers from the pot
  angle = map(potVal, 0, 1023, 0, 179);

  // print out the angle for the servo motor
  Serial.print(", angle: ");
  Serial.println(angle);

  // set the servo position
  myServo.write(angle);

  // wait for the servo to get there
  delay(15);
}

MateoVanDamme: understandable. Any idea why it's not working? I added a nice sketch and my code.

Take the servo out and see if it will print good numbers then.

Take a multimeter and make sure the pins on the pot are what you think they are.

Problem with the picture is we can't see the bottom of the pot or which row the third terminal is connected to, appears to be row 9 but ...

No and don't have one. I did use a led to test it and the component does work. Just not as I would have expected. Also sorry for not reading the rules. Next time I'll make sure everything's perfect.

A couple of observations. There's 3 pins on the component and I tested the pins resistance to each other with a led and the 5 V supply from the arduino. pin 1: power, pin 2: output and pin 3: ground

Between pin 1 and 3 no connection what so ever. No matter what I try.

Between 1 and 2: It actually works. LED Dims and brightens when I turn the knob. However when I remove the LED and hook it up to the analog port A0 it just shorts and spams 1013 on my monitor.

Between 1 and 3: Nothing at all.

Conclusion: No idea. The pins don't work as I expected them too. Maybe there is one power pin, one output pin and one that is there for soldering? Like this: pin 1: power, pin 2: output and pin 3: nothing. In the book it said that a potentiometer is a "voltage divider". This appears to be just a linear variable resistor with an extra confusing metal pin.

I tried hooking up the LED and the wire to A0 at the same time and now everything works except it goes between 1023 and 384 because the LED keeps consuming some power.

Wait I bought the arduino basic kit from this site, "crappy book" included. You would think the creators of the product know how their product works. And guys the servo isn't a problem. I've tested it separately and it works like a charm. As soon as I noticed the potentiometer was the problem I disconnected it and tried to solve that issue.

MateoVanDamme: Next time I'll make sure everything's perfect.

It's not so much about achieving perfection and more about being the kind of person who reads the instructions first. That is easily the most important skill you can have in this hobby. 99% of the questions on this board would never have needed to be asked had the poster bothered to read the data-sheet for the part they have.

Have you looked at the data-sheet for the pot you have? It would make it clear which pin does what and you wouldn't have to guess.

MateoVanDamme: Wait I bought the arduino basic kit from this site, "crappy book" included. You would think the creators of the product know how their product works. And guys the servo isn't a problem. I've tested it separately and it works like a charm. As soon as I noticed the potentiometer was the problem I disconnected it and tried to solve that issue.

the "creators" didn't write the book or this website and have never been seen here. Here there are just a bunch of hobbyists trying to disavow people of the things they learn in those crappy books.

int const potPin = A0; ? Always use const int, but it seems the compiler accepts that (turning blue). Leo..

Actually, the rule with const is that it always binds to the thing on its left. The only exception is when you write the const first on the line so it has to go with something on its right. But technically speaking the way it is here would be the more correct (although less common) way to write it.

Take the pot out of the equation by connecting a wire between A0 and the 3.3volt pin. You should see an A/D value of ~685. And the servo should move to ~120 degrees. Leo..

P.S. Buy a set of male/male Dupond wires.

It may be me but there seems to be a third wire missing. Or a resistor to form a voltage divider with this pot. Or an INPUT_PULLUP for the same effect (though with the pot connected to +5 that wouldn’t have any effect either).

On the picture I see one wire go from what seems to be the +5 to the pot, and one wire from the pot to A1. Then you provide 5V to the A1, regardless of the actual resistance, and you see a reading of 1023 at all times.

Connect the slider to A1, one end of the pot to 5V and the other end to GND and you should get the desired result.

I was just writing the same thing.

In short...where is the connection between the 3rd pin on potentiometer and ground. The diagram you posted shows it should be there but I can't see it in any of the pretty pictures and without it 1023 is exactly what you'd expect.

Steve