1
votes

i want made speed detection "device" using with Arduino and two ultrasonic hc-sr04 like this link. but I want to make it with ultrasonic instead by LDR.

from that link. how lasers and ldr work, like this

The resistors are used as pull-down resistors and I wired the sensors and put them in a case, to avoid them detecting surrounding light. For each case, a hole was drilled so that the laser beam can light the sensor while the ambient light does not affect the sensor. The working principle is easy: an object that passes by will "cut" the laser beams, this means the LDR sensor will detect this sudden drop of light intensity. First I defined a threshold value under which the sensor is considered triggered, once the value is under threshold for the first sensor then Arduino waits for the second one to be triggered. During this waiting time it counts the elapsed time between the two events. When the second beam is interrupted, the timer stops and now is just simple math. The distance between the 2 sensors is known, the time between the two events is known, and speed can be computed as speed = distance/time.

Below the Arduino code:

/* 
by Claudiu Cristian 
*/ 

unsigned long time1; 
int photocellPin_1 = 0; // 1st sensor is connected to a0 
int photocellReading_1; // the analog reading from the analog port 
int photocellPin_2 = 1; // 2nd sensor is connected to a1 
int photocellReading_2; // the analog reading from the analog port 
int threshold = 700; //value below sensors are trigerd 
float Speed; // declaration of Speed variable 
float timing; 
unsigned long int calcTimeout = 0; // initialisation of timeout variable 

void setup(void) { 
// We'll send debugging information via the Serial monitor 
Serial.begin(9600); 
} 

void loop(void) { 
photocellReading_1 = analogRead(photocellPin_1); //read out values for sensor 1 
photocellReading_2 = analogRead(photocellPin_2); //read out values for sensor 2 
// if reading of first sensor is smaller than threshold starts time count and moves to             calculation function 
if (photocellReading_1 < threshold) { 
time1 = millis(); 
startCalculation(); 
} 
} 

// calculation function 
void startCalculation() { 
calcTimeout = millis(); // asign time to timeout variable 
//we wait for trigger of sensor 2 to start calculation - otherwise timeout 
while (!(photocellReading_2 < threshold)) { 
photocellReading_2 = analogRead(photocellPin_2); 
if (millis() - calcTimeout > 5000) return; 
} 
timing = ((float) millis() - (float) time1) / 1000.0; //computes time in seconds 
Speed = 0.115 / timing; //speed in m/s given a separation distance of 11.5 cm 
delay(100); 
Serial.print(Speed); 
Serial.print("\n"); 
} 

how to implement the code with ultrasonic HC-SR04 sensors? the coding is problem for me. hopefully someone can help me...... :( Please excuse my poor English !

1
ai citit asta? tautvidas.com/blog/2012/08/… ;) Good luck!Acelasi Eu

1 Answers

1
votes

There are already lots of examples on the internet, so if all you want to do is copy, google arduino sr04

But if you want to know how to do it... The sr04 has 4 pins, vin, gnd, trigger, and echo. Connect vin and ground to +5 and gnd Connect trigger to a digital output pin Connect echo to a digital input pin

Trigger by going low for 2 microseconds (us) and then high for 10 us then low again Then get the results with a pulseIn from the echo pin

Read the data sheet for more information