Hello, can someone please advise?
I am for the school project trying to measure the speed of an object passing between 2 points.
for various reasons in the project have to hc sr04 ultrasonic sensor.
Firstly I use how many measure to in the horizontal plane speed?1 or 2?
When I use 2 sensors and the object is slowly move the project is working but the object is fastly move the project is not working. This situation It's going to be more than 2,5 km/h. Less than 2,5 km/h it's working.
Secondly this situation Is it from the sensor?
materials used in the project:
Arduino Genuino Uno,
2 units hc sr04 ultrasonic sensor,
Code:
byte trigger = 6;
byte echo = 7;
byte trigger2 = 2;
byte echo2 = 3;
unsigned long Time;
double TotalRoad;
int Distance;
unsigned long Time2;
double TotalRoad2;
int Distance2;
int maxDistance = 50;
int BetweenDistance = 12;
double StartTime;
double EndTime;
double TotalTime;
boolean endFlag;
void setup() {
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
//pinMode(trigger2, OUTPUT);
//pinMode(echo2, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigger, HIGH);
delayMicroseconds(100);
digitalWrite(trigger, LOW);
digitalWrite(trigger2, HIGH);
delayMicroseconds(100);
digitalWrite(trigger2, LOW);
Time = pulseIn(echo, HIGH);
Time2 = pulseIn(echo2, HIGH);
TotalRoad = (double)Time*0.034;
Distance = TotalRoad / 2;
TotalRoad2 = (double)Time2*0.034;
Distance2 = TotalRoad2 / 2;
if(Distance<maxDistance){
StartTime = millis();
endFlag = false;
return;
}
if(Distance2<maxDistance && Distance2>1){
EndTime = millis();
endFlag = true;
return;
}
Measurement();
}
void Measurement(){
TotalTime = EndTime - StartTime;
TotalTime = TotalTime/1000;
double Speed;
Speed = (BetweenDistance/TotalTime);
if(Speed>1 && Speed<1000){
Serial.print("Speed : ");
Serial.print(Speed);
Serial.print(" cm/sn\n\n");
Speed = (Speed/100)*(36/10);
Serial.print("Speed : ");
Serial.print(Speed);
Serial.print(" km/h\n");
}
delay(500);
}