Collision Prevention- Powered by Pi

Introduction: Collision Prevention- Powered by Pi

This Instructable will give you a step-by-step guide to construction of The Collision Prevention System. To start one must obtain the following list of materials:

Raspberry PI 3 (with power and Ethernet chords), 1 GPIO Extension Board and Ribbon Cable (GPIO), 1 Large Breadboard with diagram, 2 small breadboards with diagram, 14 jumper cables, 3 220 Ohms resistor, 1 RGB LED, 3 button switches, 1HB-SR04 Ultrasonic sensor

Step 1: GPIO Extension

Connect the GPIO extension board to the large breadboard. The GPIO should be facing vertical just as the breadboard is. Assign the left side of the GPIO to breadboard ports D1-D20 using the provided diagram. The right side then would connect to H1-H20. Connect the ribbon cable to both the Raspberry Pi 3 and the GPIO extension board. This whole component will now be referred to as the GPIO board (GPIO)

Step 2: Ultrasonic Sensor

Using another smaller breadboard, connect the HR-SR04 ultrasonic sensor to the smaller breadboard ports A2-5 using the provided diagram. Connect a jumper cable to the smaller breadboard (BB) E2, insert the other end in the GPIO extension board port J1. In the same manner, connect three more jumpers in the following fashion. (BB E3,GPIO B17) (BB E4, GPIO B18)(BB E5, GPIO B20)

Step 3: LED and Resistors

On the same small breadboard used in the previous instruction, connect three 220 ohm resistors in the following fashion. (E10, H10)(E12, H12)(E14, H14) Then connect a jumper from the same breadboard E13 to the ground power rail on the GPIO board. Connect the four prongs of the LED to the smaller breadboard ports (B13)(D14)(D12)(D10). Then connect three jumpers from the smaller breadboard to the GPIO board in the assigned fashion. (BB J10, GPIO J9) (BB J12, GPIO J8) (BB J14, GPIO J6). This breadboard is now complete.

Step 4: Ground

Use another jumper to connect GPIO board J7 to the ground power rail.

Step 5: Buttons

Using the second breadboard place the top of a button switch on port E1 and D1, place another at E5 and D5, and a third at E9 and D9. Connect three jumpers from the positive power rail on the GPIO board to the following breadboard ports (D3) (D7) (D11). Using three more jumper cables, connect the breadboard to the GPIO extension board in the following manor: (BB D1, GPIO J16) (BB D5, GPIO J18) (BB D9, GPIO J20). Finally, using the last jumper cable, connect GPIO A1 to the positive power rail. The physical setup is now complete.

Step 6: Code

Connect the Ethernet cable and power cable to the Pi and into their respective positions. Open MATLAB and run the following script to initialize the micro-controller:

rpi = raspi('','pi','raspberry');

Then copy and paste the following into a new script, called Ping, to run the collision prevention system:

function dist = ping()
trig = 19; echo = 13; test = 21; configurePin(rpi, trig, 'DigitalOutput'); configurePin(rpi, echo, 'DigitalInput'); configurePin(rpi, test, 'DigitalInput');

disp("Distance Measurement In Progress");

while true writeDigitalPin(rpi,trig, 0); disp("Letting sensor settle"); pause(2);

writeDigitalPin(rpi,trig, 1); pause(0.002); writeDigitalPin(rpi,trig, 0);

while readDigitalPin(rpi,echo) == 0 tic end

while readDigitalPin(rpi,echo) == 1 T = toc; end

pulse_duration = T; distance = pulse_duration * 17150;

open = "Distance= "; close = " cm"; string = [open, distance, close]; disp(string); dist = distance; end end

In a new script, run the following code named status:

configurePin(rpi, 21, 'DigitalInput');
configurePin(rpi, 16, 'DigitalInput'); configurePin(rpi, 12, 'DigitalInput');

status = 2; d = 10; %Status: 0-Red/Stop 1-Blue/Slow 2-Green/Go running = true; while running %d = ping(); if readDigitalPin(rpi,21) == 1 status = 0; elseif readDigitalPin(rpi,16) == 1 status = 1; elseif readDigitalPin(rpi,12) == 1 status = 2; elseif d < 10 status = 0; elseif d < 25 status = 1; else status = 2; end if status == 0 writeDigitalPin(rpi,18,1); writeDigitalPin(rpi,23,0); writeDigitalPin(rpi,24,0); elseif status == 1 writeDigitalPin(rpi,18,0); writeDigitalPin(rpi,23,0); writeDigitalPin(rpi,24,1); elseif status == 2 writeDigitalPin(rpi,18,0); writeDigitalPin(rpi,23,1); writeDigitalPin(rpi,24,0); end end

Be the First to Share


    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest



    1 year ago

    Thanks for sharing this Pi project! Those sensors are so fun!