123hridoy
Created March 21, 2022

Arduino arrow -bow system with radar

This is a unique arduino project where I tried to make a auto shooter with arrow , detecting enemy with radar.

IntermediateFull instructions provided182
Arduino arrow -bow system with radar

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Custom parts and enclosures

arrow mechanism

Schematics

circuit diagram

Code

Arduino code

Arduino
#include<Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
int degree=0;
void setup() {
  // put your setup code here, to run once:
servo1.attach(10);
servo2.attach(11);
servo1.attach(10);
servo3.attach(9);

servo1.write(0);
servo2.write(0);
servo3.write(90);

pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); 
}

void loop() {
  
  // put your main code here, to run repeatedly:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  // Displays the distance on the Serial Monitor
 
  
  
  servo2.write(0);
  if(distance>20 )
  {
    servo1.write(degree+1);
    delay(10);
   degree=degree+1;
   distance =50;
    
 }
else {
servo1.write(degree);
servo2.write(degree);
servo3.write(180);

delay(10);
degree=degree;


} 
if(degree<180)
{degree=degree;
}
if(degree>=180)
{degree=0;
}
  Serial.print(degree); Serial.print( " "); Serial.println(distance);
}

matlab code

MATLAB
clc;
clear all;

%Cusfclose(instrfindall);
delete(instrfindall);
%tomize graph
figure('units','normalized','outerposition',[0 0 1 1]);
whitebg('black');
%Draw Scale Data
th = linspace(0,pi,1000);
R = 10:10:100;  
for i=1:length(R);
x = R(i)*cos(th);
y = R(i)*sin(th);
plot(x,y,'Color', [0.603922 , 0.803922 , 0.196078] ,'LineWidth',1);
hold on;
end
%Draw Axis data
x0 = [0 100 0 0 0 0 ];  x1 = [0 100 86.60 50 -50 -86.60]; y0 = [0 0 0 0 0 0]; y1 = [100 0 50 86.60 86.60 50];
for i=1:length(x0);
hold on;
plot([x0(i),x1(i)],[y0(i),y1(i)] ,'Color', [0.603922 , 0.803922 , 0.196078],'LineWidth',2);
end
%Draw Sonar default data
for i=1:180 
hold on;
[x, y] = pol2cart(i*0.0174532925, 100);
h(i) = plot([0,x],[0,y],'g','LineWidth',1);
end
%define serial port
s1 = serial('COM3');            
s1.BaudRate=9600;                               
delete(s1)
clear s1
% now connect the device again, the following will now be successful:
s1= serial('COM3');
fopen(s1);
%Draw Sonar Data
while(1)
data = fscanf(s1);
[th, r] = strtok(data);
th = real(str2num(th));
r = str2num(r);
set(h(th),'color','r');
[x0, y0] = pol2cart(th*0.0174532925, 100);
[x, y] = pol2cart(th*0.0174532925, r);
set(h(th),'XData',[x0,x]);
set(h(th),'YData',[y0,y]);
m = plot([0,x0],[0,y0],'r','LineWidth',3);
drawnow
delete(m);
end

Credits

123hridoy
2 projects • 3 followers

Comments