Introduction: Arduino Motor Radar

This is a radar made with Arduino, this Radar allows users to detect objects.

Supplies

The materials needed:

Arduino Board

Servo motor

HC-SR04 Ultrasonic sensor

Breadboard

Jumper wires

Step 1:

Have the sensor and the motor ready, then glue the lego stand on the motor. Stick the sensor to the lego pieces.

Step 2:

Connect all the jumper wires on the Arduino board.

Step 3:

(Changed)

Arduino Code:

#includeconst int TriggerPin = 8;
const int EchoPin = 9;

const int motorSignalPin = 10;

const int startingAngle = 90;

const int minimumAngle = 10;

const int maximumAngle = 140;

const int rotationSpeed = 3;

Servo motor;

void setup(void) { pinMode(TriggerPin, OUTPUT);

pinMode(EchoPin, INPUT);

motor.attach(motorSignalPin);

Serial.begin(9600);

} void loop(void) { static int motorAngle = startingAngle; static int motorRotateAmount = rotationSpeed;

motor.write(motorAngle);

delay(10);

SerialOutput(motorAngle, CalculateDistance());

motorAngle += motorRotateAmount;

if(motorAngle <= minimumAngle || motorAngle >= maximumAngle) { motorRotateAmount = -motorRotateAmount;

}} int CalculateDistance(void) { digitalWrite(TriggerPin, HIGH);

delayMicroseconds(10); digitalWrite(TriggerPin, LOW); long duration = pulseIn(EchoPin, HIGH); float distance = duration * 0.017F; return int(distance);

} void SerialOutput(const int angle, const int distance) { String angleString = String(angle); String distanceString = String(distance); Serial.println(angleString + "," + distanceString);

}

Step 4: Credits

Thanks to JohnM1579 for the awesome idea

Link: https://www.instructables.com/Arduino-Radar-1/#di...

Arduino Instructables

Step 5: Video