top of page
Writer's pictureSarah Rashidi

Trick or Treat: Programming Spooky Door Surprises for Halloween

Updated: Nov 19, 2024

Hey there, spooky souls! 🎃 For those in the Halloween spirit, I hope you’re all ready for today’s hands-on blog! We’ll be taking you through a step-by-step guide on building your very own Door opener. But why a door opener, you ask? 🚪

Stick around, and you’ll uncover the magic of programming to solve everyday problems ensuring you have a hauntingly peaceful Halloween with no doorbell interruptions! 🦇


Ready to conjure up some code? Let’s dive in and get our hands boo-sy!👻

 

The Problem


Every Halloween, you're either stuck at home opening the door for trick-or-treaters, handing out candy nonstop, or constantly hearing the doorbell ring. Or maybe you’ve got plans like heading out for a Halloween dinner or even doing some trick-or-treating of your own. Either way, you’ll want a clever way to keep the candy flowing for those little goblins and ghouls without being tied to the door all night. Well luckily in today's blog our Spooky Door can come to the rescue 🦇👺!


What's the big Spooky Solution?


Yes you've heard it right , this Halloween we’re letting technology take over with our Spooky Door! 👻 With just a bit of setup and our friend Arduino, this project allows your door to open automatically whenever the doorbell rings. This way, those little goblins and ghouls can grab their candy without you needing to be there every time. It’s the ultimate Halloween hack to keep the treats flowing while you enjoy the night no interruptions required! 🧛‍♀️


About Arduino


Arduino is a beginner-friendly microcontroller, a small device that acts like the 'brain' for various electronic projects. Think of a microcontroller as a tiny computer that can run simple commands to control other parts, like sensors, motors, or lights. It’s what helps bring your code to life, allowing you to interact with the physical world through movement, sound, and light. You can easily find Arduino at most computer or electronics shops, so it’s super accessible for those just starting with electronics and programming!


Let's Build !


Not everyone has an Arduino (or its full kit) at hand—but don’t worry! Luckily, there’s a free alternative: Tinkercad. It is an online tool where you can design, simulate, and test electronic circuits virtually, letting you build and experiment without any hardware. To get started, simply sign up and create an account at Tinkercad.com. It’s easy to use and perfect for beginners!


After signing up and creating your Tinkercad account, go to Create a New Circuit. This will take you to an empty workspace where you can start building your project.


computer screen

As you can notice on the right side, you’ll find a search bar where you can type in the names of the components you need. Add each material, one by one, by dragging them onto the workspace. This makes it easy to assemble your circuit virtually, just like you would with physical components! There’s also a section where you can write code for your circuit, but don’t worry about that for now we’ll provide the code , so you’re all set even if you’re new to programming!


Materials Needed:



  • Arduino Uno and Servo Motor 

    computer part
  • Push Button

    puch button
  • 10kΩ Resistor 

    resistor settings
  • Breadboard 

    dashboard

  • Piezo Buzzer

    buzzer


Step-by-Step Assembly Instructions:


  • Servo Motor & Arduino Setup: ( In this case it is already setup but here's some explanation on how to connect it)

    • Connect the red wire (power) of the servo motor to the 5V pin on the Arduino.

    • Connect the brown or black wire (ground) to a GND pin on the Arduino.

    • Connect the yellow or orange wire (signal) to pin 9 (you can use a different pin but make sure to change it in the code and that it's not negative) on the Arduino for control.


  • Piezo Buzzer:

    • Connect the black wire (usually the negative side) to GND. This establishes a common ground with other components and completes the circuit for the buzzer.

    • Connect the red wire (positive side) to pin 10 (you can use a different pin but make sure to change it in the code and that it's not negative)  on the Arduino. This pin controls when the buzzer is activated, allowing it to emit sound based on the program logic.


  • Push Button:

    • Insert the push button into the breadboard. Ensure the pins are correctly placed so they do not short across the dividing line of the breadboard.

    • Connect one leg of the button to 5V on the Arduino.

    • Connect the opposite leg to pin 2 (you can use a different pin but make sure to change it in the code and that it's not negative)  on the Arduino. Place a 10kΩ resistor between this leg and GND on the breadboard to form a pull-down circuit.


Explanation of Connections:


  • Why Connect Buzzer Black Wire to GND: The black wire of the buzzer is connected to the ground because the ground serves as a reference point for the voltage supply, allowing current to flow when the buzzer is activated through its positive terminal. This helps complete the electrical circuit necessary for the buzzer to operate.


  • Why Connect Button to 5V and GND through a Resistor: Connecting one side of the button to 5V provides it with a voltage source. When the button is pressed, this voltage is directed to the connected input pin (pin 2). The resistor connected to ground ensures that when the button is not pressed, the input pin does not float, which would lead to uncertain or erratic readings. Instead, it pulls the pin to a stable LOW (0V) state.


The final outcome should look like this!


circuit

The Energy Part: Coding


Click on code and copy paste the code below.



#include <Servo.h>

Servo myServo; // Create servo object

int buttonPin = 2; // Button connected to digital pin 2

int buzzerPin = 13; // Buzzer connected to digital pin 10


void setup() {

myServo.attach(9); // Servo signal connected to pin 9

pinMode(buttonPin, INPUT); // Button pin as input

pinMode(buzzerPin, OUTPUT); // Buzzer pin as output

Serial.begin(9600); // Start serial communication

}


void loop() {

int buttonState = digitalRead(buttonPin); // Read the state of the button

if (buttonState == HIGH) {

Serial.println("Bell Rung & Door Opening");

tone(buzzerPin, 1000, 200); // Play a 1000 Hz tone for 200 ms

myServo.write(90); // Rotate servo to open position

delay(1000); // Delay while door is open

myServo.write(0); // Rotate servo to closed position

} else {

Serial.println("Door Closed");

noTone(buzzerPin); // Ensure no tone is playing

myServo.write(0); // Ensure servo is in the closed position

}

delay(200); // Debounce delay

}


Testing the Assembly:


Click on Start Simulation then

  1. Press the Button and observe:

    • The buzzer should emit a sound.

    • The servo should move to simulate opening a door.

  2. Release the Button and check:

    • The servo returns to the closed position.

    • The buzzer stops sounding.


computer screen


 

For those feeling a bit confused, no worries!


Here’s the link to the complete project setup: Tinkercad Project Link.

Make sure you’re signed up and logged into Tinkercad before clicking, and you’ll be directed to the full project with all the connections in place. This should help you visualize each part and make the setup easier to follow!

 

And there you have it your very own spooky, automated door opener! 🎉

With a little help from Arduino (using the simulation on Tinkercad), you've used the magic of programming to handle Halloween door duty like a pro, giving trick-or-treaters their candy while you enjoy the night without interruptions. Now you’re ready to scare up some fun while the tech handles the rest. Here’s to a hauntingly stress-free Halloween! 👻

Happy Halloween coding, and may your doorbell stay silent! 🦇


 

And with that, we reach the end of the blog. I hope you had a good read and learned a lot. Stay tuned as we'll cover more tech-related topics in future blogs .


Incase of any questions or suggestions, feel free to reach out to me via LinkedIn . I'm always open to fruitful discussions.🍏🦜




4 Comments


Guest
Oct 31, 2024

Extremely creative

Like
Sarah Rashidi
Sarah Rashidi
Oct 31, 2024
Replying to

Thank you!

Like

Guest
Oct 31, 2024

One of the best blogs!

Like
Sarah Rashidi
Sarah Rashidi
Oct 31, 2024
Replying to

Thank you sm!

Like
bottom of page