Metal Sweeper Robot













Many projects or jobs require the use of nails, screws, and other miscellaneous metal components that can easily be misplaced and fall to the floor. This can be a hassle to pick up – or even a health hazard. The goal of our project is to reduce inconvenience and provide a safer workspace for others by creating a device to sweep up metal.
This robot is designed to drive across the floor of a garage or shop and pick up screws, nails, and any other small items that will stick to a magnet.
Objective:
Utilize basic understanding of coding and physical construction in order to create a metal sweeper by following the instructions listed.
Supplies
For this project we mainly used items from Sparkfun's Inventor's kit. You can purchase one with an Arduino Uno here, or one with Sparkfun's own Redboard here.
Materials
- Magnets
- Batteries
- Tape
- Skewer/metal rod
- String/Paracord (for sweep loop)
- Extra motor (if sweep loop is desired)
- Sparkfun kit
- Breadboard
- Wires
- Both gear motors
- Wheels
- Double Sided Tape
- Arduino Uno
- Motor Controller
- Battery Bank
- Ultrasonic Sensor
Build options:
1) Budget friendly (Without 3D printer)
- Tape and glue
- Cardboard (approximately 100 square inches of cardboard required)
2) Utilizing 3D printer
- Substitute cardboard and tape/glue with 3D printing
We did create a .STL file for build option 2, but this Instructable will only be demonstrating build option 1. Fitment of 3D printed parts are not guaranteed to be perfect and may depend on what type of printer you are using.
Construct the Case





Build option 1: Using the CAD drawing, construct the outer casing for the device using any type of cardboard that is sturdy enough to house a microcontroller, wiring, two motors, and some magnets. Any typical shipping box would work just fine for this project.
Build option 2: Download the included .STL file for the structure/case and print it using a 3D printer.
Downloads
Wiring

.png)
To wire everything together, we will be using the breadboard included in the Sparkfun kit. Start by connecting the positive side of the breadboard to the 5V pin on your Arduino and then the negative side to one of the GND pins.
Next, attach the Sparkfun motor driver to the breadboard, then connect all of the following headers to each pin as follows:
PWMA -> pin 9
AI2 -> pin 3
AI1 -> pin 2
STBY -> pin 6
BI1 -> pin 4
BI2 -> pin 5
PWMB -> pin 10
GND -> negative/ground breadboard rail
VM -> Vin pin
VCC -> Power/positive breadboard rail
A01 -> Positive side of left wheel motor
A02 -> Negative side of left wheel motor
B02 -> Negative side of right wheel motor
B01 -> Positive side of left wheel motor
Next, we will need to wire the ultrasonic sensor. Refer to the diagram from Tinkercad and connect all of the sensor's headers to each location as follows, making sure to note the orientation of your pins.
GND -> Ground rail
ECHO -> pin 7
TRIG -> pin8
VCC -> Power rail
Code
Open up the software that you will use to program your microcontroller. Since we are using Arduino Uno, we will be using Arduino IDE to write the code.
First, we need to set up all of our global variables. These are all int variables that will be used to put a descriptive name to whichever pin a part of the circuit is connected to, so it's easier to debug.
Next, in the setup() portion of the code, we will need to tell the board how we want to use each of the pins. We will also set the serial speed as well as define a standard speed at 150.
Next, the loop. All we need it to do is tell the bot to move forward until it encounters an object in the way, in which case it will attempt to move around it.
You may have noticed there are a lot of commands in the loop, like getDistance(), for example. These are all functions (kind of like a subprocess) with their own section of code that we will need to define at some point in our code. Functions will also make the code cleaner and easier to read.
The first one is the getDistance() function, which uses the ultrasonic sensor to figure out how far away something is directly in front of it.
Next, we need a function to tell the bot how to move forward:
Next, we have a function for moving backward:
Next, we have a function to turn right (you can invert this to make it turn left).
Finally, we have a function to bring the motors to a stop.