Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
ShreyanR
Published © GPL3+

Automated Lego Shooter

A project that uses SG-90 Micro Servos to shoot Lego cannons, because why not.

BeginnerFull instructions provided4,488
Automated Lego Shooter

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
This is the board I used for this project. However, an Arduino Uno would work as well.
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
These are the motors needed for the project.
×4
Jumper wires (generic)
Jumper wires (generic)
×1
Lego Star Wars Shootable Cannon
×4
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
A program that runs Arduino Code on Mac, Windows, and Linux Devices.

Hand tools and fabrication machines

Tape, Electrical
Tape, Electrical
Any tape is perfectly fine. It most certainly does not have to be electrical tape.

Story

Read more

Schematics

Lego Shootable Cannon Servo Diagram

Code

Lego Gun Shooter Code

C/C++
Paste this into Arduino IDE
#include <Servo.h>  //Including the library for the Servos

Servo firstCannon;  //Defining the First Cannon as a Servo
Servo secondCannon;  //Defining the Second Cannon as a Servo
Servo thirdCannon;  //Defining the Third Cannon as a Servo
Servo fourthCannon;  //Defining the Fourth Cannon as a Servo

void setup() {  //Setup code, or code that is only run once

  Serial.begin(9600);  //Start the Serial communication

  Serial.println("Defend the Clones! Set up the defenses!")  //Print something in the Serial Monitor

  firstCannon.attach(7);  //Attach Digital Pin 7 to First Cannon
  secondCannon.attach(8);  //Attach Digital Pin 8 to Second Cannon
  thirdCannon.attach(6);  //Attach Digital Pin 6 to Third Cannon
  fourthCannon.attach(9); //Attach Digital Pin 9 to Fourth Cannon

}

void loop() {  //Loop code, or code that is run an infinite amount of times
    
  Serial.println("Beginning firing sequence")  //Print something in the Serial Monitor

  firstCannon.write(180);  //Swerve the first servo 180 degrees, setting off the first cannon
  delay(100);  //Wait for 1/10 of a second
  firstCannon.write(0);  //Swerve the Servo back to original position in preparation for reload
  delay(1000);  //Wait for 1 second

  secondCannon.write(180);  //Swerve the second servo 180 degrees, setting off the second cannon
  delay(100);  //Wait for 1/10 of a second
  secondCannon.write(0);  //Swerve the Servo back to original position in preparation for reload
  delay(1000);  //Wait for 1 second

  thirdCannon.write(180);  //Swerve the third servo 180 degrees, setting off the third cannon
  delay(100);  //Wait for 1/10 of a second
  thirdCannon.write(0);  //Swerve the Servo back to original position in preparation for reload
  delay(1000);  //Wait for 1 second

  fourthCannon.write(180);  //Swerve the first fourth 180 degrees, setting off the fourth cannon
  delay(100);  //Wait for 1/10 of a second
  fourthCannon.write(0);  //Swerve the Servo back to original position in preparation for reload
  delay(1000);  //Wait for 1 second

  Serial.println("All cannons fired");
  Serial.println("Prepare for reload");
  
  delay(10000);
  
  Serial.println("Reloading Complete. Preparing to fire again")

}

Credits

ShreyanR
0 projects • 6 followers

Comments