Preview Mode. Sign in to save progress!
You are in preview mode! Progress will not be saved!
Sign in to save your progress!

Detecting Objects From A Distance

Distance sensor

While robots can use touch sensors to detect walls or objects, sometimes more flexibility is needed. What if your robot need to avoid walls or objects in its path, running into them with a touch sensor isn't always the best solution. To detect objects and know how far away the objects are robots can use a distance sensor. Distance Sensors, sometimes called ultrasonic sensors, use sound waves to tell the robot how far away the robot is from the wall. The sensor sends a pulse of ultrasonic sound, and then times how long it takes for the echo to bounce back to the sensor. The Arduino is then able to use the pulses to calculate how far away an object is.

arduinoToDistance

This may seem like the perfect sensor to use everywhere, but it does have its limitations. The sensor is sound based, meaning that anything that effects sound can affect the sensor readings. For example, the sensor works best when facing a hard, flat surface. If the sensor is pointed at something angled or round the sound waves can bounce off into different directions and never return to the sensor. The sound waves can also be absorbed into soft material like foam and again not make it back to the sensor. When the sensor does not receive the echo it can not calculate the distance from the object.

Mini Project Control Motor Using A Sensor (Distance Sensor)

In this project, you will use an Ultrasonic Sensor to control when a motor runs. The motor will run when something is near the sensor and will stop when nothing is in front of it.

distance-sensor-circuit
Required items and tools

Find the following components in your kit:

  • Previous Limit Switch Circuit Previous Limit Switch Circuit
  • Arduino Uno Arduino Uno
  • USB A-to-B cord USB A-to-B cord
  • Computer with USB ports Computer with USB ports
  • Distance Sensor Distance Sensor
  • 22 AWG wire 22 AWG pin wire
  • Header Pins Header Pins
  • Header Pin Housings Header Pin Housings
  • Header Pin Crimper Header Pin Crimper
Step 1: Prepare the wires
22-AWG-split

To connect the Arduino to the Distance Sensor you will need 3 wires. Start by seperating and stripping a red, black and white 22 AWG wires.

Step 2: Attach Header Pins (Male)
r-b-w-male-header

Take the red, black, and white wires, and attach male header pins to the end of them.

Step 3: Attach Header Pins (Female)
r-b-w-female-header-combo

Take the other end of the black, red, and white wires, and attach female header pins to the ends of them. Since the sensor has all of its pins together you can use either all single pin housings or use a 3x1 pin housing. Click below if you want to learn how to use the multi pin housing.

r-b-w-female-header

Multi-pin housings work exactly the same as the single pin ones. Each clip on the crimps locks into the hole in the housing. When using multi-pin housings it is important to connect the wires in the proper order since the wires cannot be removed from the housing after they are clipped in.

(Optional) Module: Attaching Header Pins

Use this module as a refresher on attaching header pins.

Attaching Header Pins Connector: Required items and tools

To begin attaching and crimping spade connectors, you will need the following:

  • 22 AWG Wire 22 AWG Wire
  • Wire Cutter/Stripper Wire Cutter/Stripper
  • Header Pin Crimper Header Pin Crimper
  • Male or Female Header Crimps Male or Female Header Crimps
  • Header pin housings or shells Header pin housings or shells
  • Needle nose pliers or Wire Cutter / Stripper Needle nose pliers or Wire Cutter / Stripper
Note: Extra Components are very Usefull!

You may want to have extra crimps and wires. These crimps are small, require a special crimping tool, precise techniques and practice to create a proper crimp.

Understanding Header Pins

Header pin crimps are made up of three distinct portions: The mating pin zone is the portion of the crimp that interfaces with the component that you are connecting to. The other two portions interface with the wire. There is the conductor crimp zone which is the portion of the cimp that forms around the conductor and makes the electrical connection. The final part is the insulation crimp zone, where this part of the crimp forms around the wire’s insulation. This further securies the wire and creates a strain release. Both male and female header pins are crimped using the same process.

Step 1: Cut wire to length and separate

Cut a piece of the wire to the needed length and separate the number of wire you need from the .

Step 2: Strip the individual wires

Strip the ends of the wire so that 0.10 in or 2.5 mm of wire is exposed. It may be easier to strip the wires longer and trim the exposed wires to 0.10 in or 2.5 mm.

Step 3: Cut off a male or female connector

Cut off the male or female pin off of their connector strips. Keep the metal tab connected to the crimp, it will be used to align the crimp into the header pin crimper.

