Build a Confetti Bot With a Raspberry Pi
by sguequierre in Circuits > Robots
1890 Views, 10 Favorites, 0 Comments
Build a Confetti Bot With a Raspberry Pi
Are you tired of boring celebrations with the same old confetti popping techniques? You can now design your very own confetti-popping robot with a big red button that will make your parties a colorful blast, literally! With this robot, you’ll become the life of the party with just one press of a button. Whether it’s a birthday party, a wedding, a company launch, or just a random Wednesday night, this robot will add an extra dimension of fun and excitement to any event.
In this instructable, you’ll learn how to build your very own confetti bot using Viam.
This robot turns a motor when you press a button, which then sets off a confetti cannon and makes it rain confetti.
You can expand on this project to turn a motor based on other types of inputs, such as when a specific sensor goes high.
(Written by Hazal Mestci and posted by Sierra Guequierre)
Supplies
Hardware
- A macOS or Linux computer
- A Raspberry Pi, with a microSD card, set up using these instructions.
- A big button, like this one. Check the wiring diagram for the specific model you have as you wire the button.
- A mini confetti cannon, like this one
- A gpio motor. We used the Bemonoc 25GA370 DC Encoder Metal Gearmotor 12V. The STL files we use for 3D printing are adapted to the size of this motor, but you can update the design depending on the model you have.
- A L298N Motor Driver
- A 12V battery with a charger
- Jumper wires
- Alligator clips
- M2.5 x 16mm screws and M2.5 nuts
- A 2.4mm screwdriver
- a 3D printer and optionally a laser cutter (for the enclosure)
Software
Set Up Your Hardware
3D Print the enclosure
3D print the enclosure using these STL files. If you are using a different confetti cannon, you may need to adjust the size of the 3D prints to your confetti cannon size, as the wall thickness of the holder changes between brands. The same applies for the motor, if you are using a different model, you can adjust the size for the motor so the holder fits your motor head.
You can either laser cut or 3D print the side panels depending on your liking, and which machine you have access to.
Wire your motor, motor driver, board, and the battery
First, attach your motor with screws to the middle of the enclosure. Attaching the motor first makes wiring the rest easier.
Because of the model we have, we only used two screws for the top, but some motors require four which is why the enclosure has four holes.
Now wire all of the components according to the wiring diagram:
- Connect your motor to the motor driver. There are several wires coming out of the motor, connect the black one (ground) into Out1 terminal and the red one (power) to Out2 terminal and screw them in tightly (a 2.4mm screwdriver works well for this). After you have finished screwing the block down, make sure it is secure by gently tugging on the wire. If it is not secure, the wire will come out. You can leave the other wires disconnected.
- Connect your Raspberry Pi to the motor driver. Since you are using Out1 and Out2 on the driver, you need to use the corresponding inputs (In1 and In2), as well as a PWM pin. Select three available GPIO pins on the Raspberry Pi and connect them to the ENA (green wire in the wiring diagram), In1 (yellow wire in the wiring diagram), and In2 (orange wire in the wiring diagram) pins on the motor controller. Take the black safety cap out from the motor driver so you can use the ENA pin. Make sure to remember which GPIO pin on the Raspberry Pi you connected to each of these inputs. In our case, we connected Pin 11, 13, and 15 respectively.
- Connect your button to the Raspberry Pi. One of the connections goes to a 3.3V pin on the Raspberry Pi, and the other needs to be connected to a GPIO pin. We used Pin 1 for 3.3V (blue wire in wiring diagram). Make sure to record which GPIO pin you connect to since you will be using this in your robot configuration. We used Pin 37 (white wire in wiring diagram).
- Now you can connect the button to your 12V battery, use a black alligator clip to connect the ground of the button switch to the ground of the battery. Then from the same ground of the battery, use a black wire to connect to the ground pin on the motor driver. The ground of the motor driver will be shared with the Raspberry Pi, and your battery. Find a ground pin on your Raspberry Pi and connect it to the ground pin on the motor driver, allowing two pins to share the ground. Screw them tight with a screwdriver. We used Pin 6 on the Raspberry Pi as our ground pin, but you can use any Raspberry Pi ground pin.
- Now that you have grounded your robot, you can connect the motors to power. Use a red alligator clip to connect the battery to the button switch, and another red alligator clip to connect the battery to the 12V input on the motor driver.
- Your robot wiring is now complete! Put the microSD card in the Raspberry Pi and turn it on by plugging it to the wall.
Configure Your Confetti Bot With the Viam App
Now that your robot is wired, you need to configure it on the Viam app before you can program it.
Create an account on the Viam app.
In the location of your choice, create a new robot and give it a name. We named ours ConfettiBot.
Then, navigate to the robot’s Config tab to start configuring your components.
Select Raw JSON mode. Replace the configuration with the following JSON configuration for your board and your motor:
{
"components": [
{
"name": "party",
"type": "board",
"model": "pi",
"attributes": {},
"depends_on": []
},
{
"name": "start",
"type": "motor",
"model": "gpio",
"attributes": {
"pins": {
"a": "13",
"b": "15",
"pwm": "11"
},
"board": "local",
"max_rpm": 1000
},
"depends_on": ["local"]
}
]
}
Click Save Config at the bottom of the screen.
Let’s test our configuration from the Control tab. Open your board's panel and set the pin connected to your motor (in our case pin 37) to high. Now, you should see your motor turning.
Attach Components to the Enclosure
Now that you have tested your motor in the app and confirmed that everything works, you can finish assembling your confetti bot.
Attach the motor driver to the enclosure wall with four M2.5 x 16mm screws and M2.5 nuts:
Slip the Raspberry Pi into the designated slot in the enclosure. Be careful of the wires during this so they don’t pop off.
Add the confetti cannon to the enclosure by tightening the 3D printed holder around the confetti socket using one M2.5 x 16mm screw and a M2.5 nut. Then connect the enclosure to the front panel.
Next, attach the 3d-printed circular holder to the base of the confetti cannon to hold its place, then to the motor. Secure the two together with a screw from the side. Depending on your motor size, you may need a different screw size.
Add the front section you just built to the rest of the enclosure using M2.5 x 16mm screws and M2.5 nuts. Make sure to do this step before closing the side walls to be able to access the slots for screws.
(Optional) Laser-cut or Print the Sides
If you don’t have a laser cutter, you can 3D print the sides using these STL files, or leave them empty.
Final design
The final design, fully wired and put together looks like this:
Write Python Code to Control the Confetti Bot
The following section explains the code for the confetti bot. The completed code for this project is available on GitHub. If you copy the code from this link, don’t forget to change your robot address and secret so it connects to your own confetti robot.
Navigate to the Code sample tab on the Viam app, select Python as the language, and click the Copy button.
By default, the sample code does not include your robot location secret. We strongly recommend that you add your location secret as an environment variable and import this variable into your development environment as needed.
To show your robot’s location secret in the sample code, toggle Include secret on the Code sample tab. You can also see your location secret on the locations page.
Paste this into a new Python file in your favorite code editor to connect to your robot.
At the top of the code, your board and motor components are imported:
from viam.components.board import Board
from viam.components.motor import Motor
In your main function add the following code, which instantiates a variable party as the board and start as the motor:
party = Board.from_robot(robot, "party")
# Note that the pin supplied is the pin we use. Please change this to the pin
# you are using.
party_return_value = await party.gpio_pin_by_name("37")
print(f"party gpio_pin_by_name return value: {party_return_value.get()}")
start = Motor.from_robot(robot, "start")
start_return_value = await start.is_moving()
print(f"start is_moving return value: {start_return_value}")
The only other code you need to add to your main function is a while loop to check if the button is being pressed. Copy this code and add it to your own code within the main function block:
while True:
print(party_return_value.get())
while (await party_return_value.get()):
await start.set_power(.8)
await asyncio.sleep(0.1)
if not (await GPIO.get()):
break
await start.set_power(0)
This is all the code you need to activate the gpio pin and turn the confetti cannon that is attached to your motor!
Next Steps
In this tutorial, you learned how to turn a motor when a button is pressed and set off a confetti cannon. You could use this same concept for any simple robot that involves turning a motor when a pin on the Raspberry Pi goes “high.” One example of this logic would be connecting a PIR sensor to a Raspberry Pi. You could then make a motor turn whenever you sense a person walking by.
For more robotics projects, check out our other tutorials.