Add Sensors to Your Robot
Now that our robot is built and moving around, it’s time to give it a brain. The two sensors can be used by the robot to react to its surroundings; either following a line or avoiding obstacles.
ULTRASONIC AND LINE SENSING
Our robot has two sensors, an Ultrasonic and a Line Detector. The Ultrasonic is the one that looks like eyes and fits into the breadboard. The Line Detector has a small blue camera on one side and fits underneath the robot.
STEP 1
Open the CamJam website (camjam.me/?page_id=1035#worksheets) and download Worksheet 4 and Worksheet 5. Worksheet 4 is just for the Line Detector, while worksheet 5 is for both sensors. Make sure you take a good look at the Building the Circuit diagram in Worksheet 5 and keep it with you during this tutorial.
STEP 2
Make sure that the robot isn’t currently powered. If it is use VNC and shutdown the Raspberry Pi and disconnect the power to the Raspberry Pi. Locate one of the female-male jumper wires and connect the female end to the GND pin on the Line Detector. Connect the other end to the breadboard in the eighth column, fourth row (as shown here).
STEP 3
Use a regular male-male jumper cable and place it next to the jumper in the breadboard (in the same column, fifth row). Connect the other end to the GND of the EduKit Controller Board. Now take another female-male jumper wire and connect it from the VCC pin on the Line Detector to the 3V3 (3.3 volts) pin on the EduKit Controller Board.
STEP 4
Now take a third female-male jumper cable and connect it to the OUT pin of the Line Detector. Connect the other end to pin 25 on the EduKit Controller Board. This pin is used as the input pin to get a reading from the Line Detector. Note that the colours of your wires may not match the ones in the Worksheet diagram and it doesn’t matter which colour you use.
STEP 5
Now it’s time for the Ultrasonic Sensor. Take it out of the its packaging and slot it gently into the breadboard. Make sure the GND pin is in a hole in the same column as the GND pins from Step 2 (as shown in this photo). The Echo, Trig and VCC pins should be in the breadboard holes to the right.
STEP 6
Take a good look at the resistors in the tutorial. You need a 33OΩ resistor. This should be orange-orange-brown-gold (or Orange, Orange, Black, Black, Brown). Bend both pins to form a U-shape and insert one end in same column as the Echo pin on the sensor. The other end goes into an unused column on the left.
BUILDING THE CIRCUIT
We’ve started putting together the circuit but now we need to use the resistors and remaining cables. The resistor is used with Echo because the sensor needs a +5v but the Raspberry Pi input only likes 3.3v. Be sure to check the resistors carefully.
STEP 1
Now we’re going to use a 47OΩ resistor, which should be yellow-purple-brown (or Yellow, Violet, Black, Black, Brown). One end goes in the same column as the GND pin on the sensor, the other into the same column next 33OΩ resistor from Step 6.
STEP 2
Now take a jumper cable and place one end in the same column as the two resistors. Place the other end in Pin 18 of the EduKit Controller Board. Use a second jumper to connect the VCC connection to the EduKit Controller Board’s 5v socket. A third jumper connects the Trig column to Pin 17.
STEP 3
With everything wired up, take the double-sided tape off the bottom of the breadboard and attach it to the top of your robot (with the sensor facing outwards). Use some of the double-sided tape that’s spare and connect the Line Detector to the bottom of your robot making sure the lens faces down.
STEP 4
Now create the 5-distance.py code and place it in your EduKitRobotics directory. Use python3 5-distance.py to run the code and you will see distances appear on the screen. Place your hand in front of the sensor and watch how it adjusts accordingly. Now Happy robotics.
More information
- Create an USB temperature sensor for data acquisition
- Saving temperature data into an SQL Database
- Detecting vehicle license plates
- Raspberry Pi Portable Games Console
- Set Up a Time-lapse Webcam
- Build a Web Server
- Create a Supercomputer
- Tracking device locations using Google Maps
- Controlling Your Robot
- Add Sensors to Your Robot
- Turn an RC Toy into a Robot
- Using GitHub