A Halloween Suprise
Happy Halloween!
The other day, my girlfriend and I were shopping for Halloween decorations and found an excellent decoration we liked. It was a tiny plastic spider, nothing special, but I knew I could do something cool with it the moment I saw it. So, I bought it, and when I arrived home, I started searching for my Arduino stuff to make something.
Making Up The Idea
When I was a child, my dad made a lot of cool stuff with Arduino, and I was always amazed by the things he could do with it. Looking for inspiration, I started searching for my old stuff. But I found some jumper cables, breadboard, Arduino Nano, motors, and sensors. I only have a weekend before Halloween, so I need to make something simple with the things that I have.
I wanted a decoration that could scare people, so I made a spider fall from the ceiling when someone passed by. This project has three requirements. I just need to make the spider:
- Detect when someone is near
- Fall from the ceiling quickly
- Return to the ceiling and wait for the next victim
Making The Spider
Let’s solve the second requirement first because it is the most relevant to do the trick. The best way to make the spider fall fast is to use gravity, so I glue the motor to a servo so I can rotate the motor and make the spider fall. This is the result:
Now, I need to make the spider detect when someone is near. Fortunately, I have a PIR HC-SR501 sensor that can detect when someone is close. I just need to connect the sensor to the Arduino to trigger the rotation of the servo so it can release the spider.
Finally, to solve the third requirement, I just need to rotate the servo again and start the motor to make the spider return to the ceiling. I would like to find a relay to control the motor. Still, I didn’t find it, so I used a keyboard switch to control the motor, which was not the best solution, but I didn’t have time to find a better solution. This is how the switch works:
As you can see, the motor presses the switch, so I need to rotate the servo a little bit more to push it and start the motor.
The prototype works; just pack everything and wait for the next victim.
As you may have noticed, I added cardboard padding and metal wires to the motor to prevent the spider from getting stuck between the motor and the plastic box. I also added a switch for the motor so it can be turned off when I’m not using it. I used two AA batteries to power the motor and a USB cable to power the Arduino. Now, I just need to put the spider in the ceiling and wait.
Another video from the final prototype:
The code
The code is pretty simple. I just need to read the sensor, rotate the servo when someone is near, and turn the servo again to press the switch and start the motor. I used the Servo library to control the servo and the delay
function to control the time between states. Here is the code:
I used a state machine to control the spider. I’m a Pythonist developer, so I enjoy writing verbose code, which helps others (and me) quickly understand what the code does. I also added a debug state to calibrate the servo angles, press the switch correctly, and release the spider.
The Halloween Surprise
The day arrived, and I was ready to scare some people. Here are some videos of the Halloween decorations:
Conclusion
This was a fun project; I could make something cool with the few things I had in just a weekend. I wonder what I could do with more time and materials; I will have to wait until next Halloween.
I hope you like it, and I hope you have a happy Halloween!