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.

  • 9 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)
Hobby Knife

Apps and online services

About this project


This is my prank for's Arduino Day Prank Contest

Here is a link to the reply page that I used:

I'm fairly new to Arduino projects, so the wiring diagrams and sample source code from 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 (the most interesting parts of it anyway):


And here is my wiring diagram:

Step by step instructions

Following the instructions from I ended up with this:

Moved on to the sample code from 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 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

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.


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 >:)


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 to get quickly into prototyping. I'll definitely be going there in the future. Thanks for looking at my project!


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 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
    while (!Serial) ; // wait for serial port to connect. Needed for native USB

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)) {
          triggered = true;
          armed = false;
        else {
          //Serial.print(F("Distance: ")); Serial.print(hcsr04Dist); Serial.println(F("[cm]")); // print triggered distance for debug

    //Wait for reset signal
    while (triggered==true) {
        bool pushButtonVal =;
        if(pushButtonVal) {
          triggered = false;
       else {

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

// 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);
    piezoSpeaker.playMelody(piezoSpeakerNNBBLength, piezoSpeakerNNBBMelody, piezoSpeakerNNBBNoteDurations); 

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);
No Candy For YOU!! Arduino Project Code


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


Similar projects you might like

Automatic Fear 1.0

Project showcase by Alexis Santiago Allende

  • 9 respects

Pranked! Moving Tissue Box |

Project tutorial by Arduino “having11” Guy

  • 23 respects

Arduino Darkness Activated Ghost

Project tutorial by Technovation

  • 13 respects

Arduino Project: Burglar Zone Input Tester

Project tutorial by Cezarjar

  • 7 respects

The Troll Switch

Project tutorial by Aitor Gamarra

  • 7 respects

Candy Dispenser with Google Assistant

Project tutorial by Arduino “having11” Guy

  • 1 comment
  • 60 respects
Add projectSign up / Login