Halloween Candy Pumpkin

508

1

1

Introduction: Halloween Candy Pumpkin

For the celebration of this year's Halloween and in order to go deeper in our Arduino learning, we have been given the challenge of creating an animatronic device based on the Halloween festivity. The idea was to create a decoration using arduino hardware and software to make it interactive and “smart”.

Our idea was to build a pumpkin with LED lights and some movement that you can activate in order to take the candies that the angry pumpkin is defending. The functionality of our pumpkin starts with a pair of red LEDs that switch off once an ultrasonic sensor detects the proximity of a person creating tension and catching the attention of the user. After that, to take the candies from the pumpkin all you will need to do is push the little button and let the magic happen. But you have to be fast, instead, the pumpkin will cover them again and you won’t get your treat.

In this tutorial we are going to show you step by step how to build yours with your own hands, starting with the supplies you will need, the electrical and mechanical design and the final assembly of all the components.

Supplies

Electronic material:

  • Arduino UNO
  • Breadboard
  • LED lights
  • Push button
  • Ultrasonic sensor UH-SR04
  • Micro Servomotor
  • 220 Resistance
  • Wires

Other material:

  • Plastic pumpkin
  • EVA rubber sheet
  • Wood plank

Step 1: Electronic Connections

First, we did the circuit using the TINKERCAD program, where we could define how we wanted the circuit to be and which components we wanted to use. We will use a breadboard to connect everything.

LED lights: the negative pin is connected to the ground and the positive one is connected to the digital pin on the arduino with one 220 ohm resistance, in our case it is connected to the digital 12 and 13 pin, but can be connected to the other digital pins as if you wanted, but only to the digital pins. Push button: the left one is connected with a 220 ohm resistance on the 5V and between them is connected with one wire on the digital pin and the right one is connected on the ground. Micro Servomotor: the micro servomotor has three pins to be connected. The red one is connected to the arduino board 5V, the brown one is connected to the ground and the orange(PWM) one is connected to the digital pin with the - sign. Ultrasonic sensor Hc-SR04: This sensor has four pins to be connected. The Vcc on the 5V, the Trig on the digital pin without sign, the Echo on the digital pin with sign and the GND on the ground.

Step 2: Arduino Code

This step is to make the Arduino program. Before all, don’t forget to add the library file of the Ultrasonic sensor HC-SR04.

Here you have the link to download the file: https://www.arduino.cc/reference/en/libraries/hcsr04-ultrasonic-sensor/

CODE:

//First, include the servo motor and the ultrasonic sensor library on the top #include #include

HCSR04 hc(7, 6); Servo myservo;

//This variables are the outputs that we used: int buttonPin = 10; //push button int buttonState = 0; int ledpin1 = 12; //LED light int ledpin2 = 13; //LED light

//The following we initialize the inputs and outputs: void setup() { Serial.begin(9600); //Set the data rate in bits per second for serial data transmission pinMode(ledpin1, OUTPUT); pinMode(ledpin2, OUTPUT); myservo.attach(11); //The micro servomotor is connected on the digital pin 11 pinMode(buttonPin, INPUT); }

//The following we read the state of value of the components: void loop() { Serial.println( hc.dist() ); //That is for measure the distance range of the ultrasonic sensor

//Turn the lights off: digitalWrite(ledpin1, LOW); digitalWrite(ledpin2, LOW);

//Turn the lights on if the person distance is higher than 150cm: if (hc.dist() > 150 ) { digitalWrite(ledpin1, HIGH); digitalWrite(ledpin2, HIGH); }

buttonState = digitalRead(buttonPin); //Read the value of push button pin Serial.println(buttonState); //Prints the push button data

//Read the state of the push button, if the button is pressed (LOW), the servomotor turns 120 degrees and returns to the initial position. if (buttonState == LOW) { myservo.write(120); //Set the angle where we need to open the cover delay(3000); //Set the seconds what we want to be maintained opened the cover myservo.write(0); //Set to turn the initial position delay(500);//Set the seconds where takes react after pressing the button } }

Step 3: Electronic Assembly

One of the first steps we took was to make the assembly of all the electrical and electronic components in order to see our limitations and the amount of space it will take. Also we had to see the capabilities of the ultrasonic sensor and find the best position to switch the LEDs off.

