Coil Accelerated Sentry Turret

by ZhaoYin in Circuits > Arduino

419 Views, 1 Favorites, 0 Comments

Coil Accelerated Sentry Turret

IMG20230520212724.jpg

This project is a small sentry turret that is placed on a stepper motor. It rotates and scans an area in front with an ultrasonic sensor for nearby objects. When a target is found the sentry will take aim, sound a warning using a buzzer and proceed to fire a metal projectile using a coil accelerator. The turret can also automatically calibrate the front using an LED and a light sensitive resistor.

Supplies

  • Coil Accelerator Kit
  • Arduino Uno R3
  • Ultrasonic Sensor
  • Light Sensitive Resistor
  • Stepper motor and controller
  • Passive Buzzer
  • Arduino power supply module and corresponding adapter/Any 5V power supply for your circuit/breadboard
  • 1K Ohm resistor & 10K Ohm resistor & 330 Ohm resistor
  • NPN Transistor
  • Jumper cables & Dupont cables
  • Soldering kit/lots of screw terminals
  • Circuit board/breadboard
  • 3D Printer/Anything to house the turret components

Circuit Setup

sentry arduino.png
IMG20230520211218 (1).jpg
IMG20230521003256.jpg
IMG20230304202508 (1).jpg
IMG20230511230351 (1).jpg

Setup the circuit as shown in the picture. The stepper motor controller I use is not available on the simulation website I used, so ignore the weird motor controller circuit board. The LED goes under the photoresistor, which is attached to the turret and pointed downwards towards the LED. I also included a picture of the coil accelerator kit and its schematic for extra information on how those parts work. You can buy these kits from aliexpress and override the button controls using your Arduino like I did.

The Turret

IMG_20230505_233649 (1).jpg

Mount your turrent components to a stable turret frame. You can use a 3D printer to print my model. Autocannon.stl contains all the necessary parts. Sonar Holder.stl contains a seperate front part you can attach manually. Since your coil accelerator might differ from mine it is best you model your own turret or craft one from wood. I do not recommend using softer materials like cardboard. The wires might tug on the turret while it's rotating, so the material needs to have some level of strength.

Arduino Code

The code below is a modified version of the RadArduino by eleccreativa, which is based on Prometec's Motor tutorial (Spanish).

Credits for the original go to them. I changed most hardcoded values into variables and added some code to control the buzzer and coil accelerator. Make sure you install the NewPing library in your IDE and disable its timer in the configuration files. Otherwise your buzzer will give you a timer error. Also mind the light in the area you use this device in. You might have to dim the lights or change the photoresistors threshold for the calibration to work.

#include <NewPing.h>


/*
====================================================================================================
Original code from:
  Project: RadArduino.
    Radar based in Arduino Leonardo. Arduino controls an stepper motor through a controller (ULN2003A).
    An encoder has been implemented with a LED and a fotoresistor. This encoder calibrates the system.
    The GUI has been created with Processing 3.
   
  Makers: Borja Gordillo Ramajo, Javier Peces Chillarón, Pablo Cazorla Martínez.
 
  Subject: Electrónica Creativa.
 
  Universidad de Málaga.
=====================================================================================================
Modified code:
  Coil Accelerated Sentry Turret
    Rotating turret programmed to engage targets within 20cm with a small mass driver.
 
  Made by: Pascal Schippers

  University of the Arts Utrecht.
=====================================================================================================
*/
 
/* Pins configuration (HC-SR04 sensor) */
#define TRIGGER_PIN  7
#define ECHO_PIN     6
#define MAX_DISTANCE 20


/*Pins configuration (stepper motor controller) */
#define IN1  12
#define IN2  11
#define IN3  10
#define IN4  9


/*Pins configuration (LDR) */
#define LDRin A0


boolean letsGo = false; //When the radar is connected with Processing, the calibration stars.
 
/*NewPing object created*/
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);


int uS;
int light = 0;
int threshold = 350; //Resistor light threshold
boolean calibrate = false;
boolean ok = false;
boolean shot = false;
boolean targetfound = false;
int sendData = 8;
int totalsteps = 768;
int i = 0;
int aimAdjust = 0;


/*Stepper motor parameters */
int steps_left=totalsteps; //We use totalsteps because the system needs totalsteps pulses per 360º rotation.
boolean Direction = true;
int Steps = 0;


int Paso [ 8 ][ 4 ] =     //Half steps (Soft movement)
    {   {1, 0, 0, 0},
        {1, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 1, 0},
        {0, 0, 1, 1},
        {0, 0, 0, 1},
        {1, 0, 0, 1}
     };


