Introduction: The Moving Door

Picture of The Moving Door

The project is called "The Moving Door." I created this project to let people hide small and valuable items. By placing your hand near a ultrasonic distance sensor and my servo motor will turn 175 degrees and the door will turn. Once you remove your hand the door will close.

Step 1: Parts/Materials

Picture of Parts/Materials

1. Arduino

2. Ultrasonic distance sensor

3. Wires

4. Alternative power supply

5. Servo motor

6. Cardboard

7. Glue

8. USB cable

Step 2: Code

#include

const int echpin = 4

const int trigPin = 2;

Servo myservo;

int pos = 0;

void setup() {

myservo.attach(8);

Serial.begin(9600);

pinMode(2, OUTPUT);

pinMode(4, INPUT);

while(! Serial);

Serial.println("speed 0 to 225"); }

void loop() {

long duration, inches;

delay(15);

digitalWrite(2, LOW);

delayMicroseconds(2);

digitalWrite(2, HIGH);

delayMicroseconds(5);

digitalWrite(2, LOW);

duration = pulseIn(4, HIGH);

inches = duration / 74 / 2;

Serial.println(inches);

delay(200);

if (inches < 5) { for (pos = 0; pos <= 180; pos += 1)

myservo.write(pos);

delay(15); }

if (inches > 5) { for (pos = 180; pos >= 0; pos -= 1)

myservo.write(pos);

delay(15);

}

}

Step 3: Setup

Picture of Setup

Comments

wienerjosh (author)2017-11-02

thnx

Swansong (author)2017-11-01

That's a fun class project, I hope you get an A :)

wienerjosh (author)2017-11-01

very well done

About This Instructable

84views

0favorites

More by wienerjosh:The Moving Door
Add instructable to: