This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com).
New to Arduino's, 3D-printing, and computer-aided design (CAD)? This project is a great way to learn all the basics behind these topics and offers room for your creativity to make it your own! It features lots of CAD modeling for the boat's structure, an intro to autonomous systems, and introduces the concept of waterproofing 3D prints!
Step 1: Materials List
In order to begin the project, you first have to know what you'll be working with! Here are the materials you should have before you begin:
- 1x Arduino Uno R3 microcontroller and USB cable (Amazon Link)
- 1x L298N motor controller (Amazon Link)
- 4x (2 are backups) DC motors 3-6V (Amazon Link)
- 2x 28BYJ-48 Stepper motors and ULN2003 modules (Amazon Link)
- 1x Portable phone charger for power (Here's the one I used, it is a bit large though. You can use another one if preferred: Amazon Link)
- 1x Ultrasonic HCSR04 sensor (This link has a few extras thrown in with some jumper wires: Amazon Link)
- 3x Packs of Jumper wires (Male-female, male-male, female-female. Amazon Link)
- 1x Can of Flex Seal (16-oz, Amazon Link)
- 1x Painter's Tape (Amazon Link)
- 1x Fine Grit Sandpaper (around 300 is good)
- A few popsicle sticks and brushes for applying flex seal
- Access to 3D-printing. (Here's a relatively cheap and effective 3D-printer - Amazon Link)
Feel free to add any materials you come up with for your version of the project!
Step 2: 3D-Printed Parts and Design
The first part of this project is creating a mechanical system for it to work in. This would include many parts, including the hull, lid, paddles, axles for the motors to the paddles, a mount for the sensor, and the axle on which the sensor mount sits.
The components are designed in SolidWorks and put together into an assembly. All of the part files and the assembly have been put into a zip file, which can be found at the end of this step. Note that SolidWorks is not the only CAD software you can use, as many programs like Inventor and Fusion360 can be used for CAD. You could import SolidWorks parts into them.
It is important to note that the axles that hold the paddles are concentric with the holes on the hull to prevent bending the axle and having it go straight out of the boat.
Everything on this project is 3D printed (excluding electrical components), so dimensions are important. I gave tolerances of around 0.01 inches on parts, to ensure everything fits together (kinda like a loose fit). There was less tolerance for the axles going to the motor so they can fit snugly. The paddles are tightly fitted to the axle so that when the motors are set on, the paddles move and propel the boat.
When viewing the CAD, you'll notice platforms for electrical components. This is for the components to "pop" into their platform to prevent them from moving around.
The largest prints are the hull and lid, so be sure to keep this in mind when designing. You may have to split it into parts, as it would be too big to print at once.
Step 3: Control Circuit
Here we'll discuss the electrical circuit that controls the boat. I have a schematic from Fritzing, which is a helpful software you can download here. It helps with creating electrical schematics.
Not all of the components used in this project are in Fritzing, so they are replaced. The black photosensor represents the HCSR04 sensor and the small half bridge is the L298N motor controller.
The HCSR04 and L298N is connected to the power rails on the breadboard, which are in turn connected to the power side of the Arduino (on the 5V and ground pins). The echo and trigger pins of the HCSR04 go to pins 12 and 13 on the Arduino, respectively.
The enable pins (that control speed) for the L298 are connected to pins 10 and 11 (Enable A/Motor A) and 5 and 6 (ENB/Motor B). The power and grounds for the motors are then connected to ports on the L298N.
The Arduino will of course be receiving power from our portable phone charger. When the circuit is powered on, the motors are set at max speed in a direction dictated by our proximity sensor. This will be covered in the coding portion. This will move the boat.
Step 4: Arduino Code
Now we get to the nitty-gritty of what makes this project work: the code! I have attached a zip file containing the code for this project, which can be found at the end of this step. It is fully commented for you to look through!
- Code written for Arduino is written in a program known as the Arduino integrated development environment (IDE). It is something that you should download from Arduino's official website, which can be found here. The IDE is written in the C/C++ programming languages.
Code written and saved through the IDE is known as a sketch. Included in the sketches and class files and libraries you can include from online or those you created yourself. Detailed explanations of these and how to program in Arduino can be found here.
- As seen at the beginning of this step, I have a YouTube video going over the main sketch of the project, you can check it out here! This will go over the main sketch and its functions.
- I will now briefly go over the library I created for controlling the proximity sensor. The library makes it easy to get data from the sensor with less lines of code in my main sketch.
The .h file (HCSR04.h) is what lists the functions and variables that we will be using in this library and define who can access them. We start with a constructor, which is a line of code that defines an object (in our case, the "HCSR04ProxSensor" we're using) that holds values we input in the parentheses. These values will be the echo and trigger pins we're using, which will be tied to the sensor object we create (which can be named whatever we like by including "HCSR04ProxSensor NameOfOurObject"). Things within the "public" definition can be accessed by anything, both within the library and outside (like our main sketch). This is where we'll be listing our functions that we call in the main sketch. In "private" we store the variables that make the library run. These variables are only usable by the functions within our library. It's basically a way for our functions to keep track of what variables and values are associated with each sensor object we create.
Now we move to the "HCSR04.cpp" file. This is where we actually define our functions and variables and how they work. It is similar to if you were writing the code within your main sketch. Note that functions should be specified for what they return. For "readSensor()", it will return a number (as a float), so we define mark the function with "float HCSR04ProxSensor::readSensor()". Note that we must include "HCSR04ProxSensor::", the name of the object associated with this function. We define our pins using our constructor, find the distance of an object using the "readSensor()" function, and get our last read value with the "getLastValue()" function.
Step 5: 3D-Print All Parts and Assembly
Once the two pieces of the hull are printed, you can tape them together with painters tape. This should hold it together. You can then assembly all the other parts as normal based off our CAD design.
3D-printers run on g-code, which you can get from using a slicer software that comes with the printer. This software will take a .stl file (of a part you created in CAD) and convert it into code for the printer to read (the extension for this file varies among printers). Popular 3D-printing slicers include Cura, FlashPrint, and more!
When 3D-printing, it's important to know that it takes a lot of time, so be sure to plan accordingly. To avoid long print times and heavier parts, you can print with an infill of around 10%. Note that a higher infill will help against water intruding the print, as there will be less pores, but this will also make the parts heavier and take longer.
About all 3D-prints are not well suited for water, so we need to waterproof them. In this project, I chose applying Flex Seal, as it is pretty simple and works extremely well to keep water out of the print.
Step 6: Waterproofing the Print
Waterproofing this print is important, as you don't want your expensive electronics being damaged!
To start, we'll sand the outside and bottom of the hull. This is to create grooves for the flex seal to seep into, providing better protection. You can use some high grit/fine sandpaper. Be careful not to sand too much, a few strokes should be alright.
Step 7: Sanding the Hull
You'll know when to stop when you see the white lines begin to appear.
Step 8: Apply Flex Seal
You can use a popsicle stick or brush to apply the flex seal. Be sure to not miss any spots and be thorough. You can just dip your tool into the open can and rub it onto the hull.
Step 9: Let the Flex Seal Sit
Now we wait! Normally it takes about 3 hours for the flex seal to dry quite a bit, but I'd let it sit for 24 hours just to be sure. You can apply another coat of flex seal once it's finished drying to protect the hull even more, but this is a little overkill (1 layer worked great for me).
Step 10: Assembly and Testing
Now that the flex seal has finished drying, I'd recommend testing the hull in water before adding the electrical components (if the hull ISN'T waterproof, that could spell trouble for your Arduino!). Just take it to your sink or pool and see if the boat can float for more than 5 minutes without any leaks.
Once we make sure our hull is waterproof, we can start to add all of our parts! Make sure to wire the Arduino, L298N, and the rest of the components correctly to their proper pins.
In order to get wires fit to the DC motors, I soldered the male leads to the leads on the motor to ensure they stay on. Soldering is also useful for making sure all your connections are secure or if you need to make a longer wire. If you have never soldered before, you can learn more about it here!
Once everything is together, place all the components into the hull and do some testing! You'll want to check the sensor works as intended by reading distance values on the serial monitor, check motors are spinning correctly, things like that.
Step 11: Final Product
And now you're done! Check for any errors in a test drive (test float the boat and hull before applying electronics) and you're set!