Wiring the sensor in

The next diagram shows how the connections (not wiring details) will look. Connections in red are new connections:

Diagram with line sensors added

First, we will need to place a breadboard onto the robot. A breadboard lets us poke wires and component leads into slots that are connected electrically to make connections without needing soldering that are easy to modify. 

Do not make connections to and from a breadboard on any circuit that is powered up! This may cause damage to the components, sensors, or controller boards. This is a very easy way to destroy a Raspberry Pi.

The following photo shows how to attach the breadboard:

Attaching a breadboard

Perform the following steps:

  1. This is the breadboard. On the back of it should be some backing to a self-adhesive strip.
  2. Peel the backing from the strip.
  3. Line the board up with the USB battery. Note that you should try to keep the battery level indicator, if your USB battery has one, clear. My indicator was on the underside of mine.
  4. Stick the breadboard down firmly.

The next step is wiring the cables in. At this point, it is helpful to have the following Raspberry Pi GPIO diagram for reference:

Raspberry Pi GPIO pins used for this sensor

In the previous diagram, I've changed my annotations to highlight the connections we will make. First, note that the bottom of the diagram would be the front of the robot, so the upper row would be the front row of GPIO pins. I've highlighted a 3.3v pin and a GND pin. These will provide power to the sensor in the correct range for the Pi. I've also highlighted pins 23 and 16. These will be the left and right sensor input pins respectively.

Next, we need to wire the sensor and bring the connections up to the top of the robot chassis. The following photo shows you the steps you'll need:

Sensor connections at the bottom of the robot
Always use the darkest colored edge on grouped jumper wires for ground. If there are left and right groups, it can help to clearly mark one side, the left side, with a bit of insulation tape.

To wire the sensor, follow these steps using the preceding photo as a reference:

  1. With the male-to-female jumper wire strip, make two strips of three. You can do this by taking three ends and gently pulling them apart from the others. Keeping the three attached will make it easier to work with than with three separate wires for each sensor.
  2. For each cable, plug one end into a sensor. As a general guideline, if one side is a darker color, wire this one into ground, G or GND on the sensor. This pin may be marked "-" or "-ve" for negative too. This makes it easier to identify which way up it should be later. Take a note of the order of pins on the sensor—mine are "GVS": Ground, Voltage, and Signal.
  3. Push the other end through a wider hole between the bottom of the chassis to the top. In my robot, this was the same hole I pushed the motor cables through. Repeat steps 2 and 3 for the other sensor.
  1. At the top of the chassis, gently pull the cables through. You may knock the motor cables out doing this. I did have to reconnect a couple of my motor cables at this step. There should be plenty of cable for each sensor hanging over the breadboard:

Connecting the sensors to the breadboard at the top of the robot
  1. We can now take the wires we pulled through from underneath and wire them into the breadboard.
  2. Connect the wires from the sensor so G/GND (this should be the darker colored wire) goes into the blue track on the breadboard, V/VCC (middle) goes to the red track, and S/OUT goes to a pin on the breadboard.
  1. Keep the left sensor connections in a left-hand row (I went with row 8) and the right in a right hand row (row 19):

Connecting the power to the sensors from the Pi

Next, we need to make the power connections to the Pi as shown in the preceding photo. Peel off another strip of two cables—preferably with a black wire in them. These will be the power connections. Here is how to connect them:

  1. At the leftmost row (1) of the breadboard, plug the black wire into the blue strip (ground) and the lighter color into the red strip (which will be 3.3v).
  1. To plug these into the Raspberry Pi, reference the GPIO diagram in the photo, Attaching a breadboard; the black wire is GND, and should be on the top row, three pins in from the left. The lighter colored wire is 3.3v, and should be plugged into the the first pin from the left on the bottom row:

Wiring the breadboard sensor signals to the Pi

Now we need two individual wires; these carry the signal from the sensors to the Pi. Pull two individual ones from the strip. We will be using the breadboard rows we've plugged the sensor signal cables into. Holes in breadboard rows are connected horizontally up to the middle groove. I've added a green highlight to row 10 in the photo, Connecting the power to the sensors from the Pi, to show how that row's holes (also known as tie-points) are connected. The preceding photo shows how to wire the sensor signals from the breadboard to the Raspberry Pi. Refer to the following steps:

  1. One cable should be plugged into the same breadboard row as the left sensor (row 8) and the other cable should be plugged into the same row as the right sensor (row 19).
  1. We can wire these two sensor cables into the Pi. The left, from row 8, should be plugged into IO pin 23 on the Pi. The right, from row 19, goes into pin 16 on the Pi. Reference the GPIO diagram in the photo, Attaching a breadboard, to see where those pins are. Pin 23 is eight pins from the left on the top row. Pin 16 is three pins in from the right on the top row. Your sensor is now ready to test! The completed robot should look like this:

Completed line following robot on a test track
Double check your wiring before applying power. Damage to the Raspberry Pi and sensors could occur if it's not wired correctly.
..................Content has been hidden....................

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