Devices & Components
Arduino Uno Rev3
DS04-NFC 360 degree continuously rotating DC servo
Breadboard (generic)
180 Degree Servo Motor HS-311
Ultrasonic Sensor - HC-SR04 (Generic)
Project description
Code
Spider Dropper Arduino Uno code
arduino
Very simple code for programming your arduino uno for this project
1#include <Servo.h> 2#include <NewPing.h> 3 4#define TRIGGER_PIN 7 // Arduino pin tied to trigger pin on the ultrasonic sensor. 5#define ECHO_PIN 7 // Arduino pin tied to echo pin on the ultrasonice sensor. 6#define MAX_DISTANCE 200 // Maximum distance we want to ping fro (in centimeters). Maximum sensor distance is rated at 400-500cm. 7 8NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maxium distance. 9 10Servo drop; //180 degree servo 11Servo lift; //continuous rotation servo 12int state = 0; // state of 0 means don't drop the spider again until no one is in front of the ping senser - e.g. a "debounce" 13 14int storeCM = 0; 15 16//Important Variables to Addjust! 17int tripdistance = 40; //drop spider when object is within 40 CM of Ping Sensor! 18int lifttime = 16000; // 100 = 1 Second. Depending on how long you string is and/or how high up your want the spider, adjust this time to lift the spider back up! 19 20 21void setup() { 22 Serial.begin(115200); 23 drop.attach(9); // attach the "Drop" servo (the 180 degree servo) on Digital Pin 9 24 lift.attach(10); // attach the "Lift" servo (the continuous rotation servo) on Digital Pin 10 25 drop.write(150); // drop to make sure the spider is down 26 delay(1000); 27 drop.write(80); 28 lift.write(180); // lift the spider up on startup 29 delay(lifttime); 30 lift.write(90); 31 32} 33 34void loop() { 35 Serial.print("Distance: "); 36 Serial.println(sonar.ping_cm()); // Send ping, get distance in cm and print result ( 0 = outside set distance range) 37 storeCM=sonar.ping_cm(); 38 39 if(storeCM <= tripdistance && storeCM > 3 && state == 1) { 40 Serial.println("DROP THE SPIDER!"); 41 drop.write(150); //Drop the Spider! 42 delay(5000); // wait 5 seconds until we lift the spider up by winding string 43 drop.write(80); // position to lift the spider up by winding string 44 lift.write(180); 45 delay(lifttime); //lifting the spider 46 lift.write(90); // stop lifting the spider 47 delay(1000); 48 delay(100); 49 state = 0; 50 } 51 52 if(storeCM > tripdistance && state == 0) { 53 state = 1; 54 } 55 56}
Downloadable files
Wire Layout
Wire Layout

Wire Layout
Wire Layout

Comments
Only logged in users can leave comments