Hardware

To begin with, we need an Arduino Uno board (or any other Arduino board). We also need an ultrasonic range finder sensor. A quick web search shows hundreds of rangefinder sensors for less than a quarter of a dollar. We use a sensor named HC-SR04-Ultrasonic Range Finder, but just about any other sensor would do. The sensor we have chosen provides a range-finding capability for distances in a 2 cm - 300 cm range, with an accuracy of up to 3 mm.

These sensors use sonar to determine the distance to an object, just as dolphins and bats do. Here's how the sensor calculates the distance. The module has two units. The transmitter transmits ultrasound, while a receiver reads any ultrasound that reflects back. Since the speed of ultrasound is fixed and known, by calculating the time between transmission and reflection, we can calculate the distance of the object that reflected the ultrasound.

Here's how the hardware is set up:

To the left is the Arduino Uno board. The ultrasound sensor is towards the right. As you can see the sensor has four pins marked VCC, Trig, Echo, and GND. The specifications of the sensor states that it needs 5 volts to run. Accordingly, we connect the VCC pin to a pin that reads 5V on the Arduino pin. Similarly, the ground pin (GND) from the sensor is connected to a GND pin on the Arduino board. Now the sensor is powered up. We connect the Trig pin to pin number 8 and the Echo pin to pin number 7 on the Arduino board. Every time we provide a high pulse on Pin 8, the sensor will trigger an ultrasound and then the Echo pin will return the time it took for the ultrasound to reflect back, which we will read into the Arduino on Pin 7.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.71.211