galoebn
Published © GPL3+

Measure speed with two photoresistors

In this project I show you a simple way to measure the speed of objects passing by.

BeginnerFull instructions provided734
Measure speed with two photoresistors

Things used in this project

Hardware components

Photo resistor
Photo resistor
×2
Arduino Mega 2560
Arduino Mega 2560
I use an Arduino Mega 2560 but you can use any other Arduino board as well.
×1
Resistor 10k ohm
Resistor 10k ohm
×2

Story

Read more

Schematics

Schematics

Connect everything as shown in this picture. It is very important that the two photoresistors are 10cm apart from each other. Otherwise you will get wrong speed measurements.

Code

Code

Arduino
void setup(){
  Serial.begin(9600);
  delay(100);
}


void loop(){
  int x = analogRead(A0);
  delayMicroseconds(100);
  if(abs(analogRead(A0) - x) > 2){
    unsigned long t = micros();
    while(1){
      x = analogRead(A1);
      delayMicroseconds(100);
      if(abs(analogRead(A1) - x) > 2){
        Serial.print(360000.0/(micros() - t));
        Serial.println(" km/h");
        delay(500);
        break;
      }
    }
  }
}

Credits

galoebn

galoebn

9 projects • 4 followers

Comments