Foam Dart Launcher Robot Tutorial
Introduction
This tutorial will show you how to build your very own foam dart launcher robot using Viam, a Raspberry Pi, a generic foam dart launcher with foam darts, a USB camera, a solenoid, a relay, and a motor controller. This robot will be able to move around and launch foam darts.
This project is a great place to start if you are new to building robots, have a love for Nerf toys, an occasion to target something and launch a dart at it, or if you just want to troll your friends. Don’t forget to be careful and have fun!
What You’ll Need for This Tutorial
You will need the following hardware, software, tools, and consumables to complete this project:
Note
If you use a different rover and/or motor controller, ensure that the motor driver is compatible with the motors on your rover. For example, a brushed DC motor requires a brushed DC motor driver that is rated for the power requirements of the motor. Also, the configuration files shown in this tutorial must be modified if you use a different setup.
You can find more information on configuring different motors in the Motor Component topic.
Hardware and software requirements
- Raspberry Pi with microSD card, with
viam-server
installed per our Raspberry Pi setup guide. - A wheeled rover
- A foam dart launcher
- A USB camera (webcam) (optional, to see where you are going and aiming)
- A solenoid
- A relay
- A dual motor controller If you use a different motor driver, refer to the manufacturer’s data sheet and our motor component topic to learn how to configure the pins.
- Jumper wires (breadboard wires)
Tools and Consumables
- Solder (optional)
- Small flathead screwdriver
- Cutting pliers (flush-cutting pliers preferred)
- Electrical tape
- Elastic/rubber bands
How to Assemble Your Hardware
Motor Controller Setup
A motor controller is a piece of hardware that takes digital signals from the Raspberry Pi and sends power to the motors accordingly. For this setup we have one dual motor controller for the two motors.
Note
If you have more than two motors you will likely need two motor controllers.

We need only worry about OUT1 through OUT4, IN1 through IN4, 12V, and ground.
- Attach left to the motor controller.
- Use a small flathead screwdriver to loosen the Out1 and OUT2 screw terminals.
- Place the red motor wire into OUT1
- Place the black motor wire into OUT2
- Use the flathead screwdriver to tighten the terminals to firmly hold the wires in place. Note: Tightly twisting each stripped wire end and then tinning it makes it easier to insert and secure the jumper in screw terminal connectors.
- Connect the control wires IN1 and IN2 to your Raspberry Pi.
- The example robot has IN1 -> pin 11, IN2 -> pin 13
- Repeat steps 1-2 for the right motor using OUT3, OUT4, IN3, IN4
- The example robot has IN3 -> pin 16, IN4 -> pin 18
- Connect the external power that will supply power to the motors.
- In the example we have 4 AA batteries connected to the motor driver giving us 6V of power for the motors.
Camera Setup
This is as easy as plugging the camera into a USB slot on your Pi. We’ll configure the camera in the Viam app in later steps.
Relay/Solenoid Setup
The solenoid component actuates the foam dart launcher trigger. The relay works as a switch to turn on and off the solenoid. This allows us to activate the foam dart launcher with a GPIO pin on the board.
Note
We cannot directly power these components from GPIO pins, since there is a board limitation that restricts GPIO pins to providing 3.3V and a very limited current supply (16mA). Even the 3V and 5.5V power pins on the Pi supply are limited to about 1A.
If a component attempts to pull more current than that, you risk power cycling the Pi. That is why we use a relay to supply 5VDC with a higher current to actuate the solenoid. This is standard practice for power control circuits in many situations. For example, by using a common off-the-shelf 15A light switch to actuate a relay bank, it is possible to control hundreds of amps of lighting for an entire office floor.

- Connect the solenoid to the relay.
- Connect a wire to the Normally Open (NO) terminal connector.
- Connect the other end to a ground pin on the Raspberry Pi.
- Connect the Relay COMmon pin.
- Connect the COM pin to the 3.3V power of the Raspberry Pi.
- Connect VCC (DC+) and ground (DC-) .
- Connect DC+ to the 5V of the Raspberry Pi.
- Connect DC- to ground on the Raspberry Pi.
- Connect IN.
- Connect IN to a GPIO pin on the Raspberry Pi.
- For this example, we've connected to pin 37.
Assemble Solenoid/Foam Dart Launcher

- Modify the foam dart launcher to make room for the solenoid. Using cutting pliers, we cut the trigger guard off of the front as seen in the picture above.
- Test that the solenoid has enough power to press the trigger when the foam dart launcher is loaded.
- If the solenoid is not strong enough we can:
- Wrap the trigger with rubber bands to make the trigger easier to activate1.
- Increase the voltage to the solenoid. Right now it receives 5 volts, but some solenoids can support up to 12 volts. If necessary, you can connect the solenoid to another power supply such as a 9 volt battery. Check the details of your solenoid2.
- Tape the solenoid in such a manner that it makes good contact with the trigger when activated with the relay.
- Attach all of your components to the base.

Configure Your Foam Dart Launcher Robot with the Viam App
Create a new robot in the Viam app and give it a name.
Board Configuration (Raspberry Pi)
Add your board with the Name local
, Type board
, and Model pi
.
Click Create Component.

You can name your board whatever you want, we picked local
.
Just remember to use that name consistently in the following steps.
Motor Configuration
Left Motor
Add the left motor with the Name left
, Type motor
, and Model gpio
.
Click Create Component.
Select the name of the board the motor controller is wired to (for example, “local”) from the Board drop-down.
Toggle the Component Pin Assignment Type to In1/In2 since that is compatible with the input type our motor controller expects.
In the A/In1 and B/In2 drop-downs, choose 11 GPIO 17
and 13 GPIO 27
, respectively.
Set Max RPM to 150
.

Click Save config at the bottom of the screen.
Right Motor
Add the right motor with the Name right
, Type motor
and Model gpio
.
Click Create Component.
Select the name of the board the motor controller is wired to (for example, “local”) from the Board drop-down.
Toggle the Component Pin Assignment Type to In1/In2.
For A/In1 select 16 GPIO 23
and for B/In2 select 18 GPIO 24
.
Set Max RPM to 150
.

Click Save config at the bottom of the screen. Then go to the Control tab where you will now see the buttons you can use to control the motors:

Now you can drive your left and right wheels separately. Let’s add a base to be able to control them together.
Base Configuration
Configure a base component to coordinate your motors so you can move the base around with your keyboard.
Give it a Name (you can just call it “base”), set Type to base
, set Model to wheeled
, and click Create Component.
From the Right Motors and Left Motors drop downs, select right
and left
, respectively (the motors you configured in the previous step).
Set the Wheel Circumference to 200
and the Width to 130
if you used the same rover we did.
If you used different hardware, measure the diameter of your wheels and multiply by pi for the circumference.
Measure the distance between the centers of the right and left wheels to find the width.

Now let’s add a camera to watch the video stream on the control panel as you move your rover.
Camera Configuration
Add your USB camera as a webcam. Please refer to our webcam documentation for complete instructions.

If you go back to the Control tab and click to expand the base panel, you will see your base and camera:

Toggle the switch under Keyboard Disabled to enable keyboard control, then use the W, A, S, and D keys on your keyboard to move your rover around. You can view the camera stream at the same time.
Final Config
The full raw JSON config file generated by the configuration steps you just completed will look like this:
If you prefer you can copy paste it, replacing the Raw JSON field on your robot’s Config tab instead of going through all the steps above.
Toggling GPIO Pin States
The board card in the Control tab provides a way to change the state of the pin connected to the solenoid. If you click the board component, you will be able to see your GPIO pin and its current state. In the Set part of the GPIO section, select pin 37 (the pin we wired to control the solenoid). If you set the pin state to high, the solenoid will actuate. If you set it to low, it should deactivate the solenoid. Since we already assembled the robot, setting pin 37 to high launches your foam dart launcher if its loaded.



Control with the Viam App
Controlling the Base
- Navigate to Viam app -> base component
- Enable keyboard controls
- Drive your robot around!
Activating the Foam Dart Launcher
- Make sure your foam dart launcher is loaded and ready to go.
- When you are ready, navigate to the Viam app -> Control tab -> board component and set the IN pin (pin 37 in our example) to high to activate.
You can see the demo video of it in action here:
Troubleshooting
If any component fails to appear when connecting to the robot in the Viam app, check the Logs tab for potential errors.
Summary
In this tutorial, you learned how to create a remotely-controlled foam dart launching robot activated by the GPIO pins on a Raspberry Pi using Viam. You could use this same concept as the basis for a security robot that launches darts at people if they enter your room, a Nerf ball blaster dog toy, a kitten treat shooter for cats to fetch in excitement, you name it! You could even add object detection and machine learning and activate the launcher only when the camera sees a specific object or person.
If you are looking for a new robotics project, check out our other tutorials.
You can also ask questions in the Community Discord and we will be happy to help.
If you use the rubber band method, you may need to pull the rubber bands away from the trigger when reloading the foam dart launcher so it can reset and load properly. Try activating the solenoid manually to ensure that it hits the foam dart launcher trigger in the right spot. ↩︎
If you choose to increase the voltage, you must connect VCC and ground (DC+ and DC-) to the new voltage source rather than connecting them to the Raspberry Pi as described in Step 3 of Assemble Solenoid/Foam Dart Launcher. ↩︎
Have questions, or want to meet other people working on robots? Join our Community Discord.
Was this page helpful?
Glad to hear it! If there is anything we could be doing better, please create an issue.
We're sorry about that. If you'd like to talk to us for help, please join the Community Discord. To ensure we know what's wrong with this page, you can also open an issue.