Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] LDR and LM35 formuales

Status
Not open for further replies.

KhaledOsmani

Full Member level 6
Joined
May 4, 2014
Messages
384
Helped
1
Reputation
2
Reaction score
1
Trophy points
18
Activity points
3,933
I had connected an LDR to a PIC micro-controller.
It is running good, and I also made an ADC, so that the analog value of the input of the LDR (voltage) is translated into decimal values, and shown on the LCD.

My question is: Is there any formula to regulate the output of this component decimally?

i.e: when in full dark, the output must be shown as "0 lux" but it shows "7 lux" perhaps the value saved in the reserved byte must me subtracted from 7?

When in full light (glowing the LED of the iphone onto it) it says "1023 lux" which means 5V in analog which is maximum, which is logic.

What must be done to make it 100% accurate?


As for the LM35, there is for sure, a formulae so that after the ADC, the output (decimal value of the pre-saved byte in the file register) must have be mathematically operated, such as divided by two, or subtracted by ten, or both.
Can any body give me this formula? (note it is not posted in both of sensors datasheets)
 

Do you only want to change the full darkness reading?

Will you be using different LDRs?
 

In normal room lightening it was giving me 9 to 16 lux
Is that accurate?
Can only the full darkness level be changed?
 

Hi,

1023 represents the max adc value,
Mind that a 200% overload will also show 1023.

So attenuate the sensors signal that it represnts less than 1023 with 100% of light. 1000 maybe is a good selection, then you only need a decimalpoint and your display shows 100.0%.

First compensate for the dark light to 0 ( subtract 7).
Then adjust for 1000 with full light.
Then check if 0 is still correct.

The "7" is called offset and is corrected first by adding/subtracting.
The full adjust is called gain adjust and is done by multiplying/deviding the signal.

Both correctios can be done with the analog signal or with the digital signal by software.
By software is the useful way because it can be initiated by -maybe- pressing two key at the same time for period of 3 seconds.
Software is so flexible ....


Hope this helps
Klaus





Klaus
 
Klaus,
Your explanations were fantastic!

This 7 lux out of nowhere in complete darkness is an offset then.
I will subtract 7.
But the ADC value of this sensor, is only stored in one variable. Assume save in a register labeled X.
X = X - 7.
X is the decimal value converted from the analog value of the voltage, obtained by presence/Absence of light.
I can subtract 7 from it, so at complete darkness, (when LDR is all covered up) so on the LCD, it would show 0 lux or 0.00%
but at full or complete light, it would show 1023 - 7 = 1016. I cannot manipulate it from more than one side. It is a mathematical relation, which can be set once. Did you get my point?

How to manage that, or this is the final solution, and it is acceptable?

Also in a normal room, where CFL lights are used, what is the normal, hence acceptable values of lux? (logical value for regular lightning)
 

Hi,

for sure you loose the 7 LSB of resolution....

Mind: With i ADC reading of 1023 i´d show "overload"

*****

but multiply the result of 1016 * 0.9843, then you get the result of 1000 or 100.0%

So how to multiply with 0.9843:
Multiply the value with 65536 and get 64504.

Now form a 16bit x 16 bit unsigned integer multiplication. (1016 x 64504)
The result is 32 bit wide. (65536064)
Take the upper 16bit of the result and get 1000.
Here it is.

Good luck
Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top