Introduction: Scanner Turret and Cannon

We were meant to make a functional prototype using some different arduino sensors so our choice has been to develop a turret with a cannon that fires a bullet to an object that the scanner has detected.

The functioning of the turret starts with the constant movement of the scanner doing a 180 degree sweep, when it detects something, the cannon moves pointing directly to the direction which the scanner is pointing to and using two buttons, one for the loading and another for shooting, a bullet gets fired.

It also will show on screen the detected objects via a radar interface.

Project by Jaume Guardiola and Damià Cusí

Step 1: Materials Needed.


- 1x DIN A4 methacrylate 0,4mm sheet.

- 1x Wooden 0,3mm sheet. Dimensions: 600mm x 300mm.

- 1x Hinge.

- Hot glue.

- Epoxy bicomponent glue.

- Superglue.

- Wooden block.

- Elastic band.

- Pen tube.

- Small string.


- 3x servo motor MMSV001. (

- 1x ultrasonic proximity sensor HC-SR04. (

- 1x arduino nano.

- Connection wire (red, black and white if possible).

- Tin.

- Welder.

Step 2: Design

The turret exterior design drawings were made on Autocad. This file shows all the parts needed for the external assembly that will cover the cannon and radar mechanism.

Step 3: Laser Cut Wooden Sheet.

With the Autocad file we are able to laser cut the shapes for better accuracy and better look overall but they can also be handmade extracting the measurements from the file.

Step 4: Assembly Introduction

Our cannon will be divided in two main structures. There will be a base holding inside all the servo-motors, connections, as well as the arduino Nano board; then there's the moving cannon on top, holding another servo-motor inside and the shooting mechanism.

In this step we proceed to assemble the base as shown in the photo, hot glue or epoxy glue can be used. The hole in the center is designed to keep the servo that will move the cannon (it can be inserted from the upper side) and beneath it (ideally coaxially) we will mount the servo that will move the ultrasonic sensor.

Step 5: Cannon Design

For the cannon design we used some squared wood chunks and a couple of methacrylate laser-cut parts. You can also find the Autocad drawing here.

To assemble it we used hot glue and reinforcements of masking tape, but it can be glued together any way you want.

The cannon tube is a regular pen tube and the ammo will be airsoft regular ammo. Also an elastic band will be used to keep the required tension for the mechanism to shoot and a string to pull the shooter up when reloading needs to be done.

All measurements in the drawing are in millimeters; the cannon tip is raised 3mm because this way the bullet will always remain at the end of it and can be shot from behind. Also a little glue has been added at the end to keep the bullet inside but at the same time let the shooter hit it.

The servo on the upper part of the cannon is the shooter release and reload mechanism, attached to the servo there's a lever that in horizontal position will interfere with the shooter path and keep it half way into hitting the bullet and, when raised, it will add a bit of tension to the shooting mechanism and loose contact with it at aproximately 30 degrees, letting it follow its path and shoot (see picture above). To reload you'll have to pull the mechanism back up past the 30 degree point using the string attached and then press the reload button, which will take the servo back to the initial horizontal position and will keep the shooter in place until it needs to be shot again.

Note: mounting and constructing the cannon without precise tools is kind of a trial and error task, it can take a while to figure out how to make everything interact the way it needs to, a fine tuning process is required while assemblying it. We strongly advice to build the cannon and radar structures when everything is connected and working to properly align all positions.

Step 6: Arduino Connections

This is the arduino connection scheme. Basically there's 3 servos each one connected to ground, 5V and pins 9,10 and 11 accordingly (9 moves the radar, 10 moves the cannon, 11 moves the reload lever), and then the proximity sensor tied to pins 2 and 3. On top of that there's two buttons tied to pins 4 and 5; those will reload and fire. This (picture above) is the connection schematic used.

Step 7: The Code

Most of the code regarding the radar interface, either on Processing and Arduino, is referenced and extracted from external sources, our work was to adapt the code to move all the parts of the cannon accordingly to aim a certain object on a designed range. All code is included in the arduino and Processing files above, here are some things to take into consideration:

Arduino Code:

- Into the aimobject() function there's a line: if (objectin > 10) { where the value of 10 defines the "range" of detection. If the value is lowered the cannon will aim at smaller objects but will be also easily affected by noise, if the value is larger it will only detect bigger objects but aim will be more accurate for those bigger.

- Into the aimobject() function there's another line:

if (lastdistance < 5) {


if (lastdistance < 45) {

this defines the aiming active distance, you can define minimum and maximum distance (in centimeters) in which the cannon will aim to an object. We consider objects further than 45cm to be almost undetectable by the ultrasonic sensor with accuracy, but it's up to the build quality of your own system.

Processing Code:

- We don't recommend to change the resolution code of Processing, it will mess up the whole interface and will be difficult to fix.

- In processing's setup there's a parameter that needs to be replaced. (around line 68).

myPort = new Serial(this, "COM9", 9600);

COM9 has to be replaced with the number of your arduino port. example ("COM13"). If Arduino is not running or the port is not correct processing won't start.

- We changed some parameters on Processing to fit the distances and range we needed, and around line 176:

if(distance<240 || distance>300){

this is an exception that clears some noise produced by our ultrasonic sensor, it can be erased depending on the clarity of the signal of your particular unit or changed to clear another range.

Step 8: Mounting Everything Up.

Now that we have the code working and the "subassemblies" ready to be mounted, we will proceed to attach the cannon to the servo on the center of the base; one of the servo accessories has to be glued to the lower side of the cannon, ideally on the center of mass to avoid excess inertial forces.

We will also mount the ultrasonic sensor with a thin strap of wood and one servo accessory, so the sensor keeps sweeping just a little in front of the base (the cut out parts in the front of the base are designed to allow the sensor sweep 180 degrees). The servo might need to be raised up a bit, so you can make a little stand with whatever you have at your disposal.

Step 9: Trying to Shoot Something.

Now it's time to try to see if you can shoot something! If it doesn't aim correctly you probably should take the cannon out and try to align it with the proximity sensor, it can be done writing a little program that puts them both in the same position. The arduino code for aligning the motors is attached on top of this step.

(The range of motion of our build is from 0 to 160 degrees and we advise to keep it this way, the processing code is adapted for 160 degrees also, so it is centered on 80º).

You can download an attached video here where the whole reloading, aiming and shooting process it's shown.

Step 10: Reflexions

From Jaume:

I'd like to state that doing an arduino project has been funnier than expected. Arduino turned out to be a really friendly and easy platform to work on, and on top of that really useful to quickly try out new ideas with little to no infrastructure.

Being able to experiment with different sensors and technology we were so disconnected with has been a door opening experience to add new and richer content to our projects. Now developing electronical based products will at least be less of a mental barrier.

From the design engineering point of view, arduino has proven to be a practical and feasible way of quick prototyping ideas further from the formal standpoint and more on the functional side; it's also quite affordable so it can save companies a lot of money and we saw in our visit to HP.

Teamwork has also been an important point to us about this project, reinforcing that two really different mindsets can complement really well to make an stronger and more complete project overall.

From Damia:

At the end of this project I have several things that I want to comment and explain as a final conclusion.

First of all, I give thanks to the total liberty of the project content that we had from the beginning, this challenged ourselves to turn our creativity on and try to find a good way to implement many things that learned in class into a functional prototype.

In second place I express gratitude to the purpose of this kind of projects, I think that we are in a moment of our lives for learning as much things as possible, because in one future, we could be able to apply all the knowledge. And as I mentioned before, we had the liberty to test with different kind of technological stuff in order to understand the basic functions of it and how it could be useful for prototype implementation.

Finally I would like to say that all the Arduino platform made me realize the infinite ways to use it and how simple (with basic knowledge) can be.