Laser Arm Cannon

by 762177 in Circuits > Arduino

82 Views, 3 Favorites, 0 Comments

Laser Arm Cannon

image_2024-06-17_005308311.png

Welcome to this Instructable, In this project, you’ll learn how to build an arm mounted laser turret using a joystick and a potentiometer. This project combines basic electronics with programming on an Arduino to create a fun and educational setup perfect for beginners and hobbyists interested in exploring the world of microcontrollers. I first started this as a passion project, which is why I am very excited to show you all how I did it



Tinkercad

Supplies

image_2024-06-17_005515768.png

1x Arduino (or compatible microcontroller)

1x Joystick module

1x Potentiometer

1x Servo motor

1x Servo motor chassis

1x Laser diode

1x Buzzer

1X Breadboard/perf board

3-4x mtf/ftf wires

1x wrist mount (belt, arm band, thick glove)

1x soldering iron

1X hot glue gun

jumper wires

solder

electrical tape

hot glue

Build Your Joystick Tether

image_2024-06-17_005723602.png
image_2024-06-17_005819249.png
image_2024-06-17_005838183.png
image_2024-06-17_005908194.png
image_2024-06-17_010013890.png
image_2024-06-17_010036232.png

The first thing you're going to want to do to begin this project is building a long tether to connect your circuit to your joystick so that you can maneuver your arms while using wearing this device.


Step 1: get your mtf/ftf wires, this instructable will 4 however you will only need three (power, ground, x axis) (optional: button output)


Step 2: remove 1 end of your mtf/ftf wires (if using mtf wire, remove male end)


Step 3: then your going to want to get some very long jumper wires as these will make up the body of your tether


Step 4: take your jumpers and solder them to the end of your mtf wire that you removed


Step 5: you're then going to want to wrap the soldered ends in electrical tape


Step 6: repeat steps 2-5 for as many cables you want


Step 7: take all your wires together and begin to spin them together clockwise, this will create your coiled tether

Build Your Turret

image_2024-06-17_010529790.png

In this step you will assemble the actual turret that will be on your arm

Step 1: put together your servo chassis and servo


Step 2: hot glue your laser diode to the chassis

Begin Your Wiring

image_2024-06-17_010759571.png

Step 1: Connect your power and ground from your Arduino to your breadboard



Connect the Signal Pin of Your Servo to Pin 9

image_2024-06-17_011014967.png

Connect the Power Pin of Your Laser Diode to Pin 11

image_2024-06-17_011233129.png

Connect the Your Buzzer to Pin 10

image_2024-06-17_011342939.png

This will add some cool audio to your laser

Connect Your Potentiometer to Pin A1

image_2024-06-17_011554072.png

This will control your laser

Final Step on the Wiring

image_2024-06-17_011720916.png

Take your long tether and connect it to the pins of your joystick power to power, ground to ground

you will attach the "X" pin of your joystick to pin A0

Secure Your Turret

image_2024-06-17_011933147.png
image_2024-06-17_011949116.png
image_2024-06-17_012058082.png

Take the turret component that you built in step 2 and hot glue it to your wrist mount of choice

Upload the Code to Your Arduino

image_2024-06-17_012430573.png

You will then want to upload the code for this project to your Arduino





Here is a quick explanation of the Arduino code:


---------------------

#include <Servo.h>

---------------------

- Includes the Servo library for controlling servo motors.


--------------------

const int potPin = A1;

const int laserPin = 11;

const int buzzerPin = 10;

const int joystickXPin = A0;

const int servoPin = 9;

----------------------

- **Defines constants** for pin assignments:

 - `potPin` for the potentiometer on analog pin A1.

 - `laserPin` for the laser diode on digital pin 11.

 - `buzzerPin` for the buzzer on digital pin 10.

 - `joystickXPin` for the joystick X-axis on analog pin A0.

 - `servoPin` for the servo motor on digital pin 9.




------------------------

Servo myServo;

------------------------

- **Creates a Servo object** to control the servo motor.


-----------------------

int potValue = 0;

int lastPotValue = 0;

int joystickValue = 0;

----------------------

- **Defines integer variables** to store the current potentiometer value, the last potentiometer value, and the joystick X-axis value.




---------------------

void setup() {

 Serial.begin(9600);

 pinMode(potPin, INPUT);

 pinMode(laserPin, OUTPUT);

 pinMode(buzzerPin, OUTPUT);

 pinMode(joystickXPin, INPUT);

 myServo.attach(servoPin);

--------------------------


- **Initializes the serial communication** at 9600 baud rate.

- **Configures pin modes**:

 - `potPin` as input for the potentiometer.

 - `laserPin` as output for the laser diode.

 - `buzzerPin` as output for the buzzer.

 - `joystickXPin` as input for the joystick.

- **Attaches the servo object** to the `servoPin`.



----------------

void loop() {

 potValue = analogRead(potPin);

----------------

- **Reads the analog value** from the potentiometer and stores it in `potValue`.


----------------

 int laserBrightness = map(potValue, 0, 1023, 0, 255);

 analogWrite(laserPin, laserBrightness);

---------------

- **Maps the potentiometer value** (0-1023) to a brightness level (0-255) for the laser.

- **Sets the laser brightness** using `analogWrite` on `laserPin`.


------------------

 if (potValue != lastPotValue) {

  int buzzerFrequency = map(potValue, 0, 1023, 100, 1000);

  tone(buzzerPin, buzzerFrequency);

  lastPotValue = potValue;

 } else {

  noTone(buzzerPin);

 }

------------------

- **Checks if the potentiometer value has changed** since the last reading.

 - **If changed**, maps the value to a frequency (100-1000 Hz) for the buzzer and **plays a tone** using `tone()` on `buzzerPin`.

 - **Updates `lastPotValue`** to the current potentiometer value.

 - **If not changed**, stops the buzzer using `noTone()` on `buzzerPin`.


------------------------

 joystickValue = analogRead(joystickXPin);

 int servoAngle = map(joystickValue, 0, 1023, 0, 180);

 myServo.write(servoAngle);

------------------------

- **Reads the analog value** from the joystick and stores it in `joystickValue`.

- **Maps the joystick value** (0-1023) to a servo angle (0-180 degrees).

- **Sets the servo position** using `myServo.write()`.


-----------------------

 Serial.print("Potentiometer Value: ");

 Serial.print(potValue);

 Serial.print(" | Laser Brightness: ");

 Serial.print(laserBrightness);

 Serial.print(" | Buzzer Frequency: ");

 Serial.print(map(potValue, 0, 1023, 100, 1000));

 Serial.print(" | Joystick Value: ");

 Serial.print(joystickValue);

 Serial.print(" | Servo Angle: ");

 Serial.println(servoAngle);

----------------------

- **Prints the values** of the potentiometer, laser brightness, buzzer frequency, joystick, and servo angle to the serial monitor.


--------------------

 delay(100);

}

--------------------

- **Pauses execution** for 100 milliseconds to allow time for the serial monitor to update and to avoid rapid changes.

Downloads

Enjoy

IMG_0278.gif

If all goes well, you will have built a working Arduino laser cannon




Tinkercad