NetWingx
Published © GPL3+

Automatic Flame Turret

An Automatic Turret That Shoot Fireballs When There's An Object Approaches!

AdvancedFull instructions provided997
Automatic Flame Turret

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Servo Motor (Futaba S3003)
×2
Lighters (Gas & Arc Lighter)
×2

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematics

Code

Code

Arduino
#include <NewPing.h> // Call NewPing library
#include <Servo.h> // Call Servo library
#define trigPin 13 // Pin connected to ultrasonic sensor Trig
#define echoPin 12 // Pin connected the ultrasonic sensor Echo
#define MAX_DISTANCE 500
NewPing sonar(trigPin, echoPin, MAX_DISTANCE);
int angle = 0; // Set servo position in degrees
Servo servo1;
Servo servo2;
void setup() {
  Serial.begin (115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servo2.attach(3);
  servo1.attach(9); // Pin connected to servo
}
void loop() {
  int duration, distance, pos = 0, i;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); // trigPin sends a ping
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); // echoPin receives the ping
  distance = (duration / 2) / 29.1;
  Serial.print(distance);
  Serial.println(" cm");
  if (distance <= 30) { // If distance is less than 30 cm
  for (angle = 0; angle < 90; angle++)
    {
      servo1.write(33); // Stay in position
      servo2.write(angle); // Trigger the gas
      delay(15);
     }  
   } else {
    servo2.write(90);
    for (angle = 0; angle < 90; angle++) { // Sweep the servo
      servo1.write(angle);
      delay(20);
    }
    for (angle = 180; angle > 0; angle--) {
      servo1.write(angle);
    }
    delay(450);
  }
   }

Credits

NetWingx

NetWingx

1 project • 2 followers

Comments