5078+ beoordelingen
Bestel voor 16:00 voor dezelfde dag verzending
14 dagen retour
NL
Particulier
Zakelijk
In dit project laat ik jullie zien hoe je zelf een Arduino Radar maakt.
Dit is een gemiddeld/gevorderd project.
Als je project in elkaar zit zullen objecten tot 50 cm van de sensor weergeven. Als je de code aanpast kan de radar objecten tot wel 5 meter waarnemen.
Voor dit project heb je twee verschillende programma’s nodig Arduino IDE en Processing. De taal die Processing gebruikt is java dus houd hier rekening mee.
Nu gaan we het project in elkaar zetten.
Je begint met de 5V vanaf de Arduino naar het breadbord te sturen. Daarna ga je vanaf het breadbord naar de plus poort van de servo en de sensor.
Als je dat hebt gedaan ga je vanaf de GND van de servo en de sensor naar de GND van de Arduino.
Tot slot sluit je de stuur kabel van de servo aan op pin 9, de echopin op pin 6 en de trigpin op pin 7.
leftRightServo.write(leftRightPos);
for (index = 0; index<=numReadings;index++) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pulseTime = pulseIn(echoPin, HIGH);
distance = pulseTime/13;
total = total + distance;
delay(10);
}
average = total/numReadings;
if (index >= numReadings) {
index = 0;
total = 0;
}
if(average >= 300){
average = 300;
}
Serial.print(“X”);
Serial.print(leftRightPos);
Serial.print(“V”);
Serial.println(average);
}
for(leftRightPos = 180; leftRightPos > 0; leftRightPos–) {
leftRightServo.write(leftRightPos);
for (index = 0; index<=numReadings;index++) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pulseTime = pulseIn(echoPin, HIGH);
distance = pulseTime/13;
total = total + distance;
delay(10);
}
average = total/numReadings;
if (index >= numReadings) {
index = 0;
total = 0;
}
if( average >= 300){
average = 300;
}
Serial.print(“X”);
Serial.print(leftRightPos);
Serial.print(“V”);
Serial.println(average);
}
}
import processing.serial.*;
Serial arduinoport;
float x, y;
int radius = 350;
int w = 300;
int degree = 0;
int value = 0;
int motion = 0;
int[] newValue = new int[181];
int[] oldValue = new int[181];
PFont myFont;
int radarDist = 0;
int firstRun = 0;
void setup(){
size(750, 450);
background (0);
myFont = createFont(“verdana”, 12);
textFont(myFont);
arduinoport = new Serial(this, “COM10”, 9600);
}
void draw(){
fill(0);
noStroke();
ellipse(radius, radius, 750, 750);
rectMode(CENTER);
rect(350,402,800,100);
if (degree >= 179) {
motion = 1;
}
if (degree <= 1) {
motion = 0;
}
strokeWeight(7);
if (motion == 0) {
for (int i = 0; i <= 20; i++) {
stroke(0, (10*i), 0);
line(radius, radius, radius + cos(radians(degree+(180+i)))*w, radius + sin(radians(degree+(180+i)))*w);
}
} else {
for (int i = 20; i >= 0; i–) {
stroke(0,200-(10*i), 0);
line(radius, radius, radius + cos(radians(degree+(180+i)))*w, radius + sin(radians(degree+(180+i)))*w);
}
}
noStroke();
fill(0,50,0);
beginShape();
for (int i = 0; i < 180; i++) {
x = radius + cos(radians((180+i)))*((oldValue[i]));
y = radius + sin(radians((180+i)))*((oldValue[i]));
vertex(x, y);
}
endShape();
fill(0,110,0);
beginShape();
for (int i = 0; i < 180; i++) {
x = radius + cos(radians((180+i)))*(newValue[i]);
y = radius + sin(radians((180+i)))*(newValue[i]);
vertex(x, y);
}
endShape();
fill(0,170,0);
beginShape();
for (int i = 0; i < 180; i++) {
x = radius + cos(radians((180+i)))*((newValue[i]+oldValue[i])/2);
y = radius + sin(radians((180+i)))*((newValue[i]+oldValue[i])/2);
vertex(x, y);
}
endShape();
if (firstRun >= 360) {
stroke(150,0,0);
strokeWeight(1);
noFill();
for (int i = 0; i < 180; i++) {
if (oldValue[i] – newValue[i] > 35 || newValue[i] – oldValue[i] > 35) {
x = radius + cos(radians((180+i)))*(newValue[i]);
y = radius + sin(radians((180+i)))*(newValue[i]);
ellipse(x, y, 10, 10);
}
}
}
for (int i = 0; i <= 5; i++){
noFill();
strokeWeight(1);
stroke(0, 255-(30*i), 0);
ellipse(radius, radius, (120*i), (120*i));
fill(0, 100, 0);
}
for (int i = 0; i <= 6; i++) {
strokeWeight(1);
stroke(0, 55, 0);
line(radius, radius, radius + cos(radians(180+(30*i)))*w, radius + sin(radians(180+(30*i)))*w);
fill(0, 55, 0);
noStroke();
if (180+(30*i) >= 300) {
text(Integer.toString(180+(30*i)), (radius+10) + cos(radians(180+(30*i)))*(w+10), (radius+10) + sin(radians(180+(30*i)))*(w+10), 25,50);
} else {
text(Integer.toString(180+(30*i)), radius + cos(radians(180+(30*i)))*w, radius + sin(radians(180+(30*i)))*w, 60,40);
}
}
noStroke();
fill(0);
rect(350,402,800,100);
fill(0, 100, 0);
text(“Degrees: “+Integer.toString(degree), 100, 380, 100, 50);
text(“Radar screen code “, 540, 380, 250, 50);
fill(0);
rect(70,60,150,100);
fill(0, 100, 0);
text(“Screen Key:”, 100, 50, 150, 50);
fill(0,50,0);
rect(30,53,10,10);
text(“First sweep”, 115, 70, 150, 50);
fill(0,110,0);
rect(30,73,10,10);
text(“Second sweep”, 115, 90, 150, 50);
fill(0,170,0);
rect(30,93,10,10);
text(“Average”, 115, 110, 150, 50);
fill(0, 255, 0);
text(“10”, 455, 375, 200, 200);
fill(0, 255, 0);
text(“20”, 455, 310, 200, 200);
fill(0, 255, 0);
text(“30”, 455, 250, 200, 200);
fill(0, 255, 0);
text(“40”, 455, 190, 200, 200);
fill(0, 255, 0);
text(“50”, 455, 130, 200, 200);
}
void serialEvent (Serial arduinoport) {
String xString = arduinoport.readStringUntil(‘\n’);
if (xString != null) {
xString = trim(xString);
String getX = xString.substring(1, xString.indexOf(“V”));
String getV = xString.substring(xString.indexOf(“V”)+1, xString.length());
degree = Integer.parseInt(getX);
value = Integer.parseInt(getV);
oldValue[degree] = newValue[degree];
newValue[degree] = value;
firstRun++;
if (firstRun > 330) {
firstRun = 333;
}
}
}