Arduino Motorized Opening Coffin for Halloween

by RC3459345 in Living > Halloween

1667 Views, 2 Favorites, 0 Comments

Arduino Motorized Opening Coffin for Halloween

Coffin-Opening-Square.2.gif
PJRZ3877.JPG

A full-sized, motorized coffin that automatically opens and plays sounds when trick-or-treaters walk by.

The Arduino-controlled coffin opens when a motion sensor detects trick-or-treaters. As the coffin opens, a creaking-door sound is played and a skeleton sits up. The skeleton laughs fiendishly and its red eyes illuminate.

Downloads

Supplies

  1. Coffin
  2. Plywood board 1/2 inch
  3. 6 feet of 2x2
  4. Hinges (x3)
  5. One-Coat Exterior Stain & Sealer, type: solid, color: flat black [Lowes]
  6. Screws and nails
  7. Wood glue
  8. Coffin Opening Mechanism
  9. Cable and string
  10. Steel tube [Lowes]
  11. Spray paint (flat black)
  12. Motor (low RPM, high torque) with mounting bracket [Amazon]
  13. Flange couplings [Amazon]
  14. Screws and nuts, to make string reel
  15. Skeleton
  16. Skeleton [Amazon]
  17. Red LEDs for eyes
  18. Eye screw
  19. Skeleton Eyes
  20. Red LEDs (x2)
  21. Resistor 70 ohm
  22. Control Electronics
  23. Arduino (Arduino Nano or other) [Amazon]
  24. Headers [Amazon]
  25. Relay (x3) [Amazon]
  26. PIR Motion Sensor (HC-SR501) [Amazon]
  27. Ultrasonic Distance Sensor (HC-SR04) [Amazon]
  28. Hinge Lever Limit Switch
  29. with roller [Amazon]
  30. DC power source for motor [Amazon]
  31. Snubber
  32. Capacitor (x2)
  33. Resistor 5 to 20 ohm (x2)
  34. Sound
  35. PEMENOL Voice Playback Module [Amazon]
  36. Amplifier (optional) [Amazon]
  37. Speaker [Amazon]
  38. Wires
  39. Red Lights

Cut Plywood for Coffin

IMG_7194.crop.JPG
Initial Plywood Cut Diagram.with_labels.04.png

Build a coffin from a single sheet of plywood.

I followed the instructions in this very helpful video: https://www.youtube.com/watch?v=D4Drj32kNAs

See the attached cutting diagram. Please read through Step #2 before cutting.

I made a few changes vs. the video:

  1. I increased the length of the coffin from 5' to 5' 5". This was to accommodate the 5-foot tall skeleton.
  2. Made the coffin lid solid. In the video, the lid was made of wood slats.

Coffin Bottom

IMG_7195.crop.JPG
IMG_7227.blur.crop.JPG
FZ7D4LDKZHBUDMM.png

Since we are making this coffin from 1 sheet of plywood, the bottom of the coffin is constructed from pieces glued and nailed together. The single sheet of plywood is not big enough to be able to cut both a one-piece lid and a one-piece bottom.

Bottom Should Be Smaller Than the Lid

In my cutting diagram, the bottom is shown as the same size as the lid. Then there is a line showing the bottom should be 1/2 inch smaller than the lid—all around. This is because the coffin sides wrap around the bottom (this adds 1/2 inch on each side). Having a slightly smaller bottom will let the edges of the coffin lid be flush with the sides.

