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 tutorial, 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.
Requirements
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 machine 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.
In the Viam app, create a new machine and give it a name. We named ours ConfettiBot.
Navigate to the CONFIGURE tab of your machine’s page in the Viam app.
Configure the Pi as a board
Click on the Components subtab and click Create component in the lower-left corner of the page.
Click the + icon next to your machine part in the left-hand menu and select Component. Select the board type, then select the pi model. Enter party as the name and click Create. You can name your board whatever you want as long as you refer to it the same way in your code; we picked for fun. Your board configuration should now look like this:
Configure the motor
Click the + icon next to your machine part in the left-hand menu and select Component. Select the motor type, then select the gpio model. Enter start as the name for your motor component and click Create. We named it “start” to refer to the button being pressed, but this name is up to you as long as you remember the name and use the same name in the code later.
After clicking Create, there is a pin assignment type toggle. Select In1/In2 since that is compatible with the type of input our motor controller expects. In the dropdowns for A/In1 and B/In2, choose 13 GPIO 27 and 15 GPIO 22 and for PWM choose 11 GPIO 17 corresponding to our wiring.
In the Board dropdown within attributes, choose the name of the board the motor controller is wired to (“party”). This will ensure that the board initializes before the motor driver when the robot boots up.
Click Save Config at the bottom of the screen.
Let’s test our configuration from the Control tab. Go to the board panel, set the pin connected to your motor (in our case pin 37) to high, and your motor should turn.
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
Laser cut the sides of the enclosure and attach with screws. You can find the designs on Viam Labs’ GitHub.
If you don’t have a laser cutter, you can 3D print the sides instead, 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 machine address and secret so it connects to your own confetti robot.
Navigate to the CONNECT tab on the Viam app, select Python as the language, and copy the sample code. Paste this into a new Python file in your favorite code editor to connect to your machine.
API KEY AND API KEY ID: By default, the sample code does not include your machine API key and API key ID. We strongly recommend that you add your API key and API key ID as an environment variable and import this variable into your development environment as needed. To show your machine’s API key and API key ID in the sample code, toggle Include secret on the Code sample tab. You can also see your API key and API key ID on your machine’s Security tab.
CAUTION: Do not share your API key or machine address publicly. Sharing this information could compromise your system security by allowing unauthorized access to your machine, or to the computer running your machine.
At the top of the code, your board and motor components are imported:
In your main function add the following code, which instantiates a variable party as the board and start as the motor:
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:
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.
Have questions, or want to meet other people working on robots? Join our Community Discord.