Make a Radar using Arduino and Processing Help me Guys

Hello guys can you help me. my Arduino radar using Processing

I’m try this code then i success because my servo motor and sensor are working:

#define ECHOPIN 7 // Pin to receive echo pulse
#define TRIGPIN 8
#include <Servo.h>

Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600);

myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(3,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,INPUT);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}

void Print (int R , int T)
{
Serial.print(R);Serial.print(", “);
Serial.print(T);Serial.println(”.");
delay(100);
}

float Distance () {

digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
// Distance Calculation

float distance = pulseIn(ECHOPIN, HIGH);
distance= distance/58;
return(distance);
}

void loop() {

myservo.write(45); // tell servo to go to position in variable ‘pos’

delay(2000);

for(pos = 45; pos <= 135; pos += 3) // goes from 45 degrees to 135 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’

Print(Distance() , pos);
delay(10); // waits 15ms for the servo to reach the position
}
delay(1000);

for(pos = 135; pos>=45; pos-=3) // goes from 135 degrees to 45 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
Print(Distance() , pos);

delay(10); // waits 15ms for the servo to reach the position
}

}

but my problem is my radar output but still not working the output will detect the object using my sensor and rotating in 180 degree using servo motor by using this output code:

import processing.serial.*;
Serial port;
Serial port2;
String data = “”;
String Radius = “”;
String Theta = “”;
int index = 0;
float distance = 0;
float angle = 0;
float pi = 22.0/7;

void setup()
{

size(1000,1000);
background(255,255,255);
ellipse(500,500,1000,1000);
line(500,0,500,1000);
line(0,500,1000,500);
line(500,500,1000,0);
line(500,500,0,0);

port = new Serial(this, “COM10”, 9600);
port.bufferUntil(’.’);
}

void draw()

{

}

void serialEvent(Serial port)
{

data = port.readStringUntil(’.’);
data = data.substring(0, data.length() - 1);
index = data.indexOf(",");
Radius = data.substring(0, index);
Theta = data.substring (index+1 , data.length());

translate(500,500);
point (0,0);

distance = float(Radius);
angle = float(Theta) /180 * pi;
fill(30,200,30);
ellipse(distance * cos(angle) , -1 * distance * sin(angle) , 5,5);

}

but my error is The COM# port is Busy in processing then In arduino Port COM# is already in use

which one first i run ? processing or arduino ?

Help me guys

which one first i run ? processing or arduino ?

That depends. Which one do you want to use the serial port?

Thank you mister

both arduino and processing are connecting in 1 serial port

reply in Arduino while running Processing

Ex. COM11 are already in use. try to close the program

reply in Processing while Running Arduino

Ex. COM11 are Busy

but i want to see the radar detects object the output is dot( . ) in radar output

both arduino and processing are connecting in 1 serial port

No, they are not. The Arduino is on one end of the serial port. Processing is on the other end OR the Serial Monitor is on the other end. You CAN not, on Windows, have two applications using the same serial port.

but i want to see the radar detects object the output is dot( . ) in radar output

The close the Serial Monitor application. It does NOT need to be open.

Mister.

in processing the code call the serial port:

port = new Serial(this, "COM10", 9600);
port.bufferUntil('.');

then in arduino Serial Port im using COM10

what should i do. if i want to see the output on processing detects the object. ?

When processing opens the COM port, the Arduino will reset normally.
That means you should keep the COM open in P.

The P. application can wait for events from the A. and process them OR
The A. waits for commands from P. and replies appropriately OR
mix of both. :slight_smile:

then in arduino Serial Port im using COM10

You need to get something straight. The Arduino has NO clue what is on the other end of the serial port. It is most certainly NOT aware that there is anything called COM10 anywhere in the universe.

The Serial Monitor application knows that the Arduino is on the other end of COM10.

So, which is it? Are you using the Serial Monitor, which is connecting to COM10, or not?

Thank you for help

but still a problem.

i cant understand but i want see in processing output the radar and then the dot (.) will apear if object detects

but what can i do ?

in arduino

i will verify then upload ? and then do not click the serial monitor on arduino upper right side

then i will run the processing that will show the output ?

what do you think guys ?

I think you should make a minimal program that sends some info from the Arduino and make a minimal program in Processing that captures it. Then you can learn the basics about communication. Once you master that you can extend both sides.