In my project (if you don't cut the bottom smaller than the lid)

I cut the bottom to be the same size as the lid. This wasn't a huge problem, but I would have cut the bottom smaller if I had known to do this ahead of time.

Effects of Too-Large Bottom

  1. Since the sides of the coffin wrap around the bottom, there was a gap between the edges of the lid and the edges of the coffin. So, the lid was recessed about 1/2 inch from the sides.
  2. The top side panel (above the head) needed to be longer (13.5 inches vs. 12 inches) than I had originally planned. This was to make up for the fact that the sides wrapped around the bottom (just a little more length was required).

Coffin Corners

IMG_8301_blur_crop.JPG
IMG_9008_crop.JPG
IMG_8997.JPG
IMG_8998.JPG
FZ7D4LDKZHBUDMM.png

The video demonstrated a clever way of adding strength to the corners. As shown in the video and images, create small triangular braces for the corners.

Coffin Lid

IMG_7945.crop.JPG
IMG_E9126.JPG

Attached the coffin lid with 3 sets of hinges.

I had to attached the lid to the inside surface of the coffin sides. If the sizing of the coffin bottom is reduced (as suggested in step #2), then you should be able to attached the hinges to the outside surface of the coffin sides.

Paint

I painted the coffin flat black with One-Coat Exterior Stain & Sealer.

Steel Bar - Coffin Opener

IMG_8699.JPG
IMG_9218.JPG
IMG_9219.JPG

A square hollow steel tube is used like a seesaw to open the coffin lid. The steel bar goes across the top of the coffin lid, and sticks off the hinge side. The motor pulls down on the end of the tube that is sticking off the coffin. As the sticking-off-end of the tube is pulled down, the other end of the tube goes up, opening the coffin.

Spray paint the steel bar black to prevent it from rusting. Don't worry, no one sees the steel bar at night.

Hinge Side

The steel tube should be placed across the widest part of the coffin lid. The lid-hinge and the tube should be very close to each other on the hinge side (since this is where a large amount of force will be present).

I used a small block of wood on the hinge side of the coffin to raise the bar up a small amount. This let the lid open a little more.

Open Side

To attach the steel tube to the coffin: I drilled a hole into one side of the square steel tube and used a machine screw. The nut went inside the steel tube. The screw head, with a washer, went inside the coffin.

Create Reel for String

IMG_9345.JPG
IMG_8700.JPG
IMG_9348.JPG

How the Motor Pulls the Steel Bar Down

The motor spins a reel to wind-up a string. This string is connected to a loop of cable. The loop of cable goes through a hole at the end of the steel tube. When the motor spins the reel, it winds the string—pulling the end of the steel bar down.

String Reel

Create a reel for the motor to spin. I used two flange couplings, four 2-inch machine screws, and nuts to create a reel. One has to buy the flange couplings to fit the drive shaft of the motor. The motor I used had a 1/4 inch, or 6.5-7mm shaft diameter.

After Halloween, I noticed one of the screws had bent inward. The screws are not very strong in terms of resistance to bending. To help with this, I used a ratchet-wrench socket and zip ties as a metal support on the inside of the reel. The goal is that if one of the screws is pressed inward, it will be supported by the other screws. The bending force will also be spread over the length of the socket.

You may be able to buy a 'sheave' or 'pulley wheel' instead of making one.

I used a loop of cable to go through the hole in the steel tube, because the steel was cutting the string. I used string for winding on the reel—for ease of use and some stretchiness (to absorb the sudden shock when the motor turns on).

Mount Lid Motor

IMG_8698_crop.JPG

As mentioned in the materials list, a high torque, low RPM motor is needed. The motor I used had a rated torque of 6 N-m = 4.4 ft-lb = 52.8 in-lb. This means it should be able to wind up a string with 50lbs hanging from it (assuming a 1-inch radius reel). This motor was expensive. I tried other motors that did not have enough torque, so finally just bought this one that seemed sure to have enough.

I purchased a mount with the motor. This was well worth it and made mounting the motor easy. The motor-power and lid-open-sensor wires come through a hole near the motor.

The motor was really not visible to trick-or-treaters when it was dark.

Arduino Control

Arduino Circuit.03.png
IMG_E9114.JPG
IMG_E9116.JPG

The Arduino runs code to:

  1. Monitor sensors
  2. motion sensor
  3. lid-open sensors
  4. lid-closed sensors
  5. Activate the lid motor
  6. The Arduino uses 3 relays to activate the lid motor
  7. Activate sounds
  8. The Arduino triggers a sound playback module
  9. Activate skeleton eyes
  10. The Arduino sends +5V to a series of LEDs in the skeleton eyes

See the attached circuit/component diagram.

Headers

I used headers between the wires and the Arduino. All the wires that need to plug into the Arduino, plug into a header. One can then attach/detach the header from the Arduino all at once. The wires remain plugged into the header. You can take the Arduino to your computer for a code update.

Grounding

Make sure that the ground wires for all the components are connected. Ex: The relay grounds connect to the Arduino ground, which connects to the sensor grounds, etc.

Motion Sensor

IMG_9024_crop.JPG

I mounted the motion sensor on a decoration outside and next to the coffin. The motion sensor needs 3 wires: +5v, ground, signal. When it detects motion, it sends a signal to the Arduino.

Lid-Closed Sensor

IMG_9214_crop.JPG
IMG_9423_arrow.jpg
IMG_9421.JPG

The lid-closed sensor signals to the Arduino when the lid is closed.

  • If the lid is closed, then the coffin is ready to open if motion is sensed.
  • If the lid is closing, and the closed sensor signals, then the lid is closed, deactivate the motor.

I mounted the lid-closed sensor inside the coffin, on the hinge side, near the foot area. This switch signaled to the Arduino when the lid was closed.

I used a small switch known as a: snap switch, limit switch, or hinged lever switch.

Lid-Open Sensors

IMG_9350.JPG
IMG_9341_crop.jpg

The lid-open sensor signals to the Arduino when the lid is open.

  • If the lid is opening, and the lid-open sensor signals, then the lid is open, deactivate the motor.

Redundancy

I was concerned about the lid-open sensor failing to signal that the lid was open. This could lead to the motor continuing to run and jamming once the lid was fully open. To mitigate this, I used 2 separately-wired lid-open sensors (an ultrasonic sensor, and a snap switch). The Arduino always checks both lid-open sensors when checking if the lid is open.

Lid-Open Sensor #1 (Ultrasonic Sensor)

IMG_9349_arrow.jpg

I used an ultrasonic sensor for the lid-open sensor located near where the end of the steel bar approaches the string reel.

The ultrasonic sensor has two parts. One part emits sound waves. The other part of the sensor (a receiver) measures if any of the sound waves were reflected back to the sensor. The sensor then reports the 'flight time' that it took for the sound waves to make the round trip from the emitter to an object and then back to the receiver.

In the Arduino code, one must multiply this 'flight time' by the speed of sound to get the round trip distance. The speed of sound varies with temperature, so I assume 60 degrees Fahrenheit.

As the steel bar approaches the ultrasonic sensor, the bar reflects sound waves back to the sensor. The sensor checks the 'flight time' repeatedly, sending this reading to the Arduino. The Arduino converts the 'flight time' to a distance. When the steel bar is close enough to the sensor, the Arduino deactivates the motor.

The ultrasonic sensor has several advantages: 1) no physical contact with the steel bar needed, 2) reports a distance. The disadvantage is increased Arduino code complexity. It took me quite a while to get the ultrasonic sensor working properly. Please check that section of the Arduino code for detailed comments.

