Pages: [1]   Go Down
Author Topic: Analog pin has a constant value  (Read 952 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 134
We were born naked, wet and hungry. And then things get worse!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Faraday Member
**
Karma: 66
Posts: 2570
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 633
Posts: 34512
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 134
We were born naked, wet and hungry. And then things get worse!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 633
Posts: 34512
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 134
We were born naked, wet and hungry. And then things get worse!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Got it.. Thnx..

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 633
Posts: 34512
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 134
We were born naked, wet and hungry. And then things get worse!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 633
Posts: 34512
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is this rite?
Yes what's more is it is even right.  smiley
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 134
We were born naked, wet and hungry. And then things get worse!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 633
Posts: 34512
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Pages: [1]   Go Up
Jump to: