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.

Displaying AVR ADC value in LUX on the LCD

Status
Not open for further replies.
No, I haven't. I've never add both of them. Do I need to only type it or change some setting? This is in codevision

But I just try to calculate it manually and think about a mistake in the equation, since the result is very very small

Code:
lux = 10000/(pow((a2*[COLOR="#0000CD"]10000[/COLOR]),x)); // using this I got 0.0000

lux = 10000/(pow((a2*[COLOR="#0000FF"]10[/COLOR]),x));  // using this I got display, but it is very very small, like 0.0058

I just wondering that a2 is still in k.Ohm right? (from the previous equation)
 

sorry, I got carried away and started replying for avrgcc.
After entering several threads I got confused so ignore the gcc advices.

Maybe you need to enable some option in the codevision compiler.

- - - Updated - - -

why kohm since all the resistance are entered in ohm and voltages in V?
 

No problem, I learn GCC too, the principles are still the same right.

I think the compiler already linked them together since I already got display when I edit the equation.

why kohm since all the resistance are entered in ohm and voltages in V?

Because somebody helped me to derive the equation from LDR datasheet (graph) and it is in k.Ohm. You may want to check this: https://www.edaboard.com/threads/278855/
 

Yes manual calculation gives 21.54, but when I change a1 = 511;

I got 0.0021
This is very small lux and it should be around 21.54 right?
I'm sure there is mistake in the equation (code).


Next, since this is lux, I think I may not include the decimal and I will take the integer part only
 
Last edited:

I have assumed that E[lux] = 10000 / (R[kΩ]*10)^(4/3) is correct.
When the ADC reading gives 511 it means that it measures about 2.5v so te resistance equals the reference resistance which is 10K

E[lux] = 10000 / (10kΩ]*10)^(4/3)= 10000 / (100)^(1.3333) = 10000/464.08 = 21.547

Did you get 0.0021 after the conversion of a2 to kohm ?
Seems to be off by 10000

- - - Updated - - -

LDR= (10230000/ADC) - 10000

This part is correct , LDR= (10230000/511) - 10000 = 10019

- - - Updated - - -

I think the result is messed up somewhere but it doesn't seem to be the equations so it is either an overflow or the compiler does something with the pow function.
 

Now I use this code and get 21 (I need only the integer part, just ignore the fractional part)

Code:
a1 = 511;
        a2 = (10230/a1) - 10;           // [COLOR="#FF0000"]I divided it by 1000[/COLOR]
        x = 4.0/3.0;     
        m1 = 10000/(pow((a2*10),x));    
        lux = m1;                       
        
        lcd_gotoxy(0,0);
        sprintf(str,"L1:%u\n", lux);
        lcd_puts(str);


The other problem comes when I change it back to a1=read_adc(0);
The display is like this: (proteus)
*When I increase the ADC it shows => 1-2 - 4 - 11 - ... - 73 - 464 - 65535
*When I decrease the ADC it shows => 65535 - 46435 - 73435 - ... - 11435 - 41435 - 21435 - 11435
 

*When I increase the ADC it shows => 1-2 - 4 - 11 - ... - 73 - 464 - 65535

Are the values of a1 correct ? (1-1023)

So you mean that lux takes values higher that 65535 , doesn't make much sense but you can make m1 and lux an unsigned long and use
Code:
sprintf(str,"L1:%lu\n", lux);
lu is for long unsigned
 

Yes a1 must be correct!

O o, it displays 'u'

I dont know why lux is getting too long. Yes it doesnt make sense. When ADC is 1022, it will be 221325 lux. I think lux dont need to be that big. Maybe I should use a lux meter for comparing, not using the LDR graph.
 
Last edited:

Hello, Ardy sorry for such a late reply i am sure you have done your work. If not, then yes you need to compare your LDR value with some LUX METER thatz what we call calibrating.

Remember that The LDR you use for your project might be different from the datasheet you are using... thatz one reason you will all-ways face this inequality problems. So best way is to borrow some LUX meter from your friend or any one you know and follow the calibrating method. Best of luck, if you need any further help PM me :) . bye
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top