Step 4: Insert the wire into crimp

Place the wire into the crimp. Make sure the exposed wire is not in the mating pin zone.

Step 5: Fold over the Insulation-crimp

To give your crimp a better chance to be successful use your wire cutters or needle nose pliers to start to fold over the tabs on the insulation crimp zone.

Understanding the Crimper

The recommended crimper has 2 different crimping areas the larger anvil crimps the insulation zone while the smaller anvil crimps the conductor zone. Make sure to line up the zones correctly or the crimp will not crimp properly.

Step 6: Crimp the connector

Use the crimping tool to crimp the conductor crimp zone and the insulation crimp zone. Make sure the Mating pin zone is extended completely out of the crimping tool. If you crimp this part it will deform and will not function

After crimping, if you inspect the connection and see that the crimped parts are not fully compressed onto the wire you may want to crimp the connection a second time.

Step 7: Remove the metal carrier strip

Once the crimp is successfully attached to the wire you can remove the metal carrier strip by bending or cutting it off. After removing that, the crimp is ready to be placed into the plastic housing.

Step 8: Adding the housing

The plastic housing, or shields as they are sometimes called, add structure and support to make the crimp more durable. The plastic housings come in various sizes that can hold multiple connections in one block. Some projects will have all the connections next to each other which make the multi-connection block very convenient to use. Using single pin housing is easier to learn on and creates wires that have more flexibility in how they can be connected.

Both the male and female header pins have a small square or rectangle of metal in the pin mating zone. This metal “tab” will lock itself into the square opening or “slot” in the housing. Make sure the tab and the slot are facing the same direction and push the crimp into the larger opening in the housing. If done successfully the crimp will lock itself in the housing.

If the crimp is having trouble fitting into the housing you may want to use your wire cutters or needle nose pliers to compress the insulation crimp.

Step 9: Test the connection

Perform a pull test to confirm that the crimp will not slip out of the housing. If the housing does not easly slip off you have successfully made a crimp!

Step 4: Attach Wires To Distance Sensor
b-r-w-distance-sensor
  • Attach the newly created wires to the Distance Sensor. You will need to attach the female header pin of the black wire to the GND port of the Distance Sensor, the female header pin of the red wire to the 5V port of the Distance Sensor, and the female header pin of the white wire to the SIG port of the Distance Sensor.
  • The 5V and GND connections are responsible for powering the board and allowing it to send and receive sound waves. The SIG or signal connection is that connection that will relay the timing information generated by the sensor.
Step 5: Attach the Distance Sensor to the Arduino
arduino-distance-connected
  • Attach the male header pin end of the black wire to a GND pin of the Arduino.
  • Attach the male header pin end of the red wire to the 5V pin on the Arduino. Unplug the red 5V wire from the Motor Control Board to make this connection.
  • Attach the male header pin end of the white wire to digital pin 7 on the Arduino.
Step 6: Power the Arduino
arduino-powered

Connect the Arduino to your computer using the USB A-to-B cable.

Step 7: Open Distance-Sensor-Motor-Control Program
arduino-open
Step 8: Upload the Program
Distance-Sensor-Motor-Control-upload

Click on the Upload button to upload the program to the Arduino Uno. The program should immediately run after it is done uploading.

What happens?

arduino-ultrasonic-motor

The motor should move only when an object is within 10 cm of the distance sensor! Use your hand to place it in front of the sensor at different distances.

Explanation

The Distance Sensor is connected to the Arduino and is powered by using the 5V and GND pins. The Digital pin 7 is used to both instruct the sensor to send the sound waves as well as listen for the sound to bounce back.

If you look in the program, you will see that the program has commands to send two quick pulses. These quick pulses ensure that the sensor is only looking for new sound pulses. This is required because when the sensor is initially powered up it starts sending sound waves out. The set of quick pulses allow the sound waves time to dissipate allowing the sensor to have a clean input.

quick-pulses

The next few lines then set that pin as an INPUT and waits until it hears the sound. The program then records the time it took to hear the sound.

code-input-wait

Then, once it does, it uses the amount of time to determine how far away the object is from the sensor. This program calculates distance in both metric and imperial units

code-time-distance

To calculate the distances the program divides the time it took for the sensor to hear an echo by the speed of sound. That number is then divided by 2 to calculate the distance since the sound waves are traveling to the object and returning to the sensor.

arduino-distance-calculation

The code then uses this measurement to determine when the motor turns on or off.

code-motor-on-off
Contact Us