Arduino Range Finder (Week 12)

What is an Arduino Range Finder?

Ultrasonic range finders are fun little modules that measure distance. You can use them to find out the distance to an object, or to detect when something is near to the sensor like a motion detector. They are ideal for projects involving navigation, object avoidance and home security. With an Arduino kit you can create a mini range finder yourself and it is not very complicated.

sd

How does the range finder measures distance?

On the front of the ultrasonic range finder are two metal cylinders. These are Transducers. Transducers can convert mechanical forces into electrical signals. In the ultrasonic range finder there is a transmitting transducer and a receiving transducer as shown in the image below. The transmitting transducer converts an electrical signal into the ultrasonic pulse, and the receiving transducer converts the reflected ultrasonic pulse back into an electrical signal.

  • MAX3232 is the IC that controls the transmitting transducer.
  • LM324 is a quad Op-Amp that amplifies the signal generated by the receiving transducer into a signal thats strong enough to transmit to the Arduino.

The Ultrasonic range finder has four pins: Vcc, Trig, Echo and GND.

  • The Vcc pin supplies the power to generate the ultrasonic pulses.
  • The GND is connected to the ground.
  • The Trig pin is where the Arduino sends the signal to start the ultrasonic pulse.
  • The Echo pin is where the ultrasonic range finder sends the information about the duration of the trip taken by the ultrasonic pulse to the Arduino.

dcs

Arduino Range Finder Setup

First you have to set up your Arduino kit. The image below shows what the setup looks like.

sw

Once you have everything connected you need to upload the code which is shown below to the Arduino through Python or any other programme you feel comfortable using.

dwc

wd

wx

wex

Explanation/ Reasoning behind this code

  • Line 11: Declares the variables duration and distance.
  • Lines 12 and 13: Sends a 2 µs LOW signal to the trigPin to make sure it’s turned off at the beginning of the program loop.
  • Lines 15-17: Sends a 10 µs HIGH signal to the trigPin to initiate the sequence of eight 40 KHz ultrasonic pulses sent from the transmitting transducer.
  • Line 19: Defines the duration variable as the length (in µs) of any HIGH input signal detected at the echoPin. The Echo pin output is equal to the time it takes the emitted ultrasonic pulse to travel to the object and back to the sensor.
  • Line 20: Defines the distance variable as the duration (time in d = s x t) multiplied by the speed of sound converted from meters per second to centimetres per µs (0.0344 cm/µs).
  • Lines 22-24: If the distance is greater than or equal to 400 cm, or less than or equal to 2 cm, display “Distance = Out of range” on the serial monitor.
  • Lines 26-30: If the distance measurement is not out of range, display the distance calculated in line 20 on the serial monitor for 500 ms.

Adding the LCD

The image below shows you what to add when inserting your LCD. The reason you would add this to your Arduino setup is because the LCD display will inform you in “cm” the distance of the object.

wew

Once this is complete the last thing you have to do is insert the code shown below into the Arduino.

cd

dwc

dwc

dc

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Print Friendly, PDF & Email
Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *