Pages: [1]   Go Down
Author Topic: Calculating speed using an IR sensor  (Read 1271 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using the sharp GP2Y0A21YK IR sensor. The code below (taken from http://luckylarry.co.uk/) allows me to calculate the proximity of an object from the sensor

-------------------------------------------------------------------------------------------
int IRpin = 1;                                    // analog pin for reading the IR sensor
void setup() {
  Serial.begin(9600);                             // start the serial port
}
void loop() {
  float volts = analogRead(IRpin)*0.0048828125;   // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
  float distance = 65*pow(volts, -1.10);          // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
  Serial.println(distance);                       // print the distance
  delay(100);                                     // arbitary wait time.
}
-------------------------------------------------------------------------------------------

Now I need to calculate the speed of an object as it moves away or closer to the sensor. any help?
Logged

0
Offline Offline
Shannon Member
****
Karma: 159
Posts: 10409
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

speed is rate of change of distance over time.  Thus  if you measure distance d1 at time t1, d2 at t2, calculate (d2-d1)/(t2-t1).
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: