Project tutorial
Spooky Candy Box

Spooky Candy Box © MIT

Ever wanted to scare those pesky kids on Halloween as they are picking up sweets from your porch? Look NO further...

  • 5 respects

Components and supplies

Apps and online services

About this project

It's nearly Halloween! Time to bring out those spooky skeletons and cobwebs to make your house the most haunting on the street.

Kids coming to your house to get candy? Time to scare them for one last time before they get the sweet treats.

This project helps you build a bowl which will scare those pesky kids one last time by sounding a loud alarm as they reach inside the bowl to grab some candies.

Things Required

You will need a few electronic items namely,

  • Arduino Uno r3 or Boltduino
  • Bolt v2
  • HC SR04 Ultrasonic distance sensor
  • Cardboard box
  • A pair of scissors
  • Double sided tape
  • A few decorative items


Connect the components as given in the images below. I have given the connections for both an Arduino and Boltduino.

If you are using an Arduino instead of a Boltduino, you will need to interface the Bolt with the Arduino for it to be able to receive commands from the Bolt Cloud.

If you are using the Boltduino, connect the Bolt directly to the Boltduino and power it up.

If you have not yet setup your Bolt device to your account, click here to know how to do so.

Steps to Build the Bowl

  • Get a cardboard box of suitable size and cut a hole on its side at the top which is roughly the size of your Ultrasonic sensor.
  • Measure the width of your bowl and note it down. We will need to enter this value in the code for the Arduino/Boltduino.
  • Once you have cut the hole, check if you can insert the sensor into the cutout comfortably. Make adjustments as required.
  • Connect the components as given in the wiring diagram.
  • Use the double sided tape to glue the Boltduino/Arduino to the side of the box.
  • Make the sensor secure by either gluing it in place or using double sided tape.
  • Feel free to use your own decorations to make the bowl even more spooky. Use black chart paper to hide any wires.
  • Power on the Boltduino/Arduino and make sure that the Bolt unit is connected to the WiFi network.

The end project will look something similar to the one below. I have used an empty cardboard box for this project, but you can choose an even bigger one for your purpose. Just make sure that the Ultrasonic sensor is positioned so that it covers the entrance of the box where the hand is expected to come to pick up the candy.

Upload the code to the Boltduino/Arduino

  • Download the Ultrasonic library for Arduino from this link and install it to the Arduino IDE.
  • Download the Bolt-IoT Arduino library from this link and install it to the Arduino IDE.
  • Instructions on how to install the library is from this link.
  • Download the code given at the end of the project and enter the width of the bowl that you have measured earlier in line 7 of the code.
  • Use the Arduino IDE to upload the code to the Boltduino/Arduino.

Setup your product on the Cloud

  • The product will be of Output type and UART connection as it is interfaced with the Boltduino/Arduino.
  • Next, you will need to link your device to the product. Click on the "Link" icon on the top right corner to link a Bolt device to the product.
  • Choose the device to link to the product and click on "Done".
  • Click on the "Configure" icon to configure the product.
  • In the code section of the product, copy the code given at the end of the project and save it giving it a suitable file name.
  • In the code, replace the API_KEY and DEVICE_ID with your Api key and Device ID respectively and click on Save to save the changes to your project.
  • Your device ID will be something like "BOLT12345" and Api key will be something like "63244fa2-4ac0-45fb-af34-a3456gsdf8c193".
  • You can find your API key via this link and your Device ID from this link.
  • Don't forget to save your product. Click on the "Save" icon on the top right corner to save the changes that you have made.
  • To view the product, click on the "View" icon for the device to "Arm/Disarm" the system.


View your product on the Bolt Cloud and click on the "Arm System" button to arm the system. In this mode, the system will make noise whenever someone tries to put their hand inside the bowl.

You can also switch off the system by clicking on the "Disarm System" button to disable the noise.

Keep your bowl on your doorstep, make sure that the system is armed and watch the fun.

You can connect an even powerful hooter/buzzer to really scare people when they put their hand inside.


Bolt Cloud codeHTML
Upload this code to your account on Bolt Cloud.
<!DOCTYPE html>
    <title>Spooky Bowl</title>
    <script src=""></script>

        .button {
            background-color: #4CAF50;
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;

    <button class="button" onclick="arm_system()">Arm System</button>
    <button class="button" onclick="disarm_system()">Disarm System</button>

<script type="text/javascript">
    var BOLT_ID = "";  //Change this value
    var API_KEY = "";   //Change this value
    var ARM_COMMAND = "arm_system";
    var DISARM_COMMAND = "disarm_system";
    function arm_system(){
    function disarm_system(){
    function make_request(command){
            type: "GET",
            url: "" + API_KEY + "/serialWR",
            cache: false,
            async: false,
            data: {
                "data": command,
                "deviceName": BOLT_ID
            success: function(response){
                var status = response["success"];
                    alert("Device is offline!");
            error: function(response){
    function start_communication(){
    function cmd_serial_begin(){
        $.get("" + API_KEY + "/serialBegin?baud=9600&deviceName=" + BOLT_ID);

Boltduino/Arduino CodeC/C++
Upload this code to your Arduino/Boltduino via the Arduino IDE.
#include <BoltIoT-Arduino-Helper.h>
#include <Ultrasonic.h>

Ultrasonic ultrasonic(12, 13);
int distance;
int min_distance = 15;    //Change this value to the width of your bowl
int BUZZER_PIN = 3;
bool system_armed = true;

void setup() {
  digitalWrite(BUZZER_PIN, LOW);

String arm_system(){
  system_armed = true;
  return "System Armed";  

String disarm_system(){
  system_armed = false;
  return "System Disarmed";  

void sound_buzzer(){
  digitalWrite(BUZZER_PIN, HIGH);
  digitalWrite(BUZZER_PIN, LOW);

void loop() {
  distance =;
    if(distance < min_distance){


Boltduino Connections
Spook bowl boltduino bb cv1ofltnrw
Arduino Connections
Spook bowl arduino bb fntzgakf8w


Similar projects you might like

Monster in a Box

Project tutorial by craig jameson

  • 119 respects

Bolt Controlled Robot Car

Project tutorial by Bolt

  • 35 respects

Add Lights and Spooky Music to Your Jack-O-Lantern

Project tutorial by aams86

  • 1 comment
  • 25 respects

Smart Door with Face Unlock

Project tutorial by Divins Mathew

  • 40 respects

Water Level Alerting System

Project tutorial by Pranav Kundaikar and Vinayak Shantaram Joshi

  • 22 respects
Add projectSign up / Login