Analog pin has a constant value

I was trying to get the values of a LDR and I noticed that the analog pin in the arduino has a default value in it.

int analogInPin = A0;
int sensorValue = 0;

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

void loop() {
sensorValue = analogRead(analogInPin);
Serial.print("\t \n sensor = " );
Serial.print(sensorValue);

delay(1000);
}

Even without any connection, I get the values around 250-300. adding LDR to the pin, doesnt change any values. However, when I try to gnd the analog pin or, when i try to connect it to Vin, I get the values 0 and 1023 respectively. Cld someone please suggest.
Thankyou.

FelixFelicis:
... adding LDR to the pin, doesnt change any values.

Please elaborate (in re. "adding LDR to the pin").

I get the values around 250-300. adding LDR to the pin, doesnt change any values

You need to connect the LDR between the analog input and ground. Then you need a resistor 10K or so from the same analog input to +5V.

1 end of the ldr is connected to the A0, and the other end to the ground. Both with and without this ldr connection, the analog pin reads the value of 250-350

I will try to connect the 10k resistor from the same pin to gnd. Could you please let me know y is that needed?

It is needed to convert the change in resistance of the sensor into a change in voltage that can be measured.
The analogue input can only measure voltages not resistances.

Got it.. Thnx..

But y is the analog pin reading values , when it has no input to it?

Because the input is floating and picking up interference that is giving you a value, it is how electronics works and applies to digital inputs as well.

http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Grumpy_Mike:
It is needed to convert the change in resistance of the sensor into a change in voltage that can be measured.
The analogue input can only measure voltages not resistances.

Hi,

Sorry for the late reply. I was doing some research on it, and I just understood the concept of a pull up, pull down resistor. So basically my setup should be like a pull up resistor, having the LDR as a switch. one end of the LDR and the Resistor should be connected to the analog Pin. Is this rite?

(Btwn.. thnx for the link... Its really usefull)

Is this rite?

Yes what's more is it is even right. :slight_smile:

1 Last Question regarding this..

I have 6 ldrs which works with 6 pull up resistors. Is it ok, if I give the the same supply to all these 6 (Analog pins will be different though).. This will work!!

(I know this will work.. Not ready to spoil my board!! Just double chking)

Is it ok, if I give the the same supply to all these 6

If you mean is it OK to connect them to the same +5V and ground then yes, it is the only way to do it.