HELP for project

So Im working on a project for uni and am really stuck.

The idea is, using an LDR, every time it senses the light has gone down, it will add 1, and then every time it goes down again it will add another 1.

However I can not figure out how to make it add an additional 1 each time it sense it.

If anyone gets what i'm saying and knows how to do it, please help.

Thanks :slight_smile:

Post the code you have tried and we may be able to help.

...R

To add one to a counter you use the ++ operator.

count++;

Will add one to a variable called count.

You need a "state machine" to count when It goes off then on again.

Initialise ldrOnflag as false

If ldr is low and ldrOnflag is false // LDR lit
ldrOnflag = true

If LDR is high and ldrOnflag is true // LDR dark
Count ++
ldrOnflag = false

Weedpharma

HSGD1:
The idea is, using an LDR, every time it senses the light has gone down, it will add 1, and then every time it goes down again it will add another 1.

Can you be more specific about "goes down"?

Is that every step less of the 1024 'analog' steps? If so, don't bother adding 1, value = 1023 - reading.

Or is that every time there is a decrease that halts for some minimum time? And then the next, etc.

LDR is slow compared to a phototransistor. The latter costs more but shop a bit and get a bunch for $1.

weedpharma:
You need a "state machine" to count when It goes off then on again.

No you don't. You just need to detect the state change.
But as the OP is at University the whole tone of this question is very suspect.