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
Help On Project. Using the LDR on the DEV Board PIC16F88
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
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.
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
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel