Autonomous Pumpkin Candy Dispenser: Socially Distanced Pumpkin
Introduction: Autonomous Pumpkin Candy Dispenser: Socially Distanced Pumpkin
Halloween will be different this year! This project allows for automatic hands-free candy distribution using a lego-pumpkin as the candy container and an Arduino/Lego Power Functions arm.
Supplies
Materials:
Velcro (scissors for cutting)
Electronics:
1 - USB Cable to connect Arduino to Computer
1 - 9 Volt battery with wire connector
1 - 330 ohm resistor
1 - Arduino Nano
1 - Breadboard
1 - Infrared Transmitter
4 - wires (male one end and female other end)
1 - Ultrasonic sensor
Lego Electronics:
2 - Medium Motors
1 - Extra Large Motor
2 - Infrared Receivers
1 - Lego Battery
Legos:
See list of lego parts
Note: other pumpkin-related colors (e.g., tan, dark tan) may be used in lieu or Orange
Step 1: Build the Pumpkin
Follow the steps (see photos 1-15) to create the body (see photos 1-7) of the pumpkin and the top (see photos 8-15) of the pumpkin.
Step 2: Build the Arm
Follow the steps (see photos 1-44) to create the moving arm (see photos 45-51 completed arm from back, front, left, and right sides) for the project.
Step 3: Add the Arduino and Electronics
Now that you have the legos portion completed, it is time to add the Arduino and other electronics parts.
1) Attach wire cap to 9-volt battery and Arduino to the breadboard (see photo 1).
2) Attach the ultrasonic transmitter to the breadboard (short negative leg to ground row and long positive leg to empty row) and the 330 ohm resistor to the bread (one leg to empty row and one leg to row D11. Photo 2 shows a close up view.
3) Connect female ends of four wires to ultrasonic sensor (yellow to VCC pin, maroon to ground pin, green to trig pin, and blue to echo pin). Photo 3 shows a close up view.
4) Connect male ends of four wires to breadboard (VCC pin to 5V row, ground pin to ground row, trig pin to D2 row, and echo pin to D3 row). Photos 4 and 5 show close up views.
5) When connecting 9 volt battery to Arduino, connect negative to ground and positive to Vin (see photo 6).
6) Apply felt side of velcro to each wide side of the 9 volt battery. Apply hook side of velcro to bottom of breadboard and the top of the 2x4 plate. Attach breadboard to battery and battery to 2x4 plate (see photo 7).
7) Attach 5-2x4 bricks together. Attach 2x4 plate (the one attached to battery) to top of 2x4 bricks (see photo 8).
8) Attach 3-2x4 bricks together. 832
Attach 3 modified tiles with clip on top at shown in photo 9.
9) Slip ultrasonic sensor into the clips (see photo 10).
Step 4: Code the Arduino
Prerequisites
If you are not familiar with writing Arduino Code or using the Lego Power Functions Library to control Lego Motors, please read the "How to Move Lego Motors Autonomously Using Arduino" Instructable (steps 1-5):
Arduino Software Set Up
Power Function Library Set Up
Infrared Transmitter Set Up
Write Arduino Code
Writing Power Function Motor Code
Writing Project Code for Arduino
Below is the code for the Autonomous Pumpkin Candy Dispenser (Social Distancing) Project. It is also available for download (see file 1). Note that the delay command on the line below each lego.singleOutput() command determines how long the motor runs. So for the extra large turntable motor, it determines how far the turntable turns. The goal is 90 degree turns; however, your exact time may defer from mine. It is important to experiment and tweak the code accordingly. For the medium motors; one motor bends/extends the elbow (the delay determines how much it bends/extends) and the second motor closes/opens the grip feature (the delay determines how much it opens and closes). 991