-
Notifications
You must be signed in to change notification settings - Fork 2
/
radar.ino
40 lines (32 loc) · 922 Bytes
/
radar.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <Servo.h>
#include <NewPing.h>
#define TRIGGER_PIN 7 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 7 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;
long pos = 0; // variable to store the servo position
void setup() {
Serial.begin(115200);
myservo.attach(9);
}
void loop() {
for (pos = 0; pos <= 170; pos += 1)
{
Serial.print(pos);
Serial.print("|");
Serial.print(sonar.ping_cm());
Serial.println();
myservo.write(pos);
delay(15);
}
for (pos = 170; pos >= 0; pos -= 1)
{
Serial.print(pos);
Serial.print("|");
Serial.print(sonar.ping_cm());
Serial.println();
myservo.write(pos);
delay(15);
}
}