How to make Arduino Laser Turret using Servo motors and Joystick

Arduino Laser Turret, Overview:

In this endeavor, I will show how to construct an Arduino laser turret with servo motors and a two-axis joystick. I will supply the code needed along with a circuit diagram, along with a thorough explanation of the project. This will allow anyone to construct the laser turret without facing any challenges.

What is Arduino Laser Turret?

This task includes a simple tool made up of a two-way servo system with a laser component, operated by a PS2 style joystick. You may be curious about the practical applications of this project, and the response varies based on the particular situation. Allow me to offer some instances to demonstrate its potential practicality.

Take into account a 4WD-capable robot that is controlled via Bluetooth. By affixing a camera to its head, we are able to not just see what is in front but also capture side and top angles. The idea of this project stays consistent, even though the modules are replaceable.

Another use case encompasses integrating a water sprinkler into an Arduino robot designed for firefighting. We can direct the water pipe to accurately water specific areas. These instances show that the project can be utilized in different situations.

After introducing the idea, we will explore the different phases of the project in a step-by-step manner for easy comprehension.

Designing

I have used a 3D printer to make the required parts for the servo mechanism section of this project. There’s no need to worry if you are a beginner in designing and creating your own 3D prints. I have given STL files that are specifically made for this project, which you can utilize to conveniently create the necessary components.

Download 3d Files:

After acquiring the STL files, the following step is to get them ready for printing. This includes cutting the design, which can be accomplished by utilizing the popular Cura slicer software. Through the use of Cura, you can transform the 3D model into a compatible format for your 3D printer to accurately print.

It took more than three hours to print the parts for this project. In my situation, I selected white PLA filament for the material used in printing, however, you can choose any color that works best for you. Making sure you have chosen the adhesion option in your 3D printer settings is crucial. As we are printing three parts at once, it is crucial to resolve any possible problems with one part in order to guarantee the successful printing of the remaining two.

Once the printing process is finished and the printed components are in hand, some basic cleaning is necessary. A web-like pattern can often be seen on the printed pieces because supports were not utilized in the printing process. Adding direct supports to the process would increase the total printing time.

In the picture below, you can observe the web-like structure being cleared with a hobby knife.

Cleaning and removing the web-like structures from the printed parts can be time-consuming, especially since the same process must be done for all three parts. Nevertheless, after finishing the cleaning procedure, you will have the components displayed in the image below.

With the main mechanism now ready, it is time to put together the different components. Before starting the assembly, make sure you have collected all the required parts. Now that the primary mechanism is prepared, we can proceed to the next phase of the project.

We will gather all the materials listed below, as shown in the image provided.

– Arduino Uno
– Jumper wires and breadboard
– Joystick module
– 2 micro servos
– Laser diode
– Arduino IDE

Having gathered these components, we can proceed with the assembly and implementation of the project.

Circuit Diagram For Arduino laser turret:

To simplify the process, let’s go through the circuit building step by step, focusing on each component individually.

There are two main components in this circuit: the micro servos and the PS2 module.

Micro servo connections

The micro servo is made up of three pins: two for the power source (positive and negative) and one for the signal. Based on the circuit diagram, the power rails on the breadboard are connected to the positive and negative pins of both servos. The servos’ signal pins are connected to pins D3 and D4 on the Arduino Uno.

In this assignment, the servos manage the controlling of the up-down and swinging movements. The horn of the second servo has a holder to keep the laser module secured.

Analog joystick module

The joystick module comprises four pins, of which two are dedicated to the power supply, and the remaining two are used for vertical and horizontal control.

To make the connections, we need to link the positive (+) and negative (-) terminals of the joystick module to the power bars on the breadboard. Moreover, the Vrx pin is connected to A0 while the Vry pin is connected to A1 on the Arduino Uno board.

Regarding the laser diode, it can be linked directly to the power rails on the breadboard, where the +5V and GND pins from the Arduino Uno are connected.

Once these connections are set up, the circuit is fully operational, and we can move forward with uploading the codes to the Arduino Uno.

Arduino laser turret code

Servo servo1; // define servos
Servo servo2;
int joyX = 0; // give variable to joystick readings
int joyY = 1;
int joyVal; // create variable for joystick value
void setup()
{
servo1.attach(3); // start servos
servo2.attach(4);
}
void loop()
{
  
joyVal = analogRead(joyX); // read value from joystick
joyVal = map(joyVal, 0, 1023, 0, 180); // change value range to 0-180
servo1.write(joyVal); // write value to servo
joyVal = analogRead(joyY); // repeat same for y axis
joyVal = map(joyVal, 0, 1023, 0, 180);
servo2.write(joyVal);
delay(20); // add small delay to reduce noise
}

To upload the code to your Arduino Uno, follow these steps:

1. Connect the programming cable to the Arduino Uno.
2. Open the Arduino IDE.
3. Check the port number and board type by navigating to “Tools” and selecting the appropriate options for “Board Type” and “Ports.”
4. Copy the provided code and paste it into the Arduino IDE.
5. Click on the “Upload” button to initiate the upload process.
6. Once the upload is complete, disconnect the programming cable from the Arduino Uno.

By following these steps, you will successfully upload the code to your Arduino Uno and can proceed with the next stages of the project.

Some basics about the code

We start the code by #include <Servo.h> that means we are telling the IDE to include servo library so that it can understand with what module we are trying to communicate

After this we are calling functions for Joystick and then assigning the pin numbers for servos these are called as

and

Now, we need to assign values that determine how the servo should respond when it receives input from the joystick module.

joyVal = analogRead(joyX);

joyVal = map(joyVal, 0, 1023, 0, 180);

servo1.write(joyVal);

joyVal = analogRead(joyY);

joyVal = map(joyVal, 0, 1023, 0, 180);

servo2.write(joyVal);

delay(20);

The delay parameter represents the amount of time allocated to the servo. Increasing the delay value results in a slower response, as it allows for smoother movements and helps eliminate any unwanted noise or vibrations.

Final assembly


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top