Erica Jacobson
Published

Motion-Sensored Keepsake Box

Small box that opens when motion is detected.

BeginnerFull instructions provided156
Motion-Sensored Keepsake Box

Things used in this project

Hardware components

Acutronic Robotics L16-R Miniature Linear Actuator
×1
ELEGOO UNO R3 Project Complete Starter Kit
ELEGOO UNO R3 Project Complete Starter Kit
×1
LED (generic)
LED (generic)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Motion Sensored Box

Fritzing Schematic

Circuit Schematic

Code

Actuator_with_Sensor.ino

Arduino
#include <Servo.h>

Servo actuator;                           // this defines the new servo object as "acuator" and is what it will be referred to from now on
  int LEDpin = 13;                           // the LED is connected to pin 13 on arduino
  int PIRpin = 2;                           // the output of the PIR sensor is connected to pin 2 on arduino
  int PIRstat = 0;                           // initalizing PIR status
  
void setup() {
  actuator.attach(9); // the output of the actuator is connected to pin 9 on arduino
  pinMode(PIRpin, INPUT);                     // define the PIR sensor as the input
  pinMode(LEDpin, OUTPUT);                     // define the LED pin as the output that signals motion
  actuator.writeMicroseconds(1000);          // initiate a 1 ms pulse to retract actuator
  delay(10000);                                // 10 second delay to allow for actuator to retract completely
  Serial.begin(9600);
}
void loop(){
   PIRstat = digitalRead(PIRpin);           // define the status of the PIR sensor as the input of the PIR pin
   if (PIRstat == HIGH) {                      // if PIRstat is HIGH, motion is detected
     actuator.writeMicroseconds(2000);          // initiate a 2 ms pulse to fully extend actuator
     digitalWrite(LEDpin, HIGH);                 // turn LED ON
     Serial.println("Motion detected, Extend");           // reading on the serial monitor
     delay(30000);                                 // 30 second delay (5 of which is the actuator extending)
} 
 else {
     digitalWrite(LEDpin, LOW);                  // turn LED OFF
     actuator.writeMicroseconds(1000);               // 1 ms pulse to retract the actuator 
 }
}

Credits

Erica Jacobson

Erica Jacobson

2 projects • 0 followers

Comments