COVID-friendly Jack-o'-Lantern Using Arduino

by alexoort in Circuits > Arduino

1294 Views, 8 Favorites, 0 Comments

COVID-friendly Jack-o'-Lantern Using Arduino

Screenshot 2020-11-01 at 17.23.43.png
COVID-friendly trick-or-treating Jack-O-Lantern

As Halloween is right around the corner but coronavirus cases are rising throughout the world, I thought that it would be useful to make a Jack-o'-lantern that drops candy whenever you get close to it, to avoid the usual human contact during trick or treating.

To do this, I used an Arduino Nano, an ultrasonic sensor, a servo motor, and a 3D printed pumpkin!

Supplies

Electronics:

  • Arduino Nano
  • Ultrasonic sensor
  • Servo motor
  • Jumper wires
  • 3D printer & filament

Tools & other:

  • Soldering iron
  • Spray paint
  • Hot glue gun
  • String/shoelace (optional)
  • Sandpaper
  • Drill with a wire brush (optional)
  • Cotton swab/toothpick

The Pumpkin: Design

Screenshot 2020-10-17 at 20.12.55.png
Screenshot 2020-10-17 at 20.15.17.png
Screenshot 2020-10-17 at 20.16.19.png
Screenshot 2020-10-17 at 20.16.54.png

Instead of using an actual pumpkin, I decided to 3D print one, as this would allow for the moving mechanism necessary for dropping the candy.

I designed the Jack-o'-lantern using Tinkercad, and I have attached the STL files below. The Jack-o'-lantern consists of eyes, a nose, a mouth, as well as a lid at the top (to put in the candy) and a hinge at the bottom that should open whenever someone approaches. There's also small rings at the top which will allow us to hang it.

If you would like to modify the design, please go ahead; however, keep in mind that the eyes have to be 1cm apart and have a diameter of 1.6, or else the ultrasonic sensor will not fit. Also, make sure that the hinge mechanism will work in real life.

Pumpkin: 3D Printing

Screenshot 2020-10-17 at 21.18.27.png
Screenshot 2020-10-17 at 21.14.46.png
IMG_5092.jpg

For the 3D printing, I used the Ultimaker 2 from my school, but you can use whichever printer you have available. However, make sure to adjust the slicer settings and enable support (this allows the printing of overhangs), or else the print will fall apart while printing. I would also recommend printing the sides of the pumpkin as shown in the picture above, or else the filament will not properly stick to the print bed.

I decided to print the pumpkin in two parts, as this would require less support material, and also make it easier to attach the electronics inside.

For my filament, I simply used grey PLA that I had bought from Amazon. If you'd like though, you could also use orange filament so that you don't have to paint the parts later on. Before starting the print it is also important to check whether you have enough filament on your spool, as each part of the pumpkin requires roughly 100 grams.

Once the printing has finished, you will have to remove the support material. To do this, I used some pliers, a knife and a screwdriver. Some support material could not be removed using this method, so I used some sandpaper and a drill wire brush to remove most of what was left. However, it's fine if your pumpkin is not completely smooth since real pumpkins aren't perfect either.

Also, if you accidentally break the hinge on the pumpkin, do not worry at all; simply add some hot glue and stick it on again.

Painting

IMG_5078.jpg
IMG_5076.jpg
IMG_5084.jpg
IMG_5089.jpg
IMG_5095.jpg

Once you have finished removing the support material from your pumpkin, it's time to paint!

An easy option is just using orange spray paint; however, if you want to decorate your pumpkin even further and make it a zombie pumpkin, you could use acrylics.

If you are using spray paint, make sure that you are outside when you paint the parts. I would also recommend placing the pumpkin and the other parts on a piece of old cardboard or wood so that you don't paint your garden orange.

I decided to paint the pumpkin as well as the servo motor so that it is camouflaged and not very visible.

After you have applied a coat of paint, leave the parts outside for a few hours to let them properly dry.

Circuit

Screenshot 2020-10-31 at 10.54.22.png
usb cable.jpg

As you can see above, the circuit for this project is quite simple. You simply need to connect the ultrasonic sensor and the servo motor to the Arduino. For this project, it's better to use an Arduino Nano due to its smaller size. If you want to use an Arduino UNO, then you may have to edit the 3D model somewhat. Since the servo motor pulls too much power from the Arduino, an external power supply is needed, which can simply be a USB cable. To be able to connect the USB to the Servo, you will want to cut the USB cable so that you can see 4 smaller wires. Red is +5V and black is ground. The ground of some cables will sometimes be wrapped around the other wires like a case. You can ignore the green and white wires, or just cut them off.

If you want to make the project more permanent, I would recommend soldering the parts together, as this will prevent a jumper wire disconnecting. However, please don't solder the Servo motor yet, or you will have to desolder it later on.

Before we move on to the code, however, it's important to understand how an ultrasonic sensor works. Essentially, it sends out ultrasonic signals and measures the time it takes for the signals to return. Ultrasound is a type of sound that has such a high pitch that humans can't hear it. However, like sound, it bounces off objects. Therefore, if there is an object nearby, the signals will bounce off and quickly return to the sensor. The farther away from the body, the more time it will take for the ultrasonic signals to arrive back at the ultrasonic sensor.

The Code

Just like the circuit diagram, the code for the project is relatively straightforward.

In the setup, the servo motor is initialized and the trig and echo pins are declared as output and input respectively.

In the loop, the trig (ping) pin is set to LOW, and quickly after it is set to HIGH. The Arduino then measures the time it takes for the echo pin to receive the ultrasonic wave, and stores this value in the duration variable.

By using the speed of sound, this duration is turned into a distance, in cm. If the distance is smaller than 15 cm, then the Arduino moves the Servo motor, and opens the 'door' at the bottom of the pumpkin, dropping candy. The Arduino then waits for 1 second before restarting the loop.

Now you will want to upload the code to your Arduino. If you are using a Nano and you are having problems uploading, go to Tools > Processor and select 328P (Old bootloader) on the Arduino IDE.

Downloads

Assembly

IMG_5116.jpg
IMG_5117.jpg
IMG_5127.jpg
IMG_5123.jpg
IMG_5124.jpg
IMG_5125.jpg
IMG_5128.jpg
IMG_5129.jpg
IMG_5130.jpg
IMG_5132.jpg

We're almost there! Now it's time to put everything together.

First, upload the code to the Arduino. Then, using hot glue, stick the Arduino to the left side of the pumpkin (the one that has two teeth), and make sure that you don't cover the hole for the Servo motor cables. Pass the USB cable for the Arduino through the square hole (on the other side of the pumpkin) and connect it to the Arduino.

Next, insert the ultrasonic sensor through one of the eyes on the pumpkin, so that they stick out on the outside, as shown in the picture above. Now connect the ultrasonic sensor to the Arduino.

Next, connect the repurposed USB cable to the Servo motor's + and - pins. Now connect the ground (-) of the servo motor to the Arduino's ground. Finally, connect the signal pin on the Servo motor to digital pin 9 (Make sure that you pass these cables through the small hole at the back of the pumpkin).

Now that all of the necessary components are inside, you can close off the pumpkin. Add hot glue to the edge of one side of the pumpkin and then bring the two sides together until the glue has solidified. You will now want to place the small 'door' between the three hinges on the pumpkin. Then, cut off the ends of a cotton swab and insert it through the holes on the hinges. Cut off the parts that stick out and then glue the ends of the swab to the hinge on the pumpkin, so that the door can still move freely.

Glue the servo motor to the bottom of the pumpkin, so that the Servo horn (the 'pointer' on the Servo motor) is aligned with the 'door' (as shown in the pictures above). To improve the opening-and-closing mechanism, I added a resistor (you could use something else if you like) to the end of the horn and then glued the resistor to the 'door', as shown.

If you power up the servo motor and the Arduino, it should work!

Set It Up

COVID-friendly trick-or-treating Jack-O-Lantern
IMG_5175.jpg
IMG_5173.jpg
IMG_5150.jpg
IMG_5151.jpg

Woohoo! The Jack-O-Lantern itself is finished. Now you just have to set it up.

I decided to hang it from the beams on my porch, but feel free to get creative. I powered both the Servo and the Arduino with power banks, but you can also power them from the wall, or your laptop.

In terms of candy, I used wrapped chewing gum, but you could of course use other kinds of treats as well. Before you buy a lot of candy though, make sure that it will fit through the opening at the bottom of the pumpkin.

Alright, that should be it! Good luck!