Problem using Potentiometer as analog dimmer

Hello,

I’m a fairly experienced novice with Arduino and have worked through the kit book and thought I had a decent handle on it, but I’m having an issue with a simple program (Sketch below). I’ve got my pot wired up as a an analog input but the analog pin doesn’t seem to be reading it. When I read the values on the pin using Serial.print it always returns “19” no matter the position of the dial on the pot. In fact, even when I unplug my pot from the bread board Serial.print still says the value on the A5 pin is “19”. I got similar results on Analog Pin 0.
Are my Analog input pins broken?!

Just FYI, The circuit works when I wire the lights to power and ground, and when I just put “digitalWrite(lightPin, 255);” in the loop function.

// simple pot controlled pwm lighting

const int dialPin = A5;
const int lightPin = 9;
int lightVal = 0;
int lightDialVal = 0;

void setup(){
  pinMode(lightPin, OUTPUT);
  pinMode(dialPin, INPUT);
  Serial.begin(9600);
}

void loop(){  
  lightDialVal = analogRead(dialPin);
  delay(5);
  
  Serial.println(dialPin);
    
  lightVal = lightDialVal/4;
  
  analogWrite(lightPin, lightVal);
  //digitalWrite(lightPin, 255);
}

You are printing the pin number and not the value read from it!

Right you are, Stowite! Thanks. However, I'm not out of the woods yet. I changed the code to print the lightVal on the line after I define lightVal = lightDialVal/4; Now I'm getting a serial print of "0".

Then you have either 1) wired it up wrong 2) have a faulty pot 3) have a faulty input pin. - try another pin

Measure the voltage on the processor pin and se if it changes with turning.

Grrr! I wired the pot wrong! I had double and triple checked, it, but... oh well. Thanks for the suggestion, Grumpy_Mike.

I have started to use Gray Code rotary switches as input rather than potentiometers. The only real downside is that they require two input pins rather than just one.

stowite:
I have started to use Gray Code rotary switches as input rather than potentiometers. The only real downside is that they require two input pins rather than just one.

They’re more commonly known as “quadrature encoders” - a true Gray code encoder would need as many pins as there are in the code.
The other very real downside, when compared to pots, is that they don’t “remember” their last position.

AWOL: The other very real downside, when compared to pots, is that they don't "remember" their last position.

I put the last position in EEPROM.

AWOL:

stowite: I have started to use Gray Code rotary switches as input rather than potentiometers. The only real downside is that they require two input pins rather than just one.

They're more commonly known as "quadrature encoders" - a true Gray code encoder would need as many pins as there are in the code.

(Digital) quadrature is a 2-bit Gray code, so it has 2 pins! An absolute Gray code encoder would have more bits, which is what you mean by "true Gray code encoder" I think.

stowite:

AWOL: The other very real downside, when compared to pots, is that they don't "remember" their last position.

I put the last position in EEPROM.

So long as you don't forget the 100,000 times write limit on any one EEPROM memory location or else it forgets.