Shoeb Ahmed
Hi! Shoeb here. I am working as a Software...

TOP STORIES

  1. Spooky candy box

Shoeb Ahmed
Hi! Shoeb here. I am working as a Software...

TOP STORIES

  1. Spooky candy box

Hi! Shoeb here. I am working as a Software Developer at...

Spooky candy box

cover img resized

 

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

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.

 

How the project works?

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.

As soon as an obstruction is detected by the Ultrasonic distance sensor mounted on the bowl, a buzzer will sound. The system can be turned on/off via the Bolt Cloud.

 

Things Required

Hardware components - 

  • Bolt WiFi Module
  • Arduino Uno R3
  • HC SR04 Ultrasonic distance sensor
  • Cardboard box
  • A pair of scissors
  • Double sided tape
  • A few decorative items

And lastly some candies to put in your bowl as bait.

You can get the Bolt WiFi module and other items with the Bolt IoT & ML Starter Kit. The kit is also included as part of the 'Bolt IoT and ML hands-on training'.

 

Hardware connections -

Connect the hardware components as given in the diagram below,

hardware_connection_arduino

 

Lets build

  • 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.
  • Once you have cut the hole, check if you can insert the sensor into the cutout comfortably. Make adjustments as required.

inserting ultrasonic sensor

  • Connect the components as given in the wiring diagram.
  • Use the double sided tape to glue the 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 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.

box connection

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 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 Arduino.

 

Setup your product on the Cloud

create product

  • The product will be of Output type and UART connection as it is interfaced with the Arduino.

creating product config popup

  • 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.

 

Results

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.

result UI

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.

 

Want to build more such IoT and ML projects? Want to learn IoT and ML from basics?

Check out the Bolt IoT and ML training. This online video training is excellent for those who want to start with IoT and ML because it teaches you to build projects from the basics. Click on the button below to know more about the training.

Learn more about Bolt IoT & ML Training

 

Code

Bolt Cloud product code


<!DOCTYPE html>
<html>
<head>
    <title>Spooky Bowl</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <style>
        .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;
        }
    </style>

</head>
<body>
    <button class="button" onclick="arm_system()">Arm System</button>
    <br>
    <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(){
        start_communication();
        make_request(ARM_COMMAND);
    }
    
    function disarm_system(){
        start_communication();
        make_request(DISARM_COMMAND);
    }
    
    function make_request(command){
        $.ajax({
            type: "GET",
            url: "https://cloud.boltiot.com/remote/" + API_KEY + "/serialWR",
            cache: false,
            async: false,
            data: {
                "data": command,
                "deviceName": BOLT_ID
            },
            success: function(response){
                console.log(response)
                var status = response["success"];
                if(status!=1){
                    alert("Device is offline!");
                }
                else{
                    alert(response["value"]);
                }
            },
            error: function(response){
                alert(response);
            },
        });
    }
    
    function start_communication(){
        cmd_serial_begin();
    }
    
    function cmd_serial_begin(){
        $.get("https://cloud.boltiot.com/remote/" + API_KEY + "/serialBegin?baud=9600&deviceName=" + BOLT_ID);
    }
</script>

</body>
</html>
  

Arduino code


    #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() {
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(BUZZER_PIN, LOW);
  boltiot.begin(Serial);
  boltiot.setCommandString("disarm_system",disarm_system);
  boltiot.setCommandString("arm_system",arm_system);
  Serial.begin(9600);
}

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);
  delay(1000);  
  digitalWrite(BUZZER_PIN, LOW);
}

void loop() {
  boltiot.handleCommand();
  distance = ultrasonic.read();
  if(system_armed){
    if(distance < min_distance){
      sound_buzzer();  
    } 
  }
  delay(100);
}

    

 

IoT Bolt IoT Projects diy

Shoeb Ahmed
Hi! Shoeb here. I am working as a Software Developer at...