Introduction: ITT Advent Calender

This is made for a school assignment where i'm making a automatic advent calendar to keep children hands away from opening the precious gifts before their time.

There is no wooden house, but you can make one yourself with small doors. In here there will be a prototype door you can make for an opening and closing a door.

Step 1: Things You Need:

-something that can simulate a door. i used meccano to build a simple door structure.

-arduino yun

-electric tube

- a strong long object that can fit trough the electric tube ( i used a core of a coil)

-metal wire

- a red and green led

-resistors

-strip board

-Pushbutton

-6 breadboard jumper wires

- tg9e Micro Servo

-a lot of tiewraps

-external powerbank for your audrino

Step 2: Make and Assemble

cut the electric tube into two pieces and assemble one part
on the door itself and the other part on the frame by using tie wraps. For this project you can use glue as well, but it will be a lot harder to remove and reuse the objects afterwards. Make sure that the electric tube are perfectly aligned. If not there might be a chance that the metal wire in between the core and the servo will bend itself on activation. To avoid this I added a spring inside the door that acts like a door closer, it forced the door to close on its own.

I use the coil to lock the door, but you can use anything else that is firm enough to last a blow. Use a small piece of metal wire on the end side of the core and the micro servo. Make sure that the wire translates the rotating movement into either a pushing or pulling motion by shaping it into a Z. You don't want this material to be too strong or too weak. If it's too weak it will have not have enough pushing power and will bend itself. If it is too strong and something goes wrong neither the lock or wire will give. This will cause the engine to block or break If it uses too much force.

Place the resistors, jumper wires, led lights and button on the -strip board and cut of the access space you don’t need. I added a small base below the button so I don’t have to solder the button to the board (that would be a waste for me).You on the other hand can solder it straight to the board. You can separate the lights from the button if you want to place it somewhere else. For convenience sake I didn’t do this. After cutting away the access you can start solder the components together to make it rigid. After you’re done you can assemble the cords back to the Arduino. Be sure that everything is placed correctly to avoid malfunctioning code.

Step 3: Code

you're ready when your arduino is ready to go with this code:

#include

int inPin = 2;
int outPin = 11;

int state = HIGH;

int reading;

int previous = LOW;

long time = 0;

long debounce = 200;

Servo myServo; void setup() {

pinMode(inPin, INPUT);

pinMode(outPin, OUTPUT);

pinMode(10, OUTPUT);

myServo.attach(9);

}

void loop() {

reading = digitalRead(inPin);

if (reading == HIGH && previous == LOW && millis() - time > debounce) {

if (state == HIGH)

state = LOW;

else

state = HIGH;

time = millis();

}

if(state){

digitalWrite(outPin, true);

digitalWrite(10, false);

myServo.write(60);

}

else{

digitalWrite(outPin, false);

digitalWrite(10, true);

myServo.write(0);

}

previous = reading;

}