timer or counter

Hello everybody,

I’m new in Arduino and try to find my way thought programming.


I want to measure how many seconds (milli) a car is driving between point 1 and point 2 (points are laserbeams and a LDR-S When the LDR output of point 1 shows a number <200 then a stopwatch has to start shown the stopwatch starttime on a lcd i2c (on row 1). When the car drives thought point 2 (also a laserbeam and a LDR) the stopwatch time has to stop.

Who knows how to programm this or is there somewhere a written code. I found some codes but the have to many parameters


Image from Original Post so we don’t have to download it. See this Image Guide



When the car passes point 1 (LDR1 output < 200) save the time from millis().
When the car passes point 2 (LDR2 output < 200) save the time from millis().

Now you can calculate the elapsed time between the start and end time in milliseconds and display it in any form you like.

I don’t understand what you want to display when the car passes point 1

If this was my project I would connect up the LDR so it causes an Arduino pin to show HIGH when it is illuminated, otherwise LOW. If you arrange it to work with a digital I/O pin it will make the programming simpler and the timing more accurate.

Start by writing a short program that reads the I/O pin regularly (say 2 times per second) and shows the value in the Arduino Serial Monitor. There is no point writing a more complex program until that works properly.


Many LDRs are slow to respond, a photodiode or phototransistor is way quicker and more suitable for timing.