ldr timer

Hello.

We´re 15 years old spanish students and we are trying to construct an automatic arduino timer for our line follower robots. We have all the haradware. A laser diode send light to the ldr, and a lcd display 2x16 show the results, and the best lap. We find the code at - YouTube, but we caný read the times.... Can you find the code error, please?

many thanks!!!!

/* Single lane slot car timer
Written by TheInsanityUnleashed @ Youtube
----------------------------------------------------

         PhotoR     10K
+5    o---/\/\/--.--/\/\/---o GND
                |
Pin A0 o----------


Pin 9 ------Piezo-----gnd


Sensitivity Pot --------- Pin A1

----------------------------------------------------
*/

#include <LiquidCrystal.h>

//variables
const byte lightPin = 0;  
const byte speakerPin = 9;
int lightSensor = 0;
unsigned long lapMillis = 0;
unsigned long startMillis = millis();
unsigned long bestMillis = 9999999;
float lapTime = 0.00;
float bestLap = 0.00;
boolean firstTrigger = true;
boolean newBest = false;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Start!           ");
  Serial.begin(9600); 
  pinMode(speakerPin, OUTPUT);
  digitalWrite(speakerPin, LOW);
}

void loop()
{

//reading from light sensor
lightSensor = analogRead(lightPin);


//If car detected
if(lightSensor < analogRead(1)){

  
  //determine lap time in milliseconds
  lapMillis = millis() - startMillis;
  startMillis = millis();
  
  lapTime = lapMillis / 1000.00;
  
  //if firs trigger print race started
  if (firstTrigger == true){
    lcd.setCursor(0, 0);
    lcd.print("Race Started!    ");
  }
  
  //print if not first trigger
  if (firstTrigger != true){
    Serial.print("lapTime: ");
    Serial.println(lapTime);
    Serial.print("lapMillis: ");
    Serial.println(lapMillis);
    //print lap time
    lcd.setCursor(0, 0);
    lcd.print("Last: ");
    lcd.print(lapTime);
    lcd.print("       ");   
  }
 
      
  //if last lap is better than best lap
  if(lapMillis < bestMillis && firstTrigger != true)
  {
    bestMillis = lapMillis;
    bestLap = lapTime;
    Serial.print("bestLap: ");
    Serial.println(bestLap);
    //print best lap time
    lcd.setCursor(0, 1);
    lcd.print("Best: ");
    lcd.print(bestLap);
    lcd.print("      ");
    newBest = true;
  }
  
  //beep piezo
  if(newBest == true)
  {
    digitalWrite(speakerPin, HIGH);
    delay(25);
    digitalWrite(speakerPin, LOW);
    delay(25);
    digitalWrite(speakerPin, HIGH);
    delay(25);
    digitalWrite(speakerPin, LOW);
    delay(25);
    digitalWrite(speakerPin, HIGH);
    delay(25);
    digitalWrite(speakerPin, LOW);
    delay(25);
    digitalWrite(speakerPin, HIGH);
    delay(25);
    digitalWrite(speakerPin, LOW);    
    newBest = false;
  } 
  else
  {
    digitalWrite(speakerPin, HIGH);
    delay(150);
    digitalWrite(speakerPin, LOW);
  }
  
  firstTrigger = false;
  Serial.println("----------------"); 

}
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

but we caný read the times..

Do you see any text on the LCD ?

The code does SOMETHING. What does it do?
You want it to do something different. What do you want it to do differently?

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Can you please post a picture of your project.

WHY???
You have the project infront of you, we don't.
You know how it is wired, we don't.

Hope to help... Tom.... :slight_smile: