MineGuard
I was responsible for doing the stepper motor calculations, getting the stepper motor to work with a battery, the code for the spider rising and falling as well as the ultrasonic sensor code schema (my classmates made revisions), and the spool design. Gillian made the box, and Kaz made the spider. Problems with the design include the spider seeing itself. This could've been solved with an infared sensor, however, I could not manage to get even the sample code to run. Our instructor said he also had trouble getting the infared sensor we had in the lab to work, too. The spider sees itself because the ultrasonic sensor detects the spider, too. I think a slightly better/easier to use infared sensor could have made this a fully functional project.
I used quarter steps for the stepper motor to ensure a less jerky movement. View the stepper driver configuration below (src here).
I used pins D12 & D13 for the ultrasonic sensor. It's important to ensure that the pins being used aren't also being used for the stepper motor (using the pins on the right side is a safe choice). I also plugged in the sensor to the 5V and GND pins on the right side of the shield. The battery (or whatever 12V power source used) actually powers the Arduino too.
The finished wiring (battery not shown, battery replaces plug-in).
1 revolution total length of string if spindle has a radius of 0.79 in =
=4.96 inch circumference (spider falls 4.96 inches/revolution)
Full step = 200 steps per revolution
Quarter step = 800 steps per revolution
Find inches per step:
4.96/800 = 0.0062 inches/step
Solve for x (number of steps):
0.0062 * x = 84 inches(7’)
84 / 0.0062 = 13548 steps for the spider to fall 7 feet in quarter step mode
we'll make it 12000 just to be safe lol, using excess string would be bad
#include "Ultrasonic.h"
/*
Pass as a parameter the trigger and echo pin, respectively,
or only the signal pin (for sensors 3 pins), like:
Ultrasonic ultrasonic(13);
*/
Ultrasonic ultrasonic(12, 13);
int distance;
int headHeight = 24; // in inches
void setup() {
Serial.begin(9600);
}
int increment = 0;
void loop() {
// Pass INC as a parameter to get the distance in inches
distance = ultrasonic.read(INC);
Serial.print("Distance in Inches: ");
Serial.println(distance);
// make an incrementor, increment goes up for each distance less than 24, if the increment reaches 5 (on i=5),
// deploy
if (distance < headHeight) {
increment++;
Serial.println(increment);
if (increment == 5) {
Serial.println("deploy spider");
increment = 0;
}
} else{
Serial.println("dont deploy spider");
}
delay(5000);
}
// Basic CNC shield stepper motor example.
#include "Ultrasonic.h"
/*
Pass as a parameter the trigger and echo pin, respectively,
or only the signal pin (for sensors 3 pins), like:
Ultrasonic ultrasonic(13);
*/
Ultrasonic ultrasonic(12, 13);
int distance;
int headHeight = 24; // in inches
// motor stuff
int enablePin = 8;
int stepPin = 2;
int dirPin = 5;
int dir = LOW;
int speed =1000; // Steps per second
int dist = 12000; // Total number of steps to move (approx 6 feet)
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(enablePin,OUTPUT);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
// do the code below to ensure the motor isn't trying to spin before
// we meet the conditions for deploying the spider
digitalWrite(enablePin,HIGH);
digitalWrite(stepPin, LOW);
digitalWrite(dirPin, dir);
}
int increment = 0;
void loop() {
distance = ultrasonic.read(INC);
Serial.print("Distance in Inches: ");
Serial.println(distance);
// make an incrementor, increment goes up for each distance less than 24, if the increment reaches 5 (on i=5),
// deploy
if (distance < headHeight) {
increment++;
Serial.println(increment);
// on the 5th read less than 24 inches, start the motor running code
if (increment == 5) {
Serial.println("deploy spider");
digitalWrite(enablePin, LOW); // start motor
digitalWrite(dirPin,dir);
for (int i = 0; i < dist; i++) {
digitalWrite(stepPin, LOW);
delayMicroseconds(300);
digitalWrite(stepPin, HIGH);
delayMicroseconds(300);
}
delay(10000);
dir = !dir;
for (int i = 0; i < dist; i++) {
digitalWrite(stepPin, LOW);
delayMicroseconds(500); // a bit slower when going up
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
}
digitalWrite(enablePin, HIGH); // disable motor after move
increment = 0;
delay(10000); // delay after spider has been deployed
}
} else{
Serial.println("dont deploy spider");
}
delay(5000);
}
We made the hole measurement by measuring the shaft of the stepper motor in mm. We accounted for (measured) the flat edge of the stepper motor, too, so this design fits very snugly on the stepper.
Next, we made a larger circle near the hole, and a smaller circle moved 12 mm above. This will make our desired "yoyo" shape that would keep the string in place.
Next, we used the loft tool to connect the 2 circles. Extrude the tiny hole sketch in the negative direction to make a hole in this body.
We copied that body and rotated it 180 degrees. Extrude the smaller circle at the bottom, which is where the string will rotate around.
The final design.
Unfortunately, we didn't end up using this design becaue it was too large for our box, and we already had the maxmimum amount of space filled up inside the box.