Automatic timer Code

Hello. Can you help me build a code that automatically start a timer when LDR cannot detect a light?

Hello helpc

Welcome to the worldbest forum.

Yes, for shure.

We need some additional information.
Post your sketch, well formated, with well-tempered comments and in so called code tags "< code >" and a detailed circuit diagram to see how we can help.
Have a nice day and enjoy coding in C++.

Thanks

This is a nice project to get started.

Keep it simple and stupid firstly.

Either follow the example code that comes with the library
or
run some tutorials for the hardware selected.

If you are happy with the results of the tutorials you can merge these to your project.

  • connect the pins common to the transistor and LED to a pin on the Arduino configured as an INPUT.
  • write code in loop using digitalRead() to read the pin state
  • detect when the pin state changes (stateLst != state)
  • when it becomes LOW, capture a timestamp (msecLst = millis())
  • when it becomes HIGH, compute the difference between the current and captured time and report (Serial.print())

You could connect the ground of your circuit to the ground of the Arduino, then

wire an analog input on the Arduino to the junction of R2 and R3 in your circuit and

use analogRead() to see what values come from what levels of light.

Start wherever you need to with the examples on offer in the IDE for anything more elaborate.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.