Sensing Spider Prank (Wood Edition)
by jasonwinfilednz in Circuits > Arduino
835 Views, 9 Favorites, 0 Comments
Sensing Spider Prank (Wood Edition)
Halloween is coming and spiders are perfect for creating a good scare. This project can be either 3D printed or made from wood. A great and challenging introduction to Arduino that demonstrates a practical use of multiple inputs and outputs.
Using a PIR sensor our target is automatically detected and our spider deployed rapidly for the perfect fright.
Check the video links if you get stuck on a step these are timestamped so should go directly to the place you are at.
The project uses an Arduino UNO to sense our victim with a PIR sensor. Once they have been detected a small DC motor with a spool of cotton unwinds to deploy our spider. A microswitch keeps a check on our spider to make sure it doesn't get too carried away.
The project has STLs if you have access to a 3D printer or templates for cutting out on wood or a laser template for laser cutting.
If you are new to Arduino this is the perfect project to build something and see a practical outcome.
All the code is included and the parts should be readily available throughout the world.
Since building this project I have produced a significantly more in-depth guide. Although following this guide will work the new guide has improved code and wiring. You can find it here
Supplies
1 × PIR sensor HC-SR501
1 × DC motor driver MX1508
1 × DC motor1×Arduino Uno
1 × Microswitch KW11-3Z
1 × 9v Battery and snap connector
1 × MDF sheet 4.75mm thick approx 297x210mm
1 × Icecream container lid (plastic)
1 × Cotton Spool
1 × 6mm Dowel
4 × Large cable ties (5mm)
4 × Screws 3x6mm self tapping
1 × Cotton
1 × Toy spider approx 50-60mm wide
Cut Out Wood Chassis
There are two options to get the chassis cut out. You can either print the PDF called template.pdf and glue this onto a piece of 4.75mm MDF or you can use the forcutting.pdf and get the wood laser cut. The laser-cut file is designed in such a way that it should only take a few minutes to cut your wood. Either method will yield the same result. For more details see the video here
Glue Chassis Together
Glue the base of the chassis together starting with the back and the base. You should only need good PVA glue. Note that the holes further apart vertically on the back go to the left. For the base, the slotted hole goes to the right and the large hole on the left goes toward the back. For more details see the video here.
Add the left and right-hand side profiles. Note the profile with the holes goes on the right.
Glue the mounts for the Arduino on the back. I used nails to line up the holes but you could probably just do this by sight.
Glue the two motor mount cut-outs together then glue these to the base of the chassis between the two cable tie holes.
Mount the Arduino UNO
Prepare Spool
Hammer a length of dowel into the cotton spool and cut off the excess. Drill a small hole in end then carefully tap the spool onto your motor. This would be a good time to tie on one end of your cotton thread. For more details see the video here.
Install Motor
Wire the Motor Controller
Prepare the motor driver for installation. The motor driver can drive two motors but we only need to use one for this project. Add a length of wire to each of the MOTOR A outputs. These will eventually be connected to our motor. Add a length of wire to the + and - terminals of the board. Then a length of wire to IN1 and IN2. Put a header pin on all but the motor wires to make installation easier later on.
Install Motor Controller
Prepare the Paddle
The unit utilizes a paddle to tell the Arduino the spider has completed its journey. This should be made out of something flexible like plastic. I used an old ice cream container lid. Mark the paddle.pdf template out on a plastic lid and cut and drill the holes. For more details see the video here.
Downloads
Wire PIR Sensor
Install the PIR Sensor
The sensor assembly is made up of 3 wood cutouts, the sensor, and the paddle. Place the paddle at the bottom of the chassis then the two cut-outs that align with the sensor screws then the base plate. Thread screws through all components and fasten with nuts. There is a large hole in the base for the sensor wirws. For more details see the video here.
With all the paddle components in place pull the cotton through the slot and tie on your spider.
Install the Limit Microswitch
Complete Wiring
Following the diagram below pay careful attention to the polarity (red and black wires) wire the unit together, The color of the signal wires isn't important just use what you have laying around. The most important thing is to make sure you have the battery going to VIN, not to 5V otherwise you will cook your Arduino.
Upload Sketch
Copy and paste the following code into your Arduino IDE, no extra libraries are required.
// constants won't change. They're used here to set pin numbers:
const int PIRpin = 2;
//const int LEDpin =1; //digispark
const int LEDpin =13; //UNO
const int limitPin = 7; // the number of the pushbutton pin
//const int motorFWD = 0; //digispark
// const int motorREV = 4; //digispark
const int motorFWD = 5; //UNO
const int motorREV = 6; //UNO
const int frightDelay = 10000; //delay between actions
const int acceleration = 25; //how fast the motor starts to int acceleration delay in ms
// variables will change:
int limitState = 1; // variable for reading the pushbutton status
int PIRstate = 0;
int MOTdirection = 1;
int PWMValue = 200; // starting PWM value
void setup() { // initialize the LED pin as an output: pinMode(LEDpin, OUTPUT); pinMode(PIRpin, INPUT); pinMode(motorFWD, OUTPUT); pinMode(motorREV, OUTPUT); pinMode(limitPin, INPUT_PULLUP);
}
void loop() {
PIRstate = digitalRead(PIRpin);
if (PIRstate == HIGH ) { PWMValue=200; digitalWrite(LEDpin, HIGH); do { limitState = digitalRead(limitPin); driveMotor(); } while (limitState != 0); //state is 1 button is not activated
if (MOTdirection ==0){MOTdirection = 1;} else { MOTdirection = 0;}
stopMotor();
delay(500);
lockMotor();
delay(1000);
stopMotor();
delay(frightDelay); } digitalWrite(LEDpin, LOW);
}
void driveMotor(){
if (PWMValue < 255){++PWMValue;} delay(acceleration);
if (MOTdirection ==1)
{ analogWrite(motorFWD, PWMValue);
analogWrite(motorREV, 0);
}
else
{
analogWrite(motorFWD, 0);
analogWrite(motorREV, PWMValue);
}
}
void stopMotor(){
analogWrite(motorFWD, 0);
analogWrite(motorREV, 0);
}
void lockMotor(){
digitalWrite(motorFWD, 1);
digitalWrite(motorREV, 1);
}
Testing
Once you upload the code the motor will probably try and drive immediately as the PIR is high when it turns on. For testing, I suggest you attach the unit to the roof somewhere to prevent the tangling of the cotton. Check my testing in the video here for some tips.
Depending on the length of your thread, the weight of the spider, and the speed of the motor it might take a bit of tweaking to get the spider to drop and return to the full length of the thread. I suggest you check the principle of operation here: to get a goof idea of what is happening.
There are three main variables you can change.
frighdelay This is the time the spider waits between dropping. This value is milliseconds so 10000 is 10 seconds. Increase or decrease to your desire.
PWMvalue If the motor starts spinning at full speed the thread will double up on itself and the spider will drop a very short distance. The value is between 0 and 255. If you find the spider does not always fully unravel LOWERING this value makes the motor start slower. Keep increasing this value until you don't have the cotton binding on itself. If the speed for the whole journey is too slow the spider will not have enough momentum to trigger the limit switch at the end of the run.
Acceleration This is how fast the Arduino will increase the speed. This is in milliseconds. Tweaking between this value and the PWMvalue you should be able to find the sweet spot for your spider.
Notes about your spider Not all spiders are created equal. The weight and size of your spider will greatly affect how the project behaves. If your spider is too heavy it will unravel the web due to its weight. If it is too light it might not activate the limit switch. In my testing, the spider weighed around 6 grams.