Project showcase
Laser guidance using Joystick

Laser guidance using Joystick © GPL3+

Control laser pointer like a gun using a joystick

  • 1,413 views
  • 0 comments
  • 8 respects

Components and supplies

Apps and online services

About this project

The laser pointer can be operated in any given direction using a simple joystick and 2 servo motors.

This project is similar to my previous project where I made a Laser pointer operate via bluetooth using a smartphone application.

It basically contains a Servo motor mounted on a base on which we place the second servo that has a Laser pointer attached to it. The Servo on the base moves the pointer in the horizontal direction and the other servo moves it in vertical direction.

The Joystick also has an in-built pushbutton which is enabled by pressing the joystick. The SW pin provides the status of pushbutton which is used to switch on/off the Laser, VRx and VRy gives the the X and Y co-ordinates. Other 2 pins are for supply and ground.

The movement of the joystick is also programmed to be sensitive. This means more you move the joystick away from the center, the more faster the Servo will rotate.This enables fine adjustments to move the pointer to the desired target.

It is important to use a separate supply to power the servo's instead of the arduino's 5V supply.The servos were not responding well when I tried to use the arduino's supply.I have used a separate 5V supply from an adapter to operate the Servo's.

Code

Source CodeArduino
//by Shubham Santosh

#include<Servo.h>
 Servo s1,s2;  
 
void setup() {
  s1.attach(10); //defining the pins for the servo's
  s2.attach(11);
  pinMode(12,OUTPUT); //Laser Output
  pinMode(2,INPUT);   //SW pin status
  digitalWrite(2,HIGH);
  Serial.begin(9600);  //Start Seria Monitor
 
  // put your setup code here, to run once:
}
int p1=90,p2=90;   // initial position of both servos in degree
void loop() 
{
  
  int t1=0,t2=0;  //rate of increment/decrement of angle
  int a=analogRead(A0); // reads analog x-y readings of joystick
  int b=analogRead(A1);

  //when joystick is moved away from the center
  if(a<=450 or a>=550)
  {
    t1=map(a,0,1023,10,-10);
    p1=change(p1,t1);  //change the servo's current position
   
  }
  if(b<=450 or b>=550)
  {
    t2=map(b,0,1023,-10,10);
    p2=change(p2,t2);  //change the servo's current position

  }
   s1.write(p1); // rotate the servo's if the joystick is moved
   s2.write(p2);
  if(digitalRead(2)==LOW)  //reads the status of joystick's SW pin
  digitalWrite(12,HIGH);
  else
  digitalWrite(12,LOW);
  
  //print the analog readings of joystick and servo degree(For Verification)
  Serial.print("s1:");
  Serial.print(a);
  Serial.print("\t");
  Serial.print("s2:");
  Serial.print(b);
  Serial.print("\t");
  Serial.print("t1:");
  Serial.print(t1);
  Serial.print("\t");
  Serial.print("t2:");
  Serial.print(t2);
  Serial.print("\t");
  Serial.print("pos1: ");
  Serial.print(p1);
  Serial.print("pos2: ");
  Serial.println(p2);
  
  delay(70);          // for Stability
}

int change(int pos,int t)
{
    pos=pos+t;                   // Increment/decrement the Servo angle
    if (pos>180)                //  maximum anlgle of servo is 180 degree
    pos=180;
    if(pos<0)                  // minimum angle of servo is 0 degree
    pos=0;
    return(pos);               //return the change of position
}

Schematics

Schematic
Arduino joystick bb rday8uflzo

Comments

Author

 g9ikf0uavr
Shubham Santosh
  • 2 projects
  • 2 followers

Additional contributors

Published on

December 20, 2019

Members who respect this project

DefaultImages s6rfot9to323032331 336895420112967 96171529233231428 n

and 6 others

See similar projects
you might like

Similar projects you might like

Morse Code Communication Using Laser Module (Both)

Project tutorial by SURYATEJA

  • 2,645 views
  • 1 comment
  • 13 respects

HackingSTEM Joystick

by Jen Fox and Hacking STEM

  • 1,188 views
  • 0 comments
  • 3 respects

Cockroach Laser Killer

Project showcase by NerdFatherRJ

  • 10,748 views
  • 4 comments
  • 14 respects

Leap Motion Laser Tanks!

Project tutorial by Sean McCormick

  • 9,614 views
  • 5 comments
  • 49 respects

Joystick Game

Project tutorial by xXarduino_11Xx

  • 5,145 views
  • 5 comments
  • 15 respects

Arduino Bluetooth Robot for Android Device

Project showcase by aip06

  • 4,617 views
  • 2 comments
  • 19 respects
Add projectSign up / Login