Hi,
I am making a school project until the 14th, but i am new with programming.
A photoresistor controlls the leds. If i place my hand over the photoresistor, led2 goes on.
If I cover it, but then remove my hand, led1 goes on.
PLEASE HELP ME!
task:
1.read the photoresistor
2.wait 0,5 seconds
3.read the photoresistor again
a)if the light that reaches the photoresistor is interrupted for a short time, set led1 high;delay(1000);set led1 low
b)if the light that reaches the photoresistor is interrupted for a long time, set led2 high;delay(1000);set led2 low
=>that means: a)if i move my hand once over it, set led 1 high
b)if i cover it, set led 2 high
I need a programm that looks like this:
int photoIn = 1;
int led1 = 11;
int led2 = 12;
int setPoint = 350;
Yes, probably it would not work.
I just try to give a tips, not a programm. The tips are you have a deal with timing,
and should use a time checking subroutine, like millis();
I think in my example there is a timing issue, as it overwrite newvalue any cycle.
And photoresistors are slow devices, so value from the sensor couldn't change fast enough.
Put a delay(500), after last line, it will slow the speed.
Try using this format:
if(x<y) {
type your code here;
}
There is a lesson on photoresistors in the learning section on this website. You may need a voltage divider as a reference for analog input.