So, we started the assembly and after we had all built, we started looking for the optimal distance to turn off the LEDs. To make it we used the function of “Serial.println( hc.dist() );” to see the range of the ultrasonic sensor. After reading and watching the distances in real life, we decided that 80cm was a fair distance for switching the lights off and catching the attention of the user.

Step 4: Set the Cover Door With the Servo

After checking the distance we wanted to take to turn off the lights, we started doing the assembly of the whole prototype.

We decided to start with the larger components that our animatronic had, in our case was the servo. Our idea was to put a rotative door on top of the pumpkin to cover the candies that are placed on a cup inside the pumpkin. To make this system, we had to elevate the servo to put it as close to the edge of the opening as possible using a plastic part with an L form. Also we had to make the holes for the cables at the bottom of the pumpkin because we decided to place all the electronic components (the motherboard and the protoboard) on a base where they could be safe.

Step 5: Create the Base

At this point we decided to create a base where the motherboard could rest safe and avoid disconnections of the cables. To make this base, we cut a pair of pieces of wood to make the top and the bottom and we drilled them to four other pieces of wood placed on each corner.

Step 6: Set the Cup for Candies

After putting the servo at the right height we glued the coup where the candies will be at the plastic part where the servo is attached to. We had to cut the cup a little bit in order to make it fit with the tight space we had.

Budget tip: We used the cap of a spray to make the cup for the candy and painted it in black color.

Step 7: Install the Ultrasonic Sensor

With the servo and the coup to hold the candies in place it was now the moment to install the next sensor which was the ultrasound sensor. This sensor should be facing the user to be able to measure the distance correctly. To make it we chose to make two holes on the nose of the pumpkin to fit the sensor. To make this holes there’s no secret, you have to measure the diameter of the two cylinders that it has and make the holes with the correct size.

Also, don’t forget to make the holes for the cables at the bottom to be able to connect the sensor to the motherboard.

Step 8: Set the LEDs

Once we had the ultrasound sensor placed, we reached the 50% of the assembly. Now was the turn for the LEDs. These LEDs needed to be also in the front of the pumpkin to be able to catch the attention of the user easily. Like the ultrasonic sensor, we had to make two holes, one on each eye, to fit the LEDs. The procedure for the holes is as simple as the other sensor, measure and drill to the correct size. The connections for the cables of the LEDs are quite tricky and the cables can disconnect with some ease so we decided to weld them to avoid failures. Very important consideration, connect the cables correctly the ground to the ground and the one that goes to the pin with the one that goes all the way to the pin.

Step 9: Set the Button

Finally it was time to connect the button to activate the system and open the gate for the candy. This button should also be easily accessible for the user so we also decided to put it in the front, however, this time we have placed it on top of the base not at the pumpkins surface. Like the LEDs, the connections for the cables were quite tricky and they don’t fit very well, so we decided to weld the cables to the button connections.

The button looks like a spyder with four legs that are where the cables are connected, so, to fit the button to the base we had to make four holes, one for each leg to let the connections have space to connect the cables and go all the way down to the motherboard.

Step 10: Connect the Cables

After everything was placed it was time to connect again all the cables to the motherboard correctly and make some tests to see if it was working correctly without flaws.

Step 11: Final Touches

Now we had everything connected nice and working flawlessly so it was time for the final touches. We covered the sides of the base with some pieces of foam and stick to the corners with a piece of velcro to be able to remove them if we need to make some maintenance in the future. We also painted the eyes and the mouth of the pumpkin that lost some of the colour during the process and we put some decorations around to make it more special. And voilá, your animate pumpkin is ready to rock!

Step 12: Final Thoughts

This is how we made your interactive pumpkin, we hope you didn’t have any issues with the assembly and the codification of the program. This little project helped us understand better the functionality of the Arduino system and the different applications where we can use it. We hope you enjoyed this process and we challenge you to create yours and even make it a bit different adding some other functionalities to make it even cooler. And remember, be fast or you won’t get your candy!

Halloween Contest

Participated in the
Halloween Contest

Be the First to Share

    Recommendations

    • Space Contest

      Space Contest
    • 3D Printed Student Design Challenge

      3D Printed Student Design Challenge
    • Retro Tech Challenge

      Retro Tech Challenge

    Comments

    0
    randofo
    randofo

    11 months ago

    This year I hung candy for trick or treaters outside from clothespins. This is definitely a more high tech and fun experience.