Proximity Following Bullet Bill

by rjsagols in Circuits > Robots

1437 Views, 21 Favorites, 0 Comments

Proximity Following Bullet Bill

Bullet Bill Project Preview

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)

Its everyone's favorite Mario enemy, the Bullet Bill! Bill is angry and on a mission to follow you. However, this one is not trying to blow you up! This determined bullet rides on 4 wheels and uses 3 ultrasonic proximity sensors to track its nearest object and pursue it.

Here is a simplified description on how the tracking system works: You define a set distance, that when read from a ultrasonic sensor, acts like a "trigger". You can think of this like a proximity sensor having a line of sight, and when an object enters this line of sight, the bullet will follow in that direction.

The LEFT and RIGHT sensors are angled 30 degrees away from the MIDDLE sensor, which creates a cone of vision.

If an object “triggers” the MIDDLE sensor, the bullet car will drive straight towards the object.

If an object triggers the LEFT sensor, the car will rotate to the left until the MIDDLE sensor is triggered, then the car will continue straight again.

If an object triggers the RIGHT sensor, the car will rotate to the right until the MIDDLE sensor is triggered, then the car will continue straight again.

There are a few other scenarios that occur (such as 2 sensors getting triggered at once) but I go into more detail in the code section of this instructable.

Supplies

Tools:

  • 3D Printer
  • Soldering Kit (optional)
  • Small Screwdriver
  • Power Drill
  • Hot Glue-gun or Superglue

Parts:

Additional Notes:

I choose to do most of the wiring of this project with a solderless breadboard, and breadboard jumper cables. I did this because I have little experience with soldering, and because I was learning as I was going. I did not want to commit to soldering to nodes when there was a potential to change the circuit in the future. This also makes the project more feasible to new tinkerers. However, I still had to solder the gauge wire to the DC motors since mine came unattached. To avoid soldering, you can buy DC motors with wires pre-soldered on to them. I did not.

With this said, if you feel comfortable using a soldering breadboard and more efficient wiring techniques, go for it!

3D Printing

I used an Ender 3 Pro with a build volume of 8.7 x 8.7 x 9.8" (220x220x250mm). Ultimaker Cura for the slicing software.

  1. 1x Face – Orient the eyeholes pointing up, with screw holes touching the build plate. Standard support settings.
  2. 1x Back Cover – Orient cover standing like a column, with the screw holes touching the build plate. Standard support settings. The back cover is in the bullet_bill.STL file. It has the face still attached to the part. Using a slicing software, cut the face off and delete it. If your software does not have a cut feature, have the face outside the build volume and it will be ignored by the 3D printer.
  3. 1x Base Plate w/ motor holders – Orient with the motor holders facing up. Rotate plate 45 degrees to fit inside the build volume. It just barely fits with my printer.
  4. 1x Gum/Sensor Holder – Orient with sensor holes facing forward. This part looks great with red PLA. GUM_LIPS.STL in the zip file (weird name I know).
  5. 1x Arduino Holder – This was printed in 2 parts (Arduino_Holder.STL and breadB_holder.STL) and hot glued together. If you prefer a solderable breadboard, you can skip this step. There should be enough space to directly attach both of these components to the base plate.
  6. 1x Small Breadboard Holder – (breadB_holder.STL) see above. Holds 8.2 x 5.5 x 0.85cm breadboard.
  7. 4x Pins to mount Motor Driver – I hot glued these on top of the battery case to hold the L298N motor driver.

All of the STL files can be found in the .zip file. Instructables won't let me upload a zip file, so just delete the '.txt' and it will work as a normal zip file.

Right click the file after downloading - rename - delete ".txt".

Downloads

Soldering DC Motors

IMG_7693.png
IMG_7685.png

If your motors came with wires already soldered on, skip this step.

Solder gauge wires to positive and negative terminals of DC motors. Zip tie the wires to the motor to alleviate tension at the solder joints. My solder joints broke the first time without zip ties, so adding the zip tie helped significantly.

Strip the opposite ends of the wires, they will connect to the L298N motor driver. Make sure to differentiate between the positive and negative wires. Having different color wires help.

DC motors are polar, meaning the direction that current flows determines if the motor will rotate clockwise or counterclockwise-wise. I positioned the motors as shown in the picture, and tested that connecting the positive wire of the DC motor to the positive end of a battery, and negative to negative end of the battery made the motor "go forward" (the rotation of the blue arrow).

We want all the motors in this position to achieve the wanted rotation (rotation of the blue arrow) when positive of each motor is connected to positive of the battery, and negative is connected to negative of a battery.

Attach Motors to Base Plate

IMG_7685.png

Have the soldered terminals facing the outside of the car, and the black end of the motors facing inwards toward each other.

Using the 1-1/4 IN screw, line up the holes on the motors with the holes on the motor holders, insert screw, and attach with hex nut. There are multiple holes to play with how far apart you want the motors to be. I used the middle pair of holes.

Feed the 2 positive wires and 2 negative wires from the DC motors through the small rectangular shaped holes on the left and right sides of the base plate.

Arduino/Breadboard Holder

IMG_7695.png

Hot glue or super glue the Arduino holder to the breadboard holder to make one piece.

Position the Arduino/Breadboard holder 1.7 in. from the front tip of the base plate.

Here is where we drill into the base plate. Take out a pencil and draw where the screws will go on the base plate. I decided to not have pre-determined holes already printed in the base plate, to be able to change the position if needed be. Insert 1/2 in. screws into your drilled holes and attach with a hex nut.

Connecting L298N Motor Driver and Battery Pack

inAB_fritz.PNG
IMG_7696.png
motors_fritz.PNG

I decided to use 2 battery packs (8 AA batteries total) to power the DC motors. They still ran with only 1 battery pack, but I preferred the higher RPM of the motors with the more juice I fed them.

I then hot glued the motor driver pins to the top of the battery pack, to hold the L298N motor driver in place. My battery packs came with an ON/OFF switch, so make sure they are facing down toward the base so you can still insert and remove batteries. Even if part of the battery pack sticks out past the end of the base, you need to be able to access the ON/OFF switches of the battery packs. With the battery holder and motor driver in place, its time to wire everything together.

  1. Take the 2 positive wires from the pair of RIGHT motors and wind them together. Also wind the exposed ends together.
  2. Take the 2 negative wires from the pair of RIGHT motors and wind them together. Also wind the exposed ends together.
  3. Repeat previous steps with the LEFT motors.
  4. Insert the positive wires from the RIGHT motors into OUT1 on the motor driver. Insert the negative wires from the RIGHT motors into OUT2 on the motor driver.
  5. Insert the positive wires from the LEFT motors into OUT3 on the motor driver. Insert the negative wires from the LEFT motors into OUT4 on the motor driver.
  6. Insert the positive wires from the battery pack into the 12V of the motor driver.
  7. Insert the negative wires from the battery pack into the GND of the motor driver.
  8. Connect a jumper cable from the 5V of the motor driver to the positive power rail of the breadboard (we will power the power rails in a later step).
  9. Connect a jumper cable from the GND of the motor driver to the ground power rail of the breadboard (we will ground the power rails in a later step).

Note: The negative wires from the battery pack and a jumper cable that is connected to the ground of the breadboard should both be connected to the GND of the motor driver. Also, remove the connectors on the motor driver that connects ENB and ENA to the pin right above them, respectfully. Your motor driver might not have these jumpers, but mine did.

  1. Connect a jumper cable from IN1 on the motor driver to pin 2 of the Arduino board. gray
  2. Connect a jumper cable from IN2 on the motor driver to pin 4 of the Arduino board. white
  3. Connect a jumper cable from ENA on the motor driver to pin 3 of the Arduino board. orange
  4. Connect a jumper cable from IN3 on the motor driver to pin 5 of the Arduino board. yellow
  5. Connect a jumper cable from IN4 on the motor driver to pin 7 of the Arduino board. blue
  6. Connect a jumper cable from ENB on the motor driver to pin 6 of the Arduino board. green

Follow the colored wires from the fritzing diagram. The labels are in the Arduino code as well.

Proximity Sensors

sensors_fritz.PNG
IMG_7659.png

We need 3 proximity sensors, and 12 female-male jumper cables.

Connect the cables onto the 4 pins on the bottom of the ultrasonic sensor. Determine which sensors you want to be LEFT sensor, MIDDLE sensor, and RIGHT sensor.

  1. LEFT sensor: Connect trigger pin to pin 9 on the Arduino. blue
  2. LEFT sensor: Connect echo pin to pin 8 on the Arduino. white
  3. MIDDLE sensor: Connect trigger pin to pin 13 on the Arduino. cyan
  4. MIDDLE sensor: Connect echo pin to pin 12 on the Arduino. brown
  5. RIGHT sensor: Connect trigger pin to pin 11 on the Arduino. purple
  6. RIGHT sensor: Connect echo pin to pin 10 on the Arduino. pink

Follow the colored wires from the fritzing diagram. The labels are in the Arduino code as well.

  • Connect a jumper wire from the 5V of the Arduino to a red power rail on the breadboard.
  • Connect a jumper wire from the GND of the Arduino to a blue power rail on the breadboard.
  • Run a jumper wire across the breadboard that connects both red power rails together.
  • Run a jumper wire across the breadboard that connects both blue power rails together

Now, all the red power rails are powered with 5V from the Arduino, and all the blue power rails are grounded to the Arduino.

Next, connect the GND of each sensor to the GND of the breadboard (anywhere on the blue power rails). Connect the VCC of each sensor to the 5V of the breadboard (anywhere on the red power rails). Follow the fritzing diagram for reference.

The sensors fit smoothly in the eye hole slots and the GUM piece we will assemble in a later step.

Cover

IMG_7699.png
IMG_7701.png
IMG_7700.png
Cover

The cover sits on top of the base plate, and contains all the components of the Bullet Bill. It also serves the function of holding all 3 proximity sensors in place.

We are going to need the Face, Back Cover, and the Gum/Sensor Holder from the 3D printed parts, as well as 3x 1IN screws and their hex nuts.

Rest the flat part of the GUM part on the inner lip of the face cover. It is a tight fit to get in the correct position, so it might take a bit of wiggling around until it fits. Line up all 3 parts so that a screw will fit through all 3. It helps to take a drill and widen/clean the screw hole to ensure that the screw will fit.

There is a fitting for a hex nut on the GUM part. Place the hex nut inside its fitting, and insert the screw through all 3 parts. Use the pictures as reference.

Fair warning: The lower lip of the face cover is fragile. Mine broke off, and that is how I was able to insert the GUM part. I then hot glued the lower lip back onto the face, and put some extra glue on the GUM part to ensure a strong bond.

Code

With the assembly done, we are ready to program the Arduino.

The program files can be found in the .zip file. Instructables won't let me upload a zip file, so just delete the '.txt' and it will work as a normal zip file.
Right click the file after downloading - rename - delete ".txt".

The code is uploaded into 2 tabs. Bullet_Bill_Project contains the main program of the tracking system, and Motor_Controls contains the functions that the main program uses.

The Motor_Controls tabs contains the functions that control the motors to go forward, reverse, left, right, and to stop.

For example, lets analyze the GO_FORWARD function. IN1 to IN2 controls the LEFT side motors . IN3 to IN4 controls the RIGHT side motors. HIGH to LOW causes the motors to rotate forward. LOW to HIGH switches the polarity, and causes the motors to rotate backwards.

Moving STRAIGHT is accomplished by having both L and R sets of motors to rotate forward.

Moving BACKWARDS is accomplished by having both L and R sets of motors to rotate backwards.

Turning LEFT is accomplished by having the L set of motors rotate backwards, and the R set of motors to rotate forwards.

Turning RIGHT is accomplished by having the R set of motors rotate backwards, and the L set of motors to rotate forwards.

The main program consist of 6 different scenarios of input from the ultrasonic sensors. The actual program goes into a little more detail, but these this is the pseudo code of the tracking system.

  1. If the middle sensor detects a distance less than 3 in, all the motors stop.
  2. If the middle sensor detects a distance less than 18in, the car goes forwards.
  3. If the left sensor detects a distance less than 12 in, turn left.
  4. If the right sensor detects a distance less than 12 in, turn right.
  5. If the middle and right sensor is triggered, turn right.
  6. If the middle and left sensor is triggered, turn left.

The first 3 blocks in the void loop control the 3 proximity sensors.

Note: If the DC motors are wired incorrectly, try changing to order of HIGH to LOW, into LOW to HIGH in the Motor_Controls tab. Basically change all HIGH into LOW and all LOW into HIGH. Test if this gives the wanted directional output. Make sure you have this tab added to the main code when compiling and running the program, otherwise the functions will not be defined in the main code.

9V Battery

IMG_7703.png

Using the 9V power adapter, connect the battery directly to the Arduino. The 9V battery powers the Arduino, while the 2 (or 1) battery packs power the DC motors. I used double sided sticky foam to hold the battery in place.

Start Running!

Bullet Bill Project: MAKECOURSE
IMG_7684.png

This is my project video that summarize the whole project. Feel free to watch but it is mostly the same information :)

With all the components in place and the code uploaded, its time to get chased by Bill!

Plug in the 9V battery to the Arduino to get the Arduino started, then turn on the battery packs. Once the battery packs are switched ON, Bill will start moving from the sensor's inputs.

Cover the middle sensor with your hand to stop the car from moving.

In order to get the best maneuverability, I had my Bullet Bill follow a flat Swiffer mop. This was done because of the physics behind reflecting rays and waves. The proximity sensor works by shooting an ultrasonic ping , and timing how long it takes for that ping to return to its receiver. If the surface that the ping hits is angled away from the sensor, that ping will never return to the sensor, and that output would be ignored. Having a flat surface perpendicular to the ultrasonic sensor produced the best results when testing.

I found that the best turning comes from hard tile/wood floor, with the tires removed from the wheel. The least amount of friction between the ground and the wheels gave the best turning and following results. The turning system may lock up with some carpets.

Final Thoughts and Known Issues

A few things to note is that there is always room for improvement, especially with this project. This was my first project/build and I learned a lot while working on it. One major takeaway is to not be scared to go back to the drawing board. There were a few times where I hit a roadblock and I had to redesign a part. There are also other times where I should have gone back for a redesign, but I was hesitant to reprint the entire project.

Some issues where my project can improve:

One limitation comes from the way the tracking system works. The reason I called it Proximity Tracking is because Bill will follow whatever objects trigger the sensors. This means that if Bill clips a wall a little too close, he will decide to run into the wall. To prevent this, I added a function in the code where he realizes he is running into a wall, and will reverse for just enough time to me sweep in and have it continue following me. It is not perfect, but it is a semi-solution that worked for me.

Another place for improvement is in the design of the cover. The bottom is lip is very fragile and easy to snap off. I had a feeling of this while modeling in SolidWorks, but I bit my tongue and thought I would be careful. I was not, and it broke off. Instead of going back and redesigning, I did some arts and craft work and whipped out the o'l hot glue gun. Going forward, I would re-design to add more support to the bottom lip, and overall try to avoid using a hot glue gun.

I would have designed the base with pre-printed holes to eliminate the need for a drill. I would have also designed a part to hold the battery holders and the 9V battery to avoid using sticky doos to hold it in place.

The turning capability is very mediocre with the tires on and on carpet. To improve, a more classical steering system where no wheels have to rotate backwards would provide more torque to drive on carpet.

Overall, I am very happy with how this project turned out. Bill follows my mop a lot better than I expected. This was a great leaning experience, and I can't wait to tackle more projects. Keep on tinkering!