Page 1 of 1
Help On Project. Using the LDR on the DEV Board PIC16F88
Posted: Thu Jun 14, 2007 11:47 pm
by Jody
I need to write a program to use the LDR On the Dev board to turn on 4 LED's. Dark-4 LEDs and the lighter it gets the less LEDs get turned on.
The LEDs act as valves.
HELP ASAP thanks.
Jody
PM me or email
andrevs@sbsa.com
Posted: Fri Jun 15, 2007 9:29 am
by Benj
Hello
All you need is an ADC sampling routine to sample AN0 which is connected to the LDR. This routine is fairly common so you should be able to pick up an example in the language you are using fairly easily. Also the datasheet for the PICmicro will point you in the right direction when writing the routine.
Then it is simply a case of taking the analogue value and creating setpoints to switch the LEDs on or off.
for example.
Code: Select all
if (ADC_val > setpoint1)
{
//Switch On LED
}
else
{
//Switch Off LED
}
LDR
Posted: Fri Jun 15, 2007 11:44 pm
by Jody
Thanx alot
But im new to this type of progamming, and i dont know how to even start!! So if u can, i need mor detailed help..
Will be Appreciated
Jody
Posted: Sat Dec 15, 2007 3:55 pm
by Legoman
Which Pic are you using?
I did something similar. It took the voltage from the LDR run that through an ADC, scaled the value to MIDI range(0-127), then displayed the value on the LED's.
I can send you a copy of the code if you'd like?
Posted: Wed Jan 09, 2008 12:40 pm
by Benj
Hello Jody
To start you would need an ADC to read the voltage of the LDR.
This is done by adding an ADC component to your program and attaching it to AN0 via the Component connection window.
Then using hardware macros call the ADC sample function and then read back the ADC result using the read as byte function. Place the returned result into a byte variable.
Then use a decision icon to see if the sample is over a certain threshold.
Eg. VAR1 > 100
Then if the sample held in Var1 is over 100 then the yes branch will be run. Otherwise the no branch will be run.