COVID-friendly Jack-o'-Lantern Using Arduino




Introduction: COVID-friendly Jack-o'-Lantern Using Arduino

About: I like learning :)

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!



  • 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

Step 1: The Pumpkin: Design

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.

Step 2: Pumpkin: 3D Printing

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.

Step 3: Painting

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.

Step 4: Circuit

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.

Step 5: 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.

Step 6: Assembly

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!

Step 7: Set It Up

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!

Halloween Contest

Participated in the
Halloween Contest

Be the First to Share


    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Big and Small Contest

      Big and Small Contest
    • Make It Bridge

      Make It Bridge



    2 years ago

    Wow, such an amazing project idea!!