Project tutorial
No Candy For YOU!

No Candy For YOU! © GPL3+

A prank candy bowl that senses when someone tries to reach for a piece and automatically empties before they can get one.

  • 1,030 views
  • 5 comments
  • 6 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)
Hobby Knife

Apps and online services

About this project

Overview

This is my prank for circuit.io's Arduino Day Prank Contest

Here is a link to the circuit.io reply page that I used: https://storage.circuito.io/index.html?solutionId=58e452ccf72c4f00124dc4d3

I'm fairly new to Arduino projects, so the wiring diagrams and sample source code from circuit.io were a real life-saver.

My idea is to make a trick candy bowl with a trap bottom that will automatically move away when it senses proximity. For icing on the prank cake, it then plays the "Nanny nanny boo boo!" song mockingly. Once the victim recovers from the surprise/disappointment at the retreating candy and subsequent mocking, the push of a button lets you reset the system for your next friend/mark.

So, getting started, here's my BoM from circuit.io (the most interesting parts of it anyway):

Wiring

And here is my wiring diagram:

Step by step instructions

Following the instructions from circuit.io I ended up with this:

Moved on to the sample code from circuit.io to test everything out. It saved me a lot of time to have ready-made code for testing all my components and my wiring job! Also notice that all my supporting .h and .cpp files that I will need are already included:

At this point I used the serial monitor in the Arduino IDE tools and was able to experiment with each component. I noticed that the servo motor was a little jumpy at the beginning and my distance meter was giving odd values, so I decided to make a better ground plane by adding a jumper from the other Arduino Uno ground pin to the other side of the ground rail on the breadboard. This seemed to help but don't accidentally connect the breadboard ground rail to the VIN pin on the Arduino like I did (it was late). Didn't let any magic smoke out but needed a board reset and another round of testing to make sure I didn't cook anything (thankfully I didn't).

Example code was great for testing components, but it wasn't going to make my prank work. In my attached code you can see how I modified the sample code from circuit.io to achieve the behavior I needed. There's also a link to my github repository that includes all the support files that I got from circuit.io.

Now with my basic circuit prototyped and code pretty much done it was time to move on to fabbing my candy bowl, trap door, and enclosure. As cool as it would have been to 3D print this thing, I did most of my construction with cardboard, tape, and hot glue.

Videos

So with assembly all done it was time to test. Here is how the trap worked:

Oh no! My Candy?!

And here's how the reset works:

Getting ready for the next victim >:)

Conclusions

So all in all, it's pretty obvious that something is up when you spy candy in a paper bowl recessed in an old shipping box with a sensor on top. Even if the trap is kinda obvious I liked the speed of the servo trap door. BTW, in the videos you can see a USB cable coming out the the box to power it, but it does work with a 9V battery. The one I was using wasn't up to the task when I was taking videos but I tested it later with a fresh battery and everything worked just fine.

It was a fun project and I liked the help of circuit.io to get quickly into prototyping. I'll definitely be going there in the future. Thanks for looking at my project!

Code

NoCandy.inoC/C++
My Candy Bowl prank Arduiono firmware code
// Include Libraries
#include "Arduino.h"
#include "NewPing.h"
#include "PiezoSpeaker.h"
#include "Button.h"
#include "Servo.h"


// Pin Definitions
#define HCSR04_PIN_TRIG	3
#define HCSR04_PIN_ECHO	4
#define PIEZOSPEAKER_PIN_SIG	5
#define PUSHBUTTON_PIN_1	6
#define SERVO9G_PIN_SIG	2

// Global variables and defines
unsigned int piezoSpeakerNNBBLength          = 6;                                                      
unsigned int piezoSpeakerNNBBMelody[]        = {NOTE_C4, NOTE_C4, NOTE_A3, NOTE_D4, NOTE_C4, NOTE_A3}; 
unsigned int piezoSpeakerNNBBNoteDurations[] = {4      ,4      , 4      , 4      , 2      , 4      }; 
unsigned int piezoSpeakerArmedLength          = 3;                                                    
unsigned int piezoSpeakerArmedMelody[]        = {NOTE_C5, NOTE_C5, NOTE_C5}; 
unsigned int piezoSpeakerArmedNoteDurations[] = {4      ,4      , 4      }; 
const int servo9gClosedPosition   = 20;  //Starting position - closed
const int servo9gOpenPosition = 110; //Trap door open position
const int triggerDistance = 10;

