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