//int Paso [ 4 ][ 4 ] =   //Complete steps (faster and more torque)
//    {   {1, 1, 0, 0},
//        {0, 1, 1, 0},
//        {0, 0, 1, 1},
//        {1, 0, 0, 1},
//     };


 
 
void setup() {
  Serial.begin(57600);
  //Stepper motor pins
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(TRIGGER_PIN, OUTPUT); // Sets the trigPin as an Output
  pinMode(ECHO_PIN, INPUT); // Sets the echoPin as an Input
  pinMode(LDRin, INPUT);
  pinMode(13, OUTPUT);
  Serial.println("Pins initialized.");
}
 
void pcheck(){
  int sensorValue = analogRead(LDRin);
  float voltage = sensorValue * (5.0 / 1023.0);
  //Serial.println(voltage);
  Serial.println(sensorValue);
  pcheck();
}


void loop() {


  while(!letsGo) //Wait for Processing
  {
    if(Serial.available()){
      i = Serial.read(); //When 254 is received through the serial port, the calibration starts.
    }
    if(i == 49)
    {
      Serial.println("Radar initialized.");
      i = 0;
      shot = false;
      targetfound = false;
      letsGo = true;
    }
  }
 
  if(Serial.available()){
    i = Serial.read();
  }
  if(i == 50)  //When the mode is changed in Processing, arduino recalibrates the radar
  {
    Serial.println("Recalibrating");
    calibrate = false;
    if(steps_left < 100)
    {
      Direction = !Direction;
    }
    i = 0;
  }
 
  if(calibrate == false){  //Recalibration, when the LDR is found the radar main functionality starts.
    light = analogRead(LDRin);
    if(light >= threshold)
    {
        Serial.println("Calibrated.");
        Serial.println("Starting area surveillance.");
        calibrate = true;
        Direction = true;
        steps_left = totalsteps/2;
    } else {
      stepper();
      steps_left-- ;
      delay(1);
    }
  }


  if(calibrate == true) //Radar main functionality.
  {
     if(ok == false){
       delay(1000);
       ok = true;
     }
     light = analogRead(LDRin);
     if(light >= threshold)
     {
        steps_left = totalsteps/2; //Auto-calibration when HC-SR04 reachs the front point (where LDR is)
     }
     stepper() ;    // Go one step.
     --sendData;
     steps_left-- ;  // One step more gone.
     if (targetfound == true)
     {
      aimAdjust--;
     }


     if(sendData == 0){
     
       //Gets a travel time measurement
       uS = sonar.ping();
       // Estimates distances using a constant
       //Serial.println(uS / US_ROUNDTRIP_CM);
       if (uS > 5 && targetfound == false){
         aimAdjust = 320; //How many steps left to compensate for sonar detection width
         targetfound = true;
         Serial.println("Target spotted.");
         Serial.println("Aiming");
       }
       if (targetfound == true && aimAdjust <= 0)
       {
         shoot();
       }
       sendData = 8;
       
     }
   
     //Wait for 3 ms every step.
     delay (3);
  }
 
  if(steps_left == 0){
    delay(5); //Wait 5 ms when one round is completed
    Direction=!Direction; //When the back side is reached, the direction is changed.
    steps_left=totalsteps;
  }


}


void shoot(){
  if (uS > 5 & shot == false){
        alarm();
        digitalWrite(13, HIGH);
        delay(500);
        digitalWrite(13, LOW);
        shot = true;
        Serial.println("Main armament fired!");
        letsGo = false;
       }
}


void alarm(){
  tone(5, 75, 500);
  delay(500);
  tone(5, 750, 500);
  delay(1000);
  tone(5, 75, 500);
  delay(500);
  tone(5, 750, 500);
  delay(1000);
}


void stepper()            //It function increase a half step.
{
  digitalWrite( IN1, Paso[Steps][ 0] );
  digitalWrite( IN2, Paso[Steps][ 1] );
  digitalWrite( IN3, Paso[Steps][ 2] );
  digitalWrite( IN4, Paso[Steps][ 3] );
 
  SetDirection();
}


void SetDirection()
{
    if(Direction)
        Steps++;
    else
        Steps--;
     
    Steps = ( Steps + 8 ) % 8 ; //8 is used because of half step configuration
}


Time to Fire

Hook up a serial monitor and write a 1 to the Arduino. This is a safety feature you have to do between every shot. The default code is configured to shoot at anything within 20cm. Coil accelerators generally do not shoot that hard, but you should still be careful and apply the general rules of firearm safety.

  • Always points the coil accelerator in a safe direction.
  • Always treat the coil accelerator like it's loaded.
  • Always be aware of your target and what is behind or next to it.
  • Do not point this device at anything you are not willing to destroy.