Analog input problems

I am having problems reading sensor values using the analog input pins. When reading values from a potentiometer the value easily goes up and down based on how I turn it. But when reading values from a flex sensor or photocell it stays around 1000. Is it a problem with the sensors? Or the board?

Jack

Pleas post your code and (more important in this case) the schematics.

How did you connect the photocell?

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

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(100);
}

Add resistor between analog input and ground, 10 - 100 k Ohm should be o'k, depends on lighting environment.

A quick note for those who will benefit, about WHY Magician's answer is the answer....

a) For our purposes, if "things" are as they should be, an analog input will pass very little current. Some, yes, as without current in them, electronic circuits (in this case the voltage sensors in the Arduino's analog input) don't do things. But very little current, in this case.

b) The concept of "voltage drop" is essential. The following represents a circuit with three resistors connected across a source of 5v and a "zero volts" (i.e. "Ground") point. The first resistor is a 15k resistor, the second 10k, the third 25k...

FIVE----R15k----R10k----R25k----GROUND

When you measure voltages, you put the two wires (leads) from the meter on two points in the circuit. Very little current flows through the voltmeter.

If you connect one of the voltmeter leads on "ground", and test at different points in the above, you will see...

Voltage reading/ position of other lead...

5v Between "FIVE" and R20k
3.5v Between R15k and R10k
2.5v Between R10k and R25k

Bear with me...

And this is what you would see if you put the two test leads either side of each resistor....

1.5v (measuring across R15k)
1v (measureing across R10k)
2.5v (measuring across R25k)

Those three... 1.5, 1, 2.5, are the VOLTAGE DROPS across the three resistors.

With a few things wired simply (in series), as above, the total voltage drop across them all will be the same as the total of the individual voltage drops. The amount of voltage drop over each segement will depend on the segment's resistance. Big resistance, big drop.

So what does this have to do with why the photocell wiring needed the resistor?

In the original circuit....

FIVE ---- PHOTOCELL ---- AnalogInput

... there was (effectively) no place for the electricity to go, "nothing" happened.

With....

FIVE ---- PHOTOCELL ---- RESISTOR ---- GROUND

... we created a path for the electricity. Along it there are two "resistors". The photocell's resistance goes up and down. The simple resistor's resistance stays the same. The total voltage drop will always be 5v, but the amount dropped across the photocell and the amount across the simple resistor will change.

The analog input is like a voltmeter connected between ground and the point between the photocell and the resistor. It will "see" different voltages when the resistance of the photocell changes.

====
For an Arduino program using an analog input in a simple way, see....

In that, the analog input is "fed" differently, but the program would respond to a photocell+resistor circuit just as well as it responds to the distance sensing module.

very well explained!

Thanks to Magician for the answer and to tkbyd for the explanation. It worked!

Jack