Metal Sweeper Robot

by johnumomu in Circuits > Arduino

52 Views, 1 Favorites, 0 Comments

Metal Sweeper Robot

image-20250422-013837-838f54d7.jpeg
How to make the metal sweeper
Metal Sweeper
image-20250422-013827-7100e665.jpeg
image-20250422-013832-4531640c.jpeg
image-20250422-013837-838f54d7.jpeg
image-20250422-015545-a9c52601.jpeg
image-20250422-015610-1fc2e130.jpeg
image-20250422-015614-357fc394.jpeg
image-20250422-015616-7b1bbc1d.jpeg
image-20250422-015647-9c532e2d.jpeg
image-20250422-020028-ee140dec.jpeg
image-20250422-020146-725774ba.jpeg

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

  1. Magnets
  2. Batteries
  3. Tape
  4. Skewer/metal rod
  5. String/Paracord (for sweep loop)
  6. Extra motor (if sweep loop is desired)
  7. Sparkfun kit
  8. Breadboard
  9. Wires
  10. Both gear motors
  11. Wheels
  12. Double Sided Tape
  13. Arduino Uno
  14. Motor Controller
  15. Battery Bank
  16. Ultrasonic Sensor


Build options:

1) Budget friendly (Without 3D printer)

  1. Tape and glue
  2. Cardboard (approximately 100 square inches of cardboard required)

2) Utilizing 3D printer

  1. 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

exploded.gif
4.jpg
3.jpg
2.jpg
1.jpg

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.

Wiring

image-20250422-015616-7b1bbc1d.jpeg
Fantastic Gogo (1).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.


// Left Wheel

int AIN1 = 2;

int AIN2 = 3;

int PWMA = 9;


// Right wheel

int BIN1 = 4;

int BIN2 = 5;

int PWMB = 10;


int STBY = 6; // Standby pin(found this using gpt to define a set loop for my

// group project so we can raster defined shapes)


// USSensor (this was stretch goal for project, used lab to understand ints needed)

const int trigPin = 8;

const int echoPin = 7;


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.

void setup() {

// Pins for motors, all outputs

pinMode(AIN1, OUTPUT);

pinMode(AIN2, OUTPUT);

pinMode(PWMA, OUTPUT);


pinMode(BIN1, OUTPUT);

pinMode(BIN2, OUTPUT);

pinMode(PWMB, OUTPUT);


pinMode(STBY, OUTPUT);


// USSensor Pins

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);


Serial.begin(9600); //mostly used to find distances required to see and turn

//with acceptable space for project


int speed=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.

void loop() {

int distance = getDistance();


Serial.print("Object is: ");

Serial.print(distance);

Serial.println(" cm away");


if (distance > 10) { //Guessed double the necesssary length of magnet

moveForward(100); // 0–255, used this for practice whilst hardlined

} else {

delay(500);

turnRight(150);

delay(500);

}


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.

// Distance value

int getDistance() {

digitalWrite(trigPin, LOW);

delayMicroseconds(1);


digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);


int duration = pulseIn(echoPin, HIGH);

int distance = duration * 0.034 / 2; // gpt gave this as speed of sound/micro div2

return distance;

}


Next, we need a function to tell the bot how to move forward:

void moveForward(int speed) {

digitalWrite(STBY, HIGH);


digitalWrite(AIN1, HIGH);

digitalWrite(AIN2, LOW);

analogWrite(PWMA, speed);


digitalWrite(BIN1, HIGH);

digitalWrite(BIN2, LOW);

analogWrite(PWMB, speed);

}


Next, we have a function for moving backward:

void moveBackward(int speed) {

digitalWrite(STBY, HIGH);


digitalWrite(AIN1, LOW);

digitalWrite(AIN2, HIGH);

analogWrite(PWMA, speed);


digitalWrite(BIN1, LOW);

digitalWrite(BIN2, HIGH);

analogWrite(PWMB, speed);

}


Next, we have a function to turn right (you can invert this to make it turn left).

void turnRight(int speed) {

digitalWrite(STBY, HIGH);


// Left motor forward

digitalWrite(AIN1, HIGH);

digitalWrite(AIN2, LOW);

analogWrite(PWMA, speed);


// Right motor backward

digitalWrite(BIN1, LOW);

digitalWrite(BIN2, HIGH);

analogWrite(PWMB, speed);

}


Finally, we have a function to bring the motors to a stop.

void stopMotors() {

digitalWrite(STBY, LOW); // Puts the motors in standby (stops all)

}