Halloween Candy Pumpkin

by pan.songx.1029 in Circuits > Arduino

757 Views, 3 Favorites, 0 Comments

Halloween Candy Pumpkin

565c9362-e39e-45ca-b59e-1aa4310be012 (2).jpg

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

Electronic Connections

tinkercad .jpg

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.

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 } }

Downloads

Electronic Assembly

dd146bc9-8016-4c96-bc86-f6efda7dcc6d.jpg
f015b9f2-b3fc-487b-bad9-a7920b1f3d7e (2).jpg

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.

Set the Cover Door With the Servo

4df81063-665e-483d-ae2c-05e6e08f4831.jpg
eee162f3-2dd2-4623-a825-6e25a5db3d7b.jpg

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.

Create the Base

b4aa6616-a108-4735-8c55-ffc41e6b8175 (2).jpg
4cf3bb69-0967-4a9c-a3e5-632ff7249a34.jpg

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.

Set the Cup for Candies

eee162f3-2dd2-4623-a825-6e25a5db3d7b.jpg
538dc3d0-0ad9-4f30-a6e0-29ee21df052a.jpg

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.

Install the Ultrasonic Sensor

64ee90df-cefc-4e5c-998e-3e9511b0dbcc.jpg
5141e349-6a80-474e-9d94-45598fd584d2.jpg

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.

Set the LEDs

804efd49-0da6-41ab-9cc6-e581954671fd.jpg

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.

Set the Button

64ee90df-cefc-4e5c-998e-3e9511b0dbcc (2).jpg

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.

Connect the Cables

b6b67ea9-6352-4a7e-8b8d-bba8ed096ac7.jpg
804efd49-0da6-41ab-9cc6-e581954671fd.jpg

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.

Final Touches

664ad7ff-a063-428c-af04-c389e778d07a.jpg
9af31455-ba3b-40d8-8f55-344b0b64c065.jpg
8f43fd7c-9af1-42d8-be81-57f8e449752a.jpg

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!

Final Thoughts

61cc452a-9411-40e7-9906-5ef4921b18c5.jpg
7a758c49-7065-40f3-8cab-4559c610783f.jpg
87d5ba3a-8a0a-4c94-a12c-5082a2ac6111.jpg

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!