In this capstone project, we are going to combine several fundamental skills: reading analog inputs, controlling multiple servo motors, and managing multiple components simultaneously to build a Laser Turret Tracker.
This project uses an analog joystick to move a laser diode mounted on a pan-tilt bracket. It’s a fun, highly visual project that provides an excellent introduction to 2-axis control systems—the same foundational logic used in security cameras, robotic arms, and CNC machines.

A pan-tilt bracket holds two micro servos. One servo controls the horizontal rotation (pan), and the other controls the vertical rotation (tilt). We use an analog joystick (which is essentially two potentiometers) to read the user’s input. The Arduino reads these analog values, maps them to the appropriate angles (0° to 180°), and instructs the servos to move. The laser diode simply stays on, pointing wherever the servos aim it!
To build the laser turret, you’ll need the following components. If you don’t have them, you can pick them up here:
Wiring this up looks complicated because of all the wires, but it’s very straightforward when broken down into sections:
Servos require a good amount of current. While two micro servos can sometimes run off the Arduino’s 5V pin, it’s safer to use an external 5V power supply if they start jittering. For this guide, we’ll assume you are using the Arduino’s 5V, but be prepared to upgrade your power if needed.
The joystick module has 5 pins:
Each SG90 servo has 3 wires (usually Brown, Red, and Orange):
The laser diode module has 3 pins (or 2 depending on the model). If it has 3 (S, V, G):
Now, let’s write the code to tie it all together. We will use the built-in Servo.h library to handle the PWM signals for the servos.
#include <Servo.h>
// Create servo objects
Servo panServo;
Servo tiltServo;
// Define joystick pins
const int joyXPin = A0; // Pan control
const int joyYPin = A1; // Tilt control
// Define laser pin
const int laserPin = 7;
// Variables to store joystick readings
int joyXVal;
int joyYVal;
// Variables to store mapped servo angles
int panAngle;
int tiltAngle;
void setup() {
// Attach servos to their control pins
panServo.attach(9);
tiltServo.attach(10);
// Set the laser pin as an output
pinMode(laserPin, OUTPUT);
// Turn on the laser!
digitalWrite(laserPin, HIGH);
// Start servos in the middle position (90 degrees)
panServo.write(90);
tiltServo.write(90);
}
void loop() {
// Read the analog values from the joystick (0 to 1023)
joyXVal = analogRead(joyXPin);
joyYVal = analogRead(joyYPin);
// Map the joystick values to servo angles (0 to 180 degrees)
// Note: You may need to swap 0 and 180 depending on the orientation of your servos
panAngle = map(joyXVal, 0, 1023, 0, 180);
tiltAngle = map(joyYVal, 0, 1023, 0, 180);
// Write the angles to the servos
panServo.write(panAngle);
tiltServo.write(tiltAngle);
// A short delay helps the servos reach their position smoothly
delay(15);
}
0 and 180 in the map() function for that axis.This project is a perfect stepping stone into more advanced robotics. Once you master the pan-tilt mechanism, you can swap the joystick for sensors (like ultrasonic or PIR) to make the turret track movement automatically!