#include <Servo.h>
#include <Ultrasonic.h>
#define trigPin 12
#define echoPin 13
Ultrasonic us(12, 13);
int distance;
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
distance = us.read(CM);
myservo.write(distance / 3);
Serial.print("The distance of ultrasonic:");
Serial.println(distance);
Serial.print("The angle of servo motor:");
Serial.println(distance/3);
delay(1000);
}