Hello to all,
I just been wondering what can be wrong with my program code, as my result is returning to zero though all my other variables are giving correct values.
See parts of my code :
Connect LDR with a 10 Kohms resistor as shown:
Vin: 5V*

\
0 LDR(16K  2M Ohms)
/


analog 2*

/
\
/ R1 (10K ohms)
\

*> Ground
*/
int moisture; // Analogical value obtained from the experiment
double PercentMoisture; // Varible to store % Percentage Soil Moisture Value
int val; // Variable for reading the pin status to compare with buttonState
int val2; // Variable to read the debounced status
int buttonState; // Variable to hold the last button state
int lcdMode = 0; // Variable to swap between LCD menu.
float RLDR; // Resistance calculation of potential divider with LDR
float Vout; // voltage ouput from potential divider to Anolg input
float Lux;
int Luminosity;
float LightSensorLDR (){
int ADC;
ADC = analogRead (LDR_input);
RLDR = (10000.0 * (5  Vout))/Vout; // Equation to calculate Resistance of LDR, [RLDR =(R1 (Vin  Vout))/ Vout]
// R1 = 10,000 Ohms , Vin = 5.0 Vdc.
Vout = (ADC * 0.0048828125); // Vout = Output voltage from potential Divider. [Vout = ADC * (Vin / 1024)]
Lux = (500 / RLDR);
return Lux;
}
[code\]
These are some results im getting from serial monitor (Room with light ON at Night) :
LUX = 0 ADC = 63 Res LDR 0.00 Vout0.31
LUX = 0 ADC = 63 Res LDR 152539.68 Vout0.31
LUX = 0 ADC = 64 Res LDR 152539.68 Vout0.31
LUX = 0 ADC = 63 Res LDR 150000.00 Vout0.31
LUX = 0 ADC = 63 Res LDR 152539.68 Vout0.31
LUX = 0 ADC = 63 Res LDR 152539.68 Vout0.31
LUX = 0 ADC = 63 Res LDR 152539.68 Vout0.31
LUX = 0 ADC = 64 Res LDR 152539.68 Vout0.31
LUX = 0 ADC = 64 Res LDR 150000.00 Vout0.31
LUX = 0 ADC = 63 Res LDR 150000.00 Vout0.31
LUX = 0 ADC = 62 Res LDR 152539.68 Vout0.30
Any comments will be welcome if some kind of improvements can be achieved in terms of a more precise equation in converting to Lux.
Thanks
Regards
taz ..