Fusion Robotics

Hi everyone!

For this post, I’m doing something very different. I’m building a simulation for an Arduino radar!

DISCLAIMER:

A big shoutout to Robotics India for the amazing ideas and tutorials on Arduino projects. Many of the concepts here were inspired by their work, and we’ve adapted them to fit the flow of this post. We encourage readers to check out Robotics India’s content for even more detailed insights and guidance.

Furthermore, I did not use any form of AI assistance in this project. Thanks!

This is my first time EVER doing something like this. Therefore, I’ve looked online for some ideas, and have come across the holy grail of videos.

Check it out!

After watching the video, I decided to recreate the project myself, a mini Arduino radar system using an ultrasonic sensor (HC-SR04) and a servo motor.

DISCLAIMER: This code is heavily inspired by a YouTuber, and under no circumstances do I claim it as my own. I have, however, studied how the code works and believe I have a solid understanding of its functionality. My explanation within the code below reflects my own understanding and interpretation.

The basic idea is simple: the servo rotates the ultrasonic sensor back and forth, sending out sound waves to detect objects. The distance readings are then used to simulate a radar sweep, just like what you’d see on an actual radar screen.

Here’s what the setup includes:

  • Arduino UNO (the brain of the project)
  • HC-SR04 Ultrasonic Sensor (for distance measurement)
  • SG90 Micro Servo (to rotate the sensor)
  • Breadboard and jumper wires (for connections)

The circuit sends out ultrasonic pulses, measures how long they take to return, and converts that time into distance. Then, the servo moves to a new angle and repeats the process, scanning the area in front of it.

Here is the BOM (parts list), and code below, along with an explanation of how everything works!

ComponentQuantityDescription
Arduino UNO1The “Brain” of he circuit
HC-SR04 Ultrasonic Sensor1Sends and receives sound waves to measure distance.
SG90 Micro Servo Motor1Rotates the ultrasonic sensor to scan different angles.
Breadboard1Makes it easy to connect components without soldering.
Male-to-Male Jumper Wires1For all electrical connections between the components.
USB Cable (Type-B)8Used to upload code and power the Arduino.
#include <Servo.h>  
// Includes the Servo library, which allows control of servo motors.

const int SERVO_PIN = 11;  
const int TRIG_PIN = 8;  
const int ECHO_PIN = 9;  
// Defines which Arduino pins are connected to the servo and ultrasonic sensor.

const int MIN_ANGLE = 0;  
const int MAX_ANGLE = 180;  
const int ANGLE_STEP = 1;  
const int SWEEP_DELAY = 15;  
// Sets the servo movement range and speed of rotation.

const float SOUND_SPEED_FACTOR = 58.2;  
// Used to convert the echo time (in microseconds) to distance (in centimeters).

Servo myServo;  
// Creates a Servo object to control the servo motor.

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  myServo.attach(SERVO_PIN);
  Serial.begin(9600);
}
// Initializes pin modes, connects the servo, and starts serial communication.

void loop() {
  sweepAndMeasure(MIN_ANGLE, MAX_ANGLE, ANGLE_STEP);
  sweepAndMeasure(MAX_ANGLE, MIN_ANGLE, -ANGLE_STEP);
}
// Continuously sweeps the servo from 0° to 180° and back, taking distance readings.

void sweepAndMeasure(int startAngle, int endAngle, int step) {
  for (int angle = startAngle; (step > 0) ? (angle <= endAngle) : (angle >= endAngle); angle += step) {
    myServo.write(angle);
    delay(SWEEP_DELAY);
    int distance = calculateDistance();
    printData(angle, distance);
  }
}
// Moves the servo in steps, measures the distance at each angle, and sends the data to Serial.

int calculateDistance() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  long duration = pulseIn(ECHO_PIN, HIGH);
  return static_cast<int>(duration / SOUND_SPEED_FACTOR);
}
// Sends an ultrasonic pulse, measures how long it takes to return, and converts that time to distance.

void printData(int angle, int distance) {
  Serial.print(angle);
  Serial.print(",");
  Serial.print(distance);
  Serial.print(".");
}
// Prints each angle and corresponding distance reading to the Serial Monitor for radar visualization.

In short, it sweeps a servo back and forth while measuring and logging distances with an ultrasonic sensor.

Here is the link to this project

Here is the demonstration:

Thanks for reading!

Comments

5 Responses to “Fusion Robotics”

  1. mcrompton Avatar
    mcrompton

    OK, Princeton. This is a start. I like the fact that you recognize that while many of the ideas (and perhaps much of the code) is taken from others, you used that information to learn and can explain how it works. The post is lacking in a number of areas however. I see no evidence that you actually built this. While we did make the phsyical prototype optional given certain issues, I do expect to see a demonstration of at least a virtual prototype of your device. I need circuit diagrams, a link to the arduino simulator (Tinkercad?) and likely a video of the working prototype. While you say you based much of your work off of a specific video, you don’t say whether you used AI or not. If you did, I need to see that transcript. You’ve got some work to do before you resubmit.

    1. princetonc Avatar
      princetonc

      Thank you Mr. Crompton.

      I have included a disclaimer stating my usage of AI and uploaded the Arduino simulation.

      However, my screen recording software is bugged, but i will re-submit it when I work it out soon. Thanks!

      1. mcrompton Avatar
        mcrompton

        OK. This is improved, but I still need to see an actual demonstration. Given that I can’t access the TinkerCAD link and there is no video, I can’t give you credit for this yet. I also need to see the circuit diagram. Please resubmit when those are all fixed.

  2. princetonc Avatar
    princetonc

    All done, I hope the video works!

    Edit: I am unable to upload a video, as it exceeds the max capacity. But the link to view the project should work

    1. mcrompton Avatar
      mcrompton

      Hi, Princeton. I don’t see a link on your blog to the video. Typically people publish their video to YouTube as unlisted and embed that link in their blog. Also, now that I see your TinkerCAD project, I don’t see the servo moving in response to the sensor. I wonder if you know if this is a coding or a circuitry issue.

Leave a Reply to mcrompton Cancel reply

Your email address will not be published. Required fields are marked *