Project tutorial

Self-Propelled LASER Turret © GPL3+

LASER tank controlled by a PS2 wireless controller and you "fire" the LASER turret remotely too.

  • 2,491 views
  • 1 comment
  • 20 respects

Components and supplies

About this project

Full tutorial video

Hello, in this project I'm making a LASER turret mounted on a tank chassis, and controlled with a PS2 Wireless controller, I'm using a joystick for moving the tank and the other stick is for moving the Turret on a dual axis, and then a button to light up my enemies. :D

For this I'm needing an motorized chassis, you can use the usual 2WD/4WD Robot or whatever you have in hand, KY-008 LASER module mounted on the Dual Axis FPV camera cradle (Turret for this project), a dual H bridge module I'm using L298n Powered with 7.4V Li Battery, All these wired with Arduino UNO board and controlled by a PS2X Wireless controller.

N.B: In my wiring and code, you gonna notice that the LASER is wired with A0 and A1, it's because I ran out of pins and I put the A0 as my GND and A1 as digital ouput controlled to turn on and off the LASER.

Code

RC_LASER_Tank.inoArduino
Control all your systems
/* This code is for RC LASER tank / Self propelled LASER Turret
 * Refer to www.SurtrTech.com or SurtrTech YouTube channel for more details
 */

#include <PS2X_lib.h>  //Libraries needed PS2 Receiver and Servo
#include <Servo.h> 

Servo Servo1;        //Declaring cradle servos, Servo1 is the base
Servo Servo2;

PS2X ps2x;          //Declaring the PS2X controller

int error = 0;      //PS2X stuff to detect errors and type of controller
byte type = 0;
byte vibrate = 0;  //vibration of the controller

int a,b;

//Motor A Right motor for my project
int in1 = 2;
int in2 = 4;
int EnA = 3; //I'm controlling the speed also

//Motor B
int in3 = 6;
int in4 = 7;
int EnB = 5;

void setup(){
 
 Serial.begin(9600);  //Serial monitor will help you to see values and know if your controls are detected or not
 error = ps2x.config_gamepad(13,11,8,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 type = ps2x.readType();
 pinMode(in1, OUTPUT);
 pinMode(in2, OUTPUT);
 pinMode(EnA, OUTPUT);
 pinMode(in1, OUTPUT);
 pinMode(in2, OUTPUT);
 pinMode(EnB, OUTPUT); 
 pinMode(A0,OUTPUT);                 //Those lines concern the LASER, I ran out of pins and I put A0 as GND
 pinMode(A1,OUTPUT);                 //And the A1 provides 5v if I press the X button
 digitalWrite(A0,LOW);
 Servo1.attach(9);
 Servo2.attach(10);
  
}

void loop(){
   a=Servo1.read(); //Reading the previous servos positions is an important step so we can know where they should position next
   b=Servo2.read();
  
   ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate' speed    
   vibrate = ps2x.Analog(PSAB_BLUE);          //this will set the large motor vibrate speed based on 
   digitalWrite(A1,vibrate);                  //if the vibrate takes a value > threshold it will set the A1 (LASER) to high
   Stop();                                   //As long as no stick is pushed we stop, otherwise move accordingly
   
   //Forward sequence
   if(255-ps2x.Analog(PSS_LY) > 130){         //This is how I detect that the stick is pushed up the value gotten should be 130-255
   Serial.println("Forward");                 //And the 255-... before is just to arrange values because it was inverted
   Forward();
   }
   
   //Backward sequence
   if(255-ps2x.Analog(PSS_LY) < 120){
   Serial.println("Backward"); 
   Backward();
   }
   
   //Right sequence
   if(ps2x.Analog(PSS_LX) > 130){           //X Axis wasn't inverted that's why you don't see the 255-...
   Serial.println("Right");
   Right();
   }
   
   //Left sequence
   if(ps2x.Analog(PSS_LX) < 120){
   Serial.println("Left");
   Left();
   }

   //Cradle Right
   if(255-ps2x.Analog(PSS_RX) < 120){           //If the stick is pointed to the right
   Serial.println("C Right");                   //We read the current servo position (a=Servo1.read())
   Serial.println(ps2x.Analog(PSS_RX));         //And we decrement '1'
   a=a-1;                                       //Then we write the new position which is a-1 you can change the '1' to higher to make it turn fast
   Servo1.write(a);

   //Cradle Left
   }
   if(255-ps2x.Analog(PSS_RX) > 130){
   Serial.println("C Left");
   Serial.println(ps2x.Analog(PSS_RX));
   a=a+1;
   Servo1.write(a);   
   }

    //Cradle Up
   if(255-ps2x.Analog(PSS_RY) < 120){
   Serial.println("C Up");
   Serial.println(ps2x.Analog(PSS_RY));
   b=b+1;
   Servo2.write(b);

   //Cradle Down
   }
   if(255-ps2x.Analog(PSS_RY) > 130){
   Serial.println("C Down");
   Serial.println(ps2x.Analog(PSS_RY));
   b=b-1;
   Servo2.write(b);   
   }
   
 delay(50);    
}

void Forward(){
  int  F1 = map(255-ps2x.Analog(PSS_LY), 130, 255, 0, 255);     //Changing the signal received from 130-255 to 0-255 to be able to write that value as PWM signal
  digitalWrite(in1, LOW);                                       //To control the speed
  digitalWrite(in2, HIGH);
  analogWrite(EnA,F1);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(EnB,F1);
  Serial.println(F1);
  
  
}


void Backward(){
  int  F2 =  map(255-ps2x.Analog(PSS_LY), 120, 0, 0, 255);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  analogWrite(EnA,F2);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  analogWrite(EnB,F2);
  Serial.println(F2);
}


void Right(){
  int  F3 =  map(255-ps2x.Analog(PSS_LX), 120, 0, 0, 255);
  digitalWrite(in1, LOW);             //Turning sequence that suited me I stop on track and turn the other
  digitalWrite(in2, LOW);             //You can turn them on different sides to make it turn fast
  analogWrite(EnA,F3);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(EnB,F3);
  Serial.println(F3);
  
}


void Left(){
  int  F4 =  map(255-ps2x.Analog(PSS_LX), 130, 255, 0, 255);
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  analogWrite(EnA,F4);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  analogWrite(EnB,0);
  Serial.println(F4);
  
}

void Stop(){
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  analogWrite(EnA,0);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  analogWrite(EnB,0);
  
}
PS2X Library
Library for your PS2 wireless controller

Schematics

Wiring for all things
Don't forget that the l298n is powerd by 7.4V Li battery through +12V/Gnd and provides 5V for the rest of the system including Arduino
Wiring 2 8ose31x34r

Comments

Similar projects you might like

Tutorial Arduino Mini Laser Turret Control

Project in progress by Josh From BreakoutBros.com

  • 10,551 views
  • 5 comments
  • 34 respects

Arduino Laser Tripwire

Project tutorial by Ian Cumming

  • 16,237 views
  • 12 comments
  • 50 respects

Controlling an Arduino Turret with IR Remote

Project tutorial by Team RobotGeek Projects Team

  • 4,101 views
  • 1 comment
  • 17 respects

WW2 Tank Laser Tag Sherman & Panther

Project tutorial by Arduino “having11” Guy

  • 16,349 views
  • 1 comment
  • 57 respects

Arduino Sun Tracker Turret

Project tutorial by Team RobotGeek Projects Team

  • 32,112 views
  • 1 comment
  • 151 respects

Halloween Laser Maze

Project showcase by Sam Horne

  • 8,796 views
  • 6 comments
  • 24 respects
Add projectSign up / Login