This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)
This is my final project for the Make Course at USF. We were able to build anything we wanted, as long as it operated with the Arduino platform. With Star Wars being a big thing right now, I decided to create my own BB8 Droid. I'll show you the process of how I created the BB8 Droid.
Step 1: Design and 3D Print
Designing is the first step in figuring out how your project will work. For me, I gathered a bunch of ideas online and put my ideas to work. I used AutoCAD Inventor to design the BB8 Droid and all the files are available below. My approach was similar to some designs, but with some minor twists. All the parts were 3D printed for this project.
- The BB8 Core_Body file will be the core of the project, it will house the electronics and be the main focus point of this project.
- The BB8 Core_Body Motor 1 file is an additional file to use if you are using different motors.
- The BB8 Core_Top file is the top piece to the body. The Arduino will be screwed down onto it and will also have the magnets and support wheels attached to it.
- The Top Custom Wheel file are the wheels that will be used a supports. They will connect to the top part in the side slots.
- The BB8 Design Thread 1 & 2 are the half spheres that have threaded ends and can be screwed together. These will eventually encase the core and will roll around.
- The BB8 Head file is the head of the droid. This will attach to the ball by using magnets. There are pockets that were created to fit magnets into them.
I added both the AutoDesk Inventor file and the STL file. So you can open and change the file however you need it or you can go ahead and print what I have here.
- BB8 Core_Body.ipt
- BB8 Core_Body.stl
- BB8 Design Thread.ipt
- BB8 Core_Top.ipt
- BB8 Design Thread_2.ipt
- BB8 Design Thread_2.stl
- BB8 Core_Top.stl
- BB8 Design Thread.stl
- BB8 Head.ipt
- BB8 Head.stl
- Top Custom Wheel 1.5mm.ipt
- Top Custom Wheel 1.5mm.stl
- BB8 Core_Body_Motor_1.ipt
- BB8 Core_Body_Motor_1.stl
Step 2: Gather Materials
Deciding on parts can take some time, so you want to make sure you get the right ones. For this project, I wanted to get components that were simple to use. Below, you can see all the parts I needed to get my BB8 rolling.
- Arduino Uno R3
- L298N Motor Driver
- MPU-6050 Accelerometer Gyroscope
- HC-06 Wireless Bluetooth Module
- 7.4v Lipo Battery
- Lipo Battery Charger
- (2) 17mm Rubber Wheel (1.5mm Bore)
- (2) 10mm x 3mm Neodymium Magnets
- 1.5mm metal rod
- Female to Male Wire Jumpers
- (2) 3-6v DC Motors (1.5mm Shaft)
- Lead Weights
- Circuit Wire
- (4) 2mm Screws
- (4) 2.5mm Screws
- (4) 3mm Screws
- (2) 2mm Washers
- All Purpose Putty
- Contact Cemente
- Super Glue
- Grey Primer Spray Paint
- Black, White, Orange, Grey, Clear Spray Paint
- Plastidip or Flexidip
- Micro Breadboard
- Velcro Strips
- Precision Bit Screwdriver Set
- Electric Drill
- 2mm, 2.5mm, 3mm Drill Bits
- Electrical Tape
- Painters Tape
- 120 Grit, 200 Grit Sandpaper
Step 3: Build the Circuit
Breadboarding and testing the circuit is always a good step to do. It allows you to find any problems and/or make changes. I did this to verify proper operation of each component and also to test out code.
MPU6050 Accelerometer Gyroscope:
This device will be used to determine the angle of the BB8 head. In order to keep the head in the upright position.
HC-06 BlueTooth Module:
This device will be used to accept direction commands from the phone to the Arduino to control the motors on the BB8 Core. A voltage divider will need to be used to protect the HC-06 from the high voltage on the Arduino. Check out the circuit diagram to see the configuration.
L298N Motor Driver:
This device is used to control the two DC motors with PWM signals from the Arduino. The motors will operate to the desired directions from the app and the readings from the MPU6050.
The Arduino Uno will be used as the brain for the whole system. The code is designed to bring all the functionality of the devices together and work in a orderly function.
I will explain the functionality of my circuit below:
The smartphone will use the Joystick BlueTooth Commander app to connect to the HC-06 and send direction commands to the Arduino. The Arduino will read these values from the HC-06 and send a response to the L298N motor driver. The motor driver will begin to spin the wheels forwards or backwards, based on the sent signal. The MPU6050 Accelerometer Gyroscope will keep track of the angle position BB8 is currently in. If the angle reaches past a threshold, once the system stops, the motor driver will automatically turn the motors on in the needed direction to get to the upright position. To turn left or right, the system will operate similar to that of a tank. If you want to turn, one of the motors will need to slow down in order to create a turning direction.
Step 4: Prepare the Code
In order to use this code, you will need a couple libraries for the Arduino IDE. You will need the PID, I2CDev, and MPU6050 libraries. These libraries were created by some smart people, so be sure to thank them. Jeff Rowberg created the libraries for the MPU6050 and I2CDev. Brett Beauregard created the PID library. I took the time to go through the example and header files to fully understand the code and figure out how it all works.
- To start, upload these libraries to your Arduino IDE.
- Start with the MPU6050, we will need to test and calibrate this device before operation.
- To test it, use the example code in the MPU6050 folder under Example >> MPU6050_DMP6. This code will allow you to test the device and verify proper operation. The code is set to display the yaw, pitch, and roll data to you through the serial port on the Arduino.
- Once testing is completed and successful, open the MPU6050 calibration folder and open the Arduino file. This file will calibrate the MPU6050 to its given position, so be sure to place it on a flat surface. The calibration time can take a few minutes, if it freezes up just restart it. It will give you offset values that will set your MPU6050 close to the zero origin, the only value that is large is the Z-axis accelerometer value because of gravity. Take these values and plug them into the code for the MPU6050_DMP6 raw test. Your readings should be a lot more accurate.
- The HC-06 device can be configured to display a desired name, have a desired password, and operate at a desired baud rate. To change this, use the BlueTooth_Example_Code file. Take a look at the PDF provided, this includes commands that will allow you to change the name and baud rate of the device. Changing the name of the device is optional, but I recommend changing the baud rate to 57600. All commands will be sent through the serial port on the Arduino IDE once the HC-06 is connected and the code is uploaded and running.
- The app that I used for this project is called the "Joystick Bluetooth Commander". This app is available on the Google app store. If you decide to use any other bluetooth application, you will need to use different code.
- Use the BlueTooth_Joystick_App_Code file to test that you are obtaining data from the app. You will need to pair the HC-06 device with your phone prior to testing. The code for the HC-06 will most likely be 1234 or 0000 by default
- To test the motors, use the Motor_Code_Example file. This file will allow you to run the motors and determine smallest PWM signal that will get them to start turning. Tuning the motors is needed because not all motors start or turn at the same rate.
Once all the initial testing is completed, you can move on to the New_BB8_Code file. You will need to verify pin connections, MPU6050 offsets, and HC-06 baud rate. Once that is done, you can upload the code and test everything out. The code is designed to allow the user to control the direction that BB8 will role while keeping the head in the upright position. The PID will need to be tuned but cant be until the core is assembled.
I will explain the functions of the code below:
- init_imu(); - This is used to initiate the MPU6050 and set the ideal settings. This was taken from the MPU6050 example code.
- motorSetup(); - This is used to set all the pins for the motor driver to outputs.
- getValues(); - This is used to obtain the readings for the yaw, pitch, and roll from the MPU6050.
- blueTooth(); - This is used to setup the HC-06 and receive the data from the app on the phone.
- pidCompute(); - This is used to run the PID controller in order to tune to the setpoint and produce a PWM signal for the motors.
- motorControl(); This is used to control BB8 in the desired direction and also send PWM signals to keep the head in the upward position.
Step 5: Assemble the Core
The inside of the BB8 Droid is what I like to call the Core. It houses all the components and is the main part for getting BB8 to roll.
- Start with placing the motors in the side pockets of the core, feed the wiring through the pre-made holes and place the wheels on the motor shaft.
- Use the Electric Drill to make pre-made holes for the L298N Motor Driver, MPU6050, and the Arduino Uno.
- Place the L298N Motor Driver inside the core and screw it down. Connect the motor wires to the L298N.
- Place the MPU6050 on the side platform and screw it down.
- Place the HC-06 Bluetooth Module on the other side platform, it doesn't have screw holes so I used Velcro strips to hold it down.
- Place the 7.4v Lipo battery in the pocket near the front. Make sure the wires are out in the open.
- Now use the Dremel and cut little holes on the sides on the top piece of the core. This will be used to feed wires through.
- Connect all the female to male jumper wires to the components, I used electrical tape to keep the wires clean and organized.
- Create a voltage divider out of the Receive signal for the HC-06. This is needed to protect the HC-06 from high voltage Arduino signal. Use the micro breadboard and two resistors to do this. The Receive wire from the Arduino will connect to the larger resistor. The smaller resistor will connect to the other end of the larger resistor and to the ground. The Receive wire for the HC-06 will connect to the Receive pin on the HC-06 and the connecting point between the two resistors.
- Make sure the L298N Power and Ground wires are out in the open too.
- Feed all the wires through the holes of the top piece, be sure to manage them nicely and place them closes to the Arduino pin it will be connecting to.
- Screw down the top piece to the core, keep in mind the power and ground wires from the L298N and battery need to be hanging to the side.
- Start connecting the wires to the correct Arduino pins. You may have to look back inside the core to see where the wire is coming from.
- The 3D printed wheels need to be sprayed with Plastidip or Flexidip, I did this to provide a little bit of traction to them.
- Take the metal rod and place it into the pre-made holes on the top part of the core. Measure how long the piece needs to be to get from one hole to the other. It should be about 12mm. Cut the piece off, this will be used as the axle for the 3D printed wheels.
- Place a washer towards the outside of the wheels on the axle. This helps the wheels from rubbing on the side brace.
- Glue the axle in with super glue or contact cement.
- Glue the neodymium magnets in the top pockets of the top core piece. Magnets will also be placed in the pockets on BB8's head.
- Place a soft part of the Velcro strip on the front and back end of the core, this will help with noise.
- Use the Dremel to cut pockets in the bottom of the core, this is where the lead weights will go. This will work as a counter balance.
Now the core should be assembled, I designed it this way to allow easy access to program the Arduino and charging the battery.
Step 6: Prepare the Ball and Head
3D printing is not always perfect. The half sphere prints were a little warped from the printing process, so I used the putty and filled in holes, divots, and bumps. Once the putty is dry, use the sandpaper to smooth it out and create a nice even circle shape.
- To begin painting, we need to prime. Use the primer to spray the sphere pieces and head with it. Put on a good first coat and wait for it to dry.
- Once dry, do some wet sanding. This will help to hide the 3D print layer look from the pieces.
- Add one more coat of primer to all the pieces. Wait for a complete dry.
- Grab the white spray paint and paint outside of the spheres and the head. Use the painters tape to avoid places you don't want the paint, like the inside of the spheres and the threads. Wait until a complete dry.
- Use scissors and cut out the stencils for the BB8 designs.
- Screw the two shperes together.
- Start with the inner circle design, place the stencil on the ball and use the grey spray paint to create the design. You will do this six times. Let the paint dry before moving on to the next one.
- Once done with the grey designs, cut out the inner part of the orange circle. This will be used as a shield for the grey designs.
- Cover the grey design with the inner stencil, use painters tape where needed. Create a outer circle stencil, this will be used to make the orange circle the right size.
- Once the stencils are placed, use the orange spray paint. Wait for a complete dry before moving on to the next one. You will do this six times.
- To paint the BB8 head, I used the painters tape to create the designs. I covered the rest of the head with tape to avoid getting the paint in the wrong areas.
- You will have to wait for the paint to dry before moving on to the next design. Once the paint is fully dried, cover that spot with painters tape and work on the next design.
- Once both parts are fully painted, use the clear coat spray and apply a layer of paint on the ball and head. Wait for a complete dry before adding another coat. This is used to protect the spray paint from getting scratches when rolling around.
- Use the Plastidip or Flexidip and spray a thin layer inside the two half sphere pieces. Use painters tape to avoid getting the spray on the threads and outside of the ball. This is used to provide a decent grip for the wheels on the core.
- To finalize the head, cut a white jumper wire in half and super glue it to the back part of the head. This will act as an antenna for BB8. Use another white jumper wire for the other antenna too.
You should now have a fully painted BB8 that is ready for operation.
Step 7: Bring It All Together
Now that the code is set up, the core is assembled, and the ball and head are finished, lets bring it all together and get a working project. Tuning the PID controller will be included in this step.
- Place the core inside the half sphere, make sure that the wheels touch the inside of the sphere. Make sure there is some pressure but not too much, the core needs to be able to grab the ball but also be able to move.
- Plug in the battery on the core and upload the New_BB8_Code file. This will be used to tune the PID controller.
- Screw the other half of the sphere on to enclose the core inside the ball. Place the head on top of the ball where the magnets are.
- To tune the PID controller, there is a long but decent way to approach it. For those who don't know a PID controller is used to determine what speed the motors should run so the BB8 head will be in the upright position. The PID controller will have an input, output, and setpoint. The input will come from the MPU6050. The setpoint is the desired angle of the head, in this case 0 degrees is desired. The output is the changed input to get close to the setpoint.
- Set all PID constants to zero.
- Slowly increase the P-constant value. Keep increasing this until the motors respond quickly to tilting.
- Now increase the I-constant. This should be a low value. It accumulates errors quickly over time.
- Raise the D-constant. The derivative component works against motion, so it helps to dampen any oscillations and reduce overshooting.
- Spend a good amount of time tuning the PID controller until the motors respond smoothly to movement.
- Now once the PID controller is tuned, you should be able to connect the app to the HC-06, upload the correct code, and begin to start attempting to control your BB8. Some issues may come up that need to be worked out.
- A major issue that happened to me was that the magnets were to strong and lifted the core inside the ball. This prevented the bottom wheels from touching the inside of the ball, so BB8 wasn't able to roll. To fix this, try extending out the motors from the pocket their in so that the wheels touch the inside of the ball. This is what fixed my problem.
The BB8 should be ready to go. Get the battery all charged up and connected to the phone. Start trying to control him and drive him where desired. If all goes well, BB8 should roll around at a nice smooth rate. If problems occur, do your best to determine the issue and fix it.
Step 8: Possible Improvements
Implement an X-axis Balancing System in Code:
- The BB8 Droid currently only reacts to Y-axis changes. So to correct the head position, the motors will just simply spin in the forward or backwards position based on the current angle. Some of the code is already added to implement an X-axis system but it will require a little more time to figure out a good coding approach.
Find Better Drive Wheels:
- The wheels I am currently using tend to slip a little bit and shred easily. Maybe finding a firmer rubber material will help. It was the only 17mm wheel I could find at the time.
Use Higher Torque Motors:
- With the motors I am using now, the BB8 droid sometimes needs a little push to get going. Finding high torque motors of small size is hard to find. Another option is to use a gearing system.
Include BB8 Sounds:
- I found audio files of all the different BB8 sounds. If someone wanted to they could create a little sound box to play these audio files. This wouldn't be to bad to implement because the app has six buttons that can be programmed to do anything. They could be used to play these audio files when the button is pressed. All you would need is another Arduino Uno, SD card reader adapter, Speaker, Black Box, wires, and a 9v battery.