├── README.md └── radar code.txt /README.md: -------------------------------------------------------------------------------- 1 | # radar_code -------------------------------------------------------------------------------- /radar code.txt: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | UltraSonicDistanceSensor distanceSensor(6, 7); //Create the 1st sensor object 5 | UltraSonicDistanceSensor distanceSensor2(5, 4); //Create the 2nd sensor object 6 | Servo servoMotor; //Create the Servo object 7 | 8 | int delayTime = 5; //Delay value to wait for the servo to reach the 1 angle difference 9 | long d; //Distance from 1st sensor calculated 10 | long d2; //Distance from 2nd sensor calculated 11 | 12 | void setup() { 13 | Serial.begin(9600); //Initialize the Serial communication at 9600 bauds 14 | 15 | servoMotor.attach(2); //Attach the servo to the Digital PWM pin 2 16 | servoMotor.write(180); //Rotate the servo to the 180? 17 | delay(1000); //Wait for the servo to reach 180? 18 | servoMotor.write(0); //Rotate the servo to the 0? 19 | delay(1000); //Wait for the servo to reach 0? 20 | 21 | } 22 | 23 | void loop() { 24 | for (int i = 1; i < 180; i++) { //Move the Servo 180 degrees forward 25 | readSensors(); //Read the sensors --------------------------------------------------------------------------------