Computer Science, asked by tamaghnadey1916, 9 months ago

please help: A syntax in arduino programming language to calculate the distance of an obstacle when you are using LDR technology​

Answers

Answered by TyrannosaurusRex1
1

Answer:

const int pingPin = 7;

void setup() {

// initialize serial communication:

Serial.begin(9600);

}

void loop() {

// establish variables for duration of the ping,

// and the distance result in inches and centimeters:

long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.

// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

pinMode(pingPin, OUTPUT);

digitalWrite(pingPin, LOW);

delayMicroseconds(2);

digitalWrite(pingPin, HIGH);

delayMicroseconds(5);

digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH

// pulse whose duration is the time (in microseconds) from the sending

// of the ping to the reception of its echo off of an object.

pinMode(pingPin, INPUT);

duration = pulseIn(pingPin, HIGH);

// convert the time into a distance

inches = microsecondsToInches(duration);

cm = microsecondsToCentimeters(duration);

Serial.print(inches);

Serial.print("in, ");

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(100);

}

long microsecondsToInches(long microseconds) {

// According to Parallax's datasheet for the PING))), there are

// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per

// second). This gives the distance travelled by the ping, outbound

// and return, so we divide by 2 to get the distance of the obstacle.

// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf

return microseconds / 74 / 2;

}

long microsecondsToCentimeters(long microseconds) {

// The speed of sound is 340 m/s or 29 microseconds per centimeter.

// The ping travels out and back, so to find the distance of the

// object we take half of the distance travelled.

return microseconds / 29 / 2;

}

Explanation:

Although you'd require ping senseor

Answered by shivpatil120482
1

Answer:

Take the answer

Explanation:

Measuring distances from our robot to other objects is one of the most common data we want to obtain. For example, if we are building an autonomous vehicle, we want to check its distance from obstacles to help it make the right decision about its course. There are also many more examples of robots that we want them to activate mechanisms when something or someone gets close to them.

One of the simplest, cheapest, and most accurate ways to measure distances is by using ultrasonic sensors. Their working principle is based on the fact that sound is reflected upon most objects and materials. These sensors have a transmitter that sends a short ultrasonic burst and a receiver that senses the ultrasound upon it’s return. Knowing the speed of the sound in the air (approximately 343 m/sec), we can calculate the distance it traveled, if we measure the time passed for the ultrasound to return to the sensor.

Working Principle

All ultrasonic sensors operate in a similar way. They send a short (a few microseconds long) ultrasonic burst from the transmitter and measure the time it takes for the sound to return to the receiver.

Let’s say that it took 10 milliseconds for the ultrasound to return to the sensor. That means:

That the time in seconds is 0, 01.

Knowing that sound travels in the air 343 meters for every second, we can calculate the distance in meters by simply multiplying seconds by 343. in our case 0, 01 x 343 = 3, 43 meters.

This is the distance that the ultrasound traveled to the obstacle and back to the sensor, so the obstacle is  3, 43/2 = 1, 715 meters away from the sensor.

Pros and Cons

The main advantages of using ultrasonic sensors to measure distance are:

They are cheap and there is a plethora of choices in the market,

They are not affected by the color or the transparency of obstacles,

They are not affected by lighting conditions,

They are pretty accurate on their measurements.

Their drawbacks are:

They don’t work well enough on obstacles with small surfaces.

The angle of the surface of the obstacle is crucial for the sensor.

Obstacles made from sound absorbing materials (for example sponges) are hard to be traced by the sensor, since the absorb sound.

Choosing a Sensor

There is a wide variety of ultrasonic sensors on the market, for most robotics platforms. For those who prefer working with the Lego platform, EV3 and the older NXT, include ultrasonic sensors. Some examples of using them in the classroom are:

A door alarm using Lego NXT

Aliens welcome!

Keeping distances

If you are an Arduino or Raspberry Pi fan and want to dive more into how these sensors work, there are several options that you can find online. The most common and affordable choice is the HC-SR04, which costs less than a euro on ebay (August 2018). For more details and comparative tests with various ultrasonic sensors, I advise you to watch two detailed videos (here and here) from Andreas Spiess channel on Youtube.

Thank you

Similar questions