Jasonwinfieldnz
Published © GPL3+

Motion sensing spider dropper

Halloween is coming and spiders are perfect for creating a good scare. This project can be either 3D printed or made from wood.

IntermediateFull instructions provided2 hours152
Motion sensing spider dropper

Story

Read more

Custom parts and enclosures

STLs

STLs for 3D printing.

Schematics

Wiring diagram

Code

Sketch

Arduino
Arduino sketch to upload to Arduino UNO
// 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);
}

Credits

Jasonwinfieldnz

Jasonwinfieldnz

1 project • 1 follower

Comments