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.
RequirementsHardware- 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)
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 to 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 batteryFirst, 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 thewiring 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 thewiring diagram)
Now you can connect the button to your 12V battery, and 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 into the wall.
Now that your robot is wired, you need to configure it on the Viam app before you can program it.
Create a free account on the Viam app.
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.
Configure the Pi as a boardClick on the Components subtab and click Create component in the lower-left corner of the page.
Add your board with thetype board
and model pi
. Enter party
for the name of your board component, then 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 party
for fun. Your board configuration should now look like this:
Click on the Components subtab and click Create component in the lower-left corner of the page. Select motor
for the type and gpio
for the model. Enter start
for the name of your motor component, then click Create. Again, 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 drop downs 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 drop-down 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.
Now, 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 enclosureNow 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 an 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.
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.
The final design, fully wired and put together looks like this:
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.
LOCATION SECRETBy 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.
CAUTIONDo not share your location secret, part secret, or robot address publicly. Sharing this information could compromise your system security by allowing unauthorized access to your robot, or to the computer running your robot.
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 used. Please change this to the
# pin you are using on the Pi.
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 stepsIn 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.
Hazal Mestci
Comments