In this capstone project, we are going to combine analog inputs, multiple servo motors, and dangerous beams of light to build a Laser Turret Tracker. This project uses an analog joystick to aim a laser diode mounted on a pan-tilt bracket. Itâs the exact same logic used in security cameras and robotic arms, just scaled down to annoy your pets.

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!