Lid-Open Sensor #2 (Snap Switch)

IMG_9351_arrow.jpg

I used a snap switch as the secondary lid-open sensor. I mounted it on the side of the coffin. When the steel tube comes down (opening the coffin) it triggers the switch.

I had to mount the switch as close to the lid hinges as possible. This location is close to the fulcrum of the steel bar, where it is moving the least. The issue is, after triggering the switch, the steel bar continues moving for a bit due to the momentum of the lid and the motor. So, if I mounted the switch near the end of the steel bar, the steel bar would impact the switch. I mounted the switch up high, where the steel bar was not moving as rapidly. Even in this location, the bar did tend to hit into the switch. I used the ultrasonic sensor to deactivate the motor slightly earlier than the switch would have (to prevent the bar from hitting into the switch body).

You may also see a snap switch called a 'hinge metal roller lever micro switch', 'limit switch', 'roller lever hinge limit switch micro', etc.

Infrared Proximity Sensors

Initially, I used an Infrared Proximity Sensors for the lid-closed and lid-open sensors. When the steel bar (open sensor) or coffin lid (closed sensor) approached the infrared proximity sensor, the bar reflected infrared light to the sensor and triggered it. The main drawback was that the Infrared Proximity Sensors did not work well in daylight. They signaled continuously because the ambient infrared light triggered the sensors. Once it was dark enough, they worked very well. Still, I changed the coffin to using snap switches and the ultrasonic sensor. Some of the pictures in this instructable show the infrared proximity sensors, which I have since removed.

Sounds

Sound wave.jpg

The Arduino triggers a PEMENOL Voice Playback Module to play sound files stored on the playback module.

Coffin Sounds

  • coffin opening sounds
  • skeleton laughing sounds
  • coffin closing sounds
  • ambient sounds

I've attached the sound files that I used. The coffin opening and closing sounds are around 4.5 seconds long, about the time it takes the coffin to open. These sounds also mask the sound of the motor. The skeleton laughing sound is the Crypt Keeper (9 seconds).

Ambient Sounds

When no trick-or-treaters come by for a certain number of seconds, the Arduino selects randomly between 3 ambient sounds (heavy breathing, werewolf, spooky sounds) and triggers one to play. If trick-or-treaters are detected by the motion sensor, any ambient sounds playing are abandoned, and the coffin opening sequence begins immediately. The ambient sounds are 5-8 seconds long.

Attached Audio Files

  1. Coffin opening => 00001.mp3
  2. Crypt Keeper laughing => 00002.mp3
  3. Coffin closing => etc.
  4. heavy breathing
  5. werewolf
  6. spooky ambience

The playback module requires that the files be named in numerical order.

Sound Playback Module

Module Close Up.JPG

The PEMENOL Voice Playback Module stores mp3 files of the sounds. You connect the playback module to your computer and copy files to it just like a USB drive. The module includes a built-in 5-watt amplifier, so you can connect it directly to a speaker.

Triggering Sounds

The module operates in different modes, with each mode corresponding to a different method for triggering specific sound files to play. The red dip switches allow you to select the mode that the module will operate in.

I used the 'Direct IO' method. In this mode: The playback module has 8 inputs, with each corresponding to an individual sound file. The Arduino puts a low signal on the input that it wants the module to play. The module then plays the entire sound file once it is triggered (even if the Arduino stops producing the trigger signal). However, if the Arduino triggers a different sound to play, the Playback Module immediately switches to playing this new sound file.

Operational Notes

  • In my experience, I encountered an error each time the coffin system was first powered up, and the Playback Module played its first sound file.
  • During playing of its first sound file, the Playback Module would suddenly start playing static noise. This would last for about 30 seconds.
  • Once, I had to cycle the +5V power on the Playback Module to get this to stop.
  • After this static noise on the first playback, the Playback Module worked fine. This only happened when the coffin system had been unplugged, and was now powered up.
  • Once I switched to using an external amplifier (next step) this issue no longer occurred.

Amplifier (optional)

amplifier side.jpg

Over Halloween, I felt the speaker should have been louder. I have since upgraded to a cheap 10+watt amplifier. The playback module has a line-level (unamplified) output. I connect this line-level output from the playback module to the amplifier using a headphones-type (3.5mm-plug-to-RCA-plugs) cord. The amplifier then connects directly to the speaker and drives it.

Build a Speaker Box

speaker box.JPG
IMG_9002_speaker.JPG

I built a wood enclosure for the speaker. I used this helpful website: https://www.omnicalculator.com/other/speaker-box

I painted the speaker box flat black, with the same exterior stain as the coffin. I placed the speaker inside the coffin. I may place a second speaker outside the coffin.

Motor Control

Motor Circuit.02.png

Motor

To open the coffin, the motor spins the reel, which reels in the string. This pulls one end of the steel tube down toward the motor. The other end of the tube goes up. The up-end is attached to the open side of the coffin.

To close the coffin, the motor spins the other way, letting gravity pull the coffin lid down to a closed position.

This requires a low RPM, high torque motor. The only motor I found that had enough torque was a direct current (DC) motor. Therefore, I purchased a 10amp, 12V DC power supply to power the motor.

Wiring Overview

You have 120V alternating current (AC) household power going into the power supply. The power supply outputs DC: +12V and negative/ground. These 12V wires connect to relays. When the relays are triggered, they close the circuit, and +12V electricity flows through the motor.

Direction Control

To change the direction of the motor, one must switch the positive and negative power inputs to the motor. For example: +12V on the left wire spins the motor counterclockwise. +12V on the right wire spins the motor the other way (clockwise). Doing this with relays (and not physically switching any of the wires) was a bit tricky.

I used three relays to be able to drive the motor in the open or close direction. As you can see in the diagram, I labeled the relays A, B, C. The A and C relays provide +12V to each side of the motor. The A and C relays are never triggered at the same time. Only one relay at a time provides the +12V power (depending on the direction we want the motor to turn).

The B relay provides the ground or negative to the opposite side of the motor. The B relay switches the negative connection from one side of the motor to the other, depending on whether relay A or C is powering the motor. The negative connection must always be on the opposite side of the motor from the positive.

For example: If relay A is providing +12V to the left side of the motor, then relay B will connect the negative/ground wire to the right side of the motor. This connection sequencing is controlled by the Arduino.


On the diagram, NO = Normally Open; NC = Normally Closed.

Snubber Circuit

Snubber Detail.02.png
IMG_8558.JPG

What is a Snubber Circuit

The motor indicates it can use up to 6 amps of current. A motor is an inductive load, meaning it has inductance. Inside the motor, the wires are wound in such a way that a magnetic field is created. This magnetic field is what causes the motor's rotor to spin.

When the electricity is switched off, the energy in the magnetic field needs somewhere to go. It can generate a voltage spike—which can cause arcing between the contacts of the on/off the switch (relay in this case). Arcing between the contacts of a relay gradually erodes the contacts, wearing out the relay.

A snubber circuit absorbs the energy from an inductive load. A snubber circuit is just a capacitor and a resistor in series across the relay. When the relay switches the circuit off, the voltage in the circuit will start to change. In changing voltage situations, capacitors start to conduct electricity. This lets the excess energy from the inductive load flow through the capacitor and resistor. The resistor dissipates the excess energy as a little bit of heat.

Snubber Test

I tested the snubber circuit by manually touching the wires from the motor to the power supply. This would make the motor run. When I moved the wires away (disconnecting them from the power supply) I saw a small spark. When I included a snubber circuit, the wires did not spark—because the snubber circuit absorbed this energy.

Coffin Snubber Circuit

I created 2 snubber circuits, one for each of the +12V-outputting-relays (relay A and relay C). Each snubber used resistors that totaled about 5ohms. For the capacitors, I used what I had lying around. So, I used a 25V 220µF capacitor for the snubber circuit on one relay. I used a 35V 470µF capacitor on the other. I put the positive side of the capacitor toward the +12V coming from the relay. The negative side then went toward the motor. The resistor can be on either side of the capacitor. This setup worked well.

Do You Need It?

A snubber circuit is likely not required for this project. A little bit of arcing will not wear out the relays over the small number of times the motor will be activated.

Skeleton Eyes

IMG_9376.JPG
red-LED-e 400.jpg

To give the skeleton light-up eyes, wire two red LEDs together in series, along with a 70 to 100 ohm resistor. The current will have to go through all 3 components in series. This should be connected to a +5V output pin of the Arduino. The three components must be wired in series because the +5V from the Arduino will drive too much current through a single LED. It would burn it out.

Drill holes in the eyes of the skeleton. Cut out a small portion of the rear of the skull in order to mount the LEDs from inside the skull (LED poking thought the eye holes, leads and wires inside the skull). I used a small amount of glue to secure the LED in each eye.

Arduino Code

State machine.02.jpg

State Machine

The Arduino code is designed as a state machine. A state machine is always in a particular state. A state machine reads its inputs and changes to a different state based on those inputs. Some of the states also have actions that the Arduino carries out.

For example:

  1. The Arduino starts out in the IDLE state when it powers up.
  2. IDLE state
  3. Arduino checks the lid-closed sensor.
  4. If the coffin is closed
  5. Arduino moves to the READY_TO_OPEN state.
  6. READY_TO_OPEN state
  7. The Arduino checks the motion sensor.
  8. If motion is detected
  9. Trigger the opening sound
  10. Trigger the motor to open the coffin
  11. Arduino moves to the OPENING state.
  12. etc...

If-Statements

One way of implementing a state machine is using a series of case statements. The code in each case statement runs some kind of test (usually reading inputs). Based on the result of this test, the code then moves to another state. I initially used case statements. However, due to weird issues with the code not entering certain states when it should have, I changed the implementation to using if-else statements.

Enumeration

I used a header file (Skeleton.h) to define an enumeration that contains all the possible states for the state machine. This allows you to use the enumeration in the if-statements. This has benefits over using strings to define each state.

Timeouts

I had a series of timeouts in place to turn the coffin off if something went wrong. I didn't want the motor to run too long if the open or closed sensors failed (perhaps the motor could overheat if the reel jammed). I was also concerned about kids grabbing the lid—it would be better for the coffin to deactivate in that case.

The coffin lid usually took 4.8 seconds to open or close. If the lid took longer than 6 seconds, the timeout was reached—I assumed something had gone wrong.

When a timeout is reached, the Arduino turns off the motor and goes into the TIMEOUT state. The Arduino remains in that state until it is manually reset. I had the Arduino's internal LED blink SOS to let me know when it was in the TIMEOUT state. Over Halloween, none of the timeouts were reached and the coffin worked well all night.

The Arduino Code is Attached Below

Put both files in the project directory.


Image source: https://medium.com/@yolapop/implementing-state-machine-on-android-app-634b2f75b08e Implementing State Machine in Android App; by Yolanda Septiana

Make the Skeleton Sit Up

IMG_9380.JPG

I connected the skeleton head to the lid with a string. As the lid opens, it pulls the skeleton up.

  • The skeleton I used came with a black string attached to the top of its head.
  • I screwed an eye screw into the underside of the coffin lid.
  • I attached the black string to the eye screw—to raise the skeleton as the lid opened.

This did not make the skeleton sit up a full 90°, but it was simple and good enough for me.

Please let me know if you find a better way to make the skeleton sit up.

Consolidate Electronics

IMG_9355.JPG
IMG_9356.JPG
IMG_9358.JPG
IMG_8999.JPG
IMG_9361_rotate_crop.JPG
  • I consolidated the electronics in a plastic box between the skeleton's legs.
  • I used black landscape fabric under the skeleton to cover the electronics.

Final Setup

FBVL70SKWW47PJP.jpeg
IMG_7998_crop.JPG
  • Keeping kids back
  • I hammered broken wood pieces (from a pallet) into the ground to form a spooky fence around the coffin.
  • I didn't want little kids touching or getting hit by the coffin lid.
  • I would like to add a kill-switch on the outside of the coffin to deactivate the motor immediately. Just in case.
  • I used red Christmas lights in and around the coffin to illuminate the skeleton and surrounding graveyard. I may switch to a red flood light (for brighter light).