Offline
Full Member
Karma: 0
Posts: 122
We were born naked, wet and hungry. And then things get worse!!!
|
 |
« on: March 05, 2012, 07:52:03 am » |
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
Edison Member
Karma: 24
Posts: 1475
Now, More Than Ever
|
 |
« Reply #1 on: March 05, 2012, 07:59:02 am » |
... adding LDR to the pin, doesnt change any values. Please elaborate (in re. "adding LDR to the pin").
|
|
|
|
|
Logged
|
Don't React -- Read!
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 296
Posts: 26010
Solder is electric glue
|
 |
« Reply #2 on: March 05, 2012, 08:01:06 am » |
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
Full Member
Karma: 0
Posts: 122
We were born naked, wet and hungry. And then things get worse!!!
|
 |
« Reply #3 on: March 05, 2012, 08:29:07 am » |
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)
Online
Brattain Member
Karma: 296
Posts: 26010
Solder is electric glue
|
 |
« Reply #4 on: March 05, 2012, 08:30:37 am » |
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
Full Member
Karma: 0
Posts: 122
We were born naked, wet and hungry. And then things get worse!!!
|
 |
« Reply #5 on: March 05, 2012, 08:33:58 am » |
Got it.. Thnx..
But y is the analog pin reading values , when it has no input to it?
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 296
Posts: 26010
Solder is electric glue
|
 |
« Reply #6 on: March 05, 2012, 08:40:24 am » |
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
Full Member
Karma: 0
Posts: 122
We were born naked, wet and hungry. And then things get worse!!!
|
 |
« Reply #7 on: March 09, 2012, 02:29:59 am » |
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)
Online
Brattain Member
Karma: 296
Posts: 26010
Solder is electric glue
|
 |
« Reply #8 on: March 09, 2012, 03:37:48 am » |
Is this rite? Yes what's more is it is even right. 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 122
We were born naked, wet and hungry. And then things get worse!!!
|
 |
« Reply #9 on: March 14, 2012, 07:46:39 pm » |
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)
Online
Brattain Member
Karma: 296
Posts: 26010
Solder is electric glue
|
 |
« Reply #10 on: March 14, 2012, 11:37:52 pm » |
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
|
|
|
|
|
|