// Constructors
Servo servo9g;
NewPing hcsr04(HCSR04_PIN_TRIG,HCSR04_PIN_ECHO);
PiezoSpeaker piezoSpeaker(PIEZOSPEAKER_PIN_SIG);
Button pushButton(PUSHBUTTON_PIN_1);




// define vars for testing menu
#define TIMEOUT 10000       //define timeout of 10 sec
char menuOption = 0;
long time0;

/* This code sets up the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. */
void setup() {
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    while (!Serial) ; // wait for serial port to connect. Needed for native USB
    Serial.println("start");
    
    pushButton.init();
    servo9g.attach(SERVO9G_PIN_SIG);
    servo9g.write(servo9gClosedPosition);
    delay(500);
    servo9g.detach();
}

void loop() {

    bool triggered=false;
    bool armed=true;
    
    //Keep checking distance meter - if something close then open servo if not then back to wait
    while (triggered==false) {
        int hcsr04Dist = hcsr04.ping_cm();
        
        if((hcsr04Dist != 0) && (hcsr04Dist < triggerDistance)) {
          triggertrap(hcsr04Dist);
          triggered = true;
          armed = false;
        }
        else {
          //Serial.print(F("Distance: ")); Serial.print(hcsr04Dist); Serial.println(F("[cm]")); // print triggered distance for debug
          delay(100);
        }
    }
    

    //Wait for reset signal
    while (triggered==true) {
        bool pushButtonVal = pushButton.read();
    
    
        if(pushButtonVal) {
          resettrap();
          triggered = false;
        }
       else {
          delay(100);
        }
    }

    //Wait for second button press to signal that the trap is ready to arm again
    while (armed==false) {
        bool pushButtonVal = pushButton.read();
    
        if(pushButtonVal) {
          armtrap();
          armed = true;
        }
       else {
          delay(100);
        }
    }
}

// This section is used to trigger the trap and play music
void triggertrap(int triggerDistance)
{
    //Open servo trap
    Serial.print(F("Trigger Distance: ")); Serial.print(triggerDistance); Serial.println(F("[cm]")); // print triggered distance for debug
    servo9g.attach(SERVO9G_PIN_SIG);         // 1. attach the servo to correct pin to control it.
    servo9g.write(servo9gOpenPosition);      // 2. turns servo to open position. 
    delay(1000);                              // 3. wait 100 milliseconds
    servo9g.detach();                        // 4. detach the servo

    //Play Music- The Speaker will play the Nanny Nanny Boo Boo tune x2:P
    piezoSpeaker.playMelody(piezoSpeakerNNBBLength, piezoSpeakerNNBBMelody, piezoSpeakerNNBBNoteDurations);
    delay(250); 
    piezoSpeaker.playMelody(piezoSpeakerNNBBLength, piezoSpeakerNNBBMelody, piezoSpeakerNNBBNoteDurations); 
    
    delay(500);
}

void resettrap()
{
    //Close servo trap
    servo9g.attach(SERVO9G_PIN_SIG);         // 1. attach the servo to correct pin to control it.
    servo9g.write(servo9gClosedPosition);    // 2. turns servo to closed position.
    delay(1000);                              // 3. wait 100 milliseconds
    servo9g.detach();                        // 4. detach the servo
}

void armtrap()
{
    //Indicate trap armed
    piezoSpeaker.playMelody(piezoSpeakerArmedLength, piezoSpeakerArmedMelody, piezoSpeakerArmedNoteDurations);
    delay(500);                        
}
No Candy For YOU!! Arduino Project Code

Schematics

Wiring Diagram from Circuit.io
So nice to have this auto-generated by circuit.io!
Circuit io wiringdiagram 5amxa7ubls

Comments

Similar projects you might like

Automatic Fear 1.0

Project showcase by Alexis Santiago Allende

  • 1,105 views
  • 3 comments
  • 5 respects

Arduino Darkness Activated Ghost

Project tutorial by Technovation

  • 1,974 views
  • 2 comments
  • 10 respects

Pranked! Moving Tissue Box | Circuito.io

Project tutorial by Arduino “having11” Guy

  • 3,954 views
  • 1 comment
  • 18 respects

The Troll Switch

Project tutorial by Aitor Gamarra

  • 1,002 views
  • 1 comment
  • 2 respects

Candy Dispenser with Google Assistant

Project tutorial by Arduino “having11” Guy

  • 15,482 views
  • 1 comment
  • 51 respects

Candy Dispenser

Project tutorial by Hada Amira

  • 7,234 views
  • 7 comments
  • 20 respects
Add projectSign up / Login