{"id":21018793,"url":"https://github.com/hantdev/shortrangeradar","last_synced_at":"2025-05-15T06:31:52.607Z","repository":{"id":244488952,"uuid":"814292869","full_name":"hantdev/shortrangeradar","owner":"hantdev","description":"Short Range Ultrasonic Radar - A simple radar using the ultrasonic sensor, this radar works by measuring a range from 3cm to 40 cm as non-contact distance, with angle range between 15˚ and 165˚.","archived":true,"fork":false,"pushed_at":"2024-11-11T11:24:58.000Z","size":16382,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-19T17:12:45.624Z","etag":null,"topics":["arduino","c","esp32","iot","radar","sr04"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hantdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-12T18:05:14.000Z","updated_at":"2024-12-14T05:01:07.000Z","dependencies_parsed_at":"2024-11-19T10:35:13.296Z","dependency_job_id":"d8758094-199c-4cb2-b5ed-25abdeae79c0","html_url":"https://github.com/hantdev/shortrangeradar","commit_stats":null,"previous_names":["hantbk/shortrangeradar","hantdev/shortrangeradar"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hantdev%2Fshortrangeradar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hantdev%2Fshortrangeradar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hantdev%2Fshortrangeradar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hantdev%2Fshortrangeradar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hantdev","download_url":"https://codeload.github.com/hantdev/shortrangeradar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254288270,"owners_count":22045868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","c","esp32","iot","radar","sr04"],"created_at":"2024-11-19T10:27:39.582Z","updated_at":"2025-05-15T06:31:47.595Z","avatar_url":"https://github.com/hantdev.png","language":"C++","readme":"# Short Range Ultrasonic Radar\n![Cover](./assets/cover.webp)\n\n## 📝 Table of Contents:\n[A. Introduction](#I-Introduction)\n\n[B. User Guide](#II-User-Guide)\n\n[C. Component List](#III-Component-List)\n\n[D. Schematic Diagram](#IV-Schematic-Diagram)\n\n[E. Software Design](#V-Software-Design)\n\n[F. Authors](#VI-Authors)\n\n\u003ca name=\"I-Introduction\"\u003e\u003c/a\u003e\n## 🏁 A. Introduction\n- This project uses an ultrasonic sensor to measure the distance from the sensor to obstacles within a range of 2cm to 400cm (0.8inch to 157inch) with an accuracy of 0.3cm (0.1inch), which is good for most applications.\n- Uses a servo motor to sweep a 180-degree angle.\n- The measured distance will be displayed on a 1.3-inch OLED screen in the form of a horizontal scanning radar.\n- The project is implemented on the ESP32 board.\n- The project is suitable for use in small spaces such as rooms, corridors, etc.\n\n## HC-SR04 Ultrasonic Sensor Technical Data\nThe following table shows the key features and specs of the HC-SR04 ultrasonic sensor. For more information, you should consult the sensor’s datasheet.\n\n| Feature | Description |\n| :---: | :---: |\n| Power Supply | 5V DC |\n| Working Current | 15mA |\n| Working Frequency | 40kHz |\n| Maximum Range |  4 meters |\n| Minimum Range | 2 cm |\n| Mesuring Angle | 15º |\n| Resolution | 0.3 cm |\n| Trigger Input Signal | 10uS TTL pulse |\n| Echo Output Signal | TTL pulse proportional to the distance range |\n| Dimensions | 45mm x 20mm x 15mm |\n\n## How Does the HC-SR04 Ultrasonic Sensor Work?\nThe ultrasonic sensor uses sonar to determine the distance to an object. Here’s how it works:\n\n1. The ultrasound transmitter (trig pin) emits a high-frequency sound (40 kHz).\n2. The sound travels through the air. If it finds an object, it bounces back to the module.\n3. The ultrasound receiver (echo pin) receives the reflected sound (echo).\n\n![HC-SR04 Ultrasonic Sensor](./assets/sr04.webp)\n\nTaking into account the sound’s velocity in the air and the travel time (time passed since the transmission and reception of the signal) we can calculate the distance to an object. Here’s the formula:\n  \n```\ndistance to an object = ((speed of sound in the air)*time)/2\n```\n- where: speed of sound in the air at 20ºC (68ºF) = 343m/s\n\n\n\u003ca name=\"II-User-Guide\"\u003e\u003c/a\u003e\n## 🧾 B. User Guide\nSteps to implement:\n- Connect the ultrasonic sensor to the circuit according to the schematic diagram.\n- Connect the servo motor to the circuit according to the schematic diagram.\n- Connect the OLED screen to the circuit according to the schematic diagram.\n- Upload the code to the circuit.\n- Place the circuit in a fixed position, do not move it.\n- When an obstacle moves past the sensor, the screen will display a horizontal scanning radar image.\n\nPin connection convention:\n| SR04 Ultrasonic Pin | Servo Pin    | OLED Pin    | ESP32 Pin |\n| :---:   | :---: | :---: | :---: |\n| VCC | VCC   | VCC   | 3.3V |\n| Trig |   |  | 23   |\n| Echo |   | | 18   |\n| GND  | GND   | GND  | GND  |\n|       |   | SDA  | 21   |\n|       |  | SCK  | 22   |\n|       | PWM  |  | D5   |\n\nConnection diagram:\n![Connection diagram](./assets/simulation.png)\n\nActual image:\n\n![Actual circuit](./assets/radar.png)\n\nDemo video:\n\nhttps://github.com/DoDat-12/shortrangeradar/assets/89787228/abf60fdb-f4bd-479f-adab-8d7409c9bfb1\n\n\n\n\u003ca name=\"III-Component-List\"\u003e\u003c/a\u003e\n## 🧰 C. Component List\n1. HC-SR04 Ultrasonic Sensor\n- Quantity: 1\n- Purchase link: [HC-SR04](https://www.amazon.com/Ultrasonic-Measuring-Transducer-ultrasonic-transducer/dp/B0DDHGRP6C/ref=sr_1_4?crid=1IB3FHUI8M8N3\u0026dib=eyJ2IjoiMSJ9.eXeBKxGwPIAwCcKVzElQv8X3oAAwhxUeCUVdVBFUYNmUlyYLGCS0GYFsrQ2Uvwsxc7-pPrgm9S_HSuKXgtnIbmuIaC99BHFq0Yt4IfO23YlEanGObyIW4m1OSDgjuTBA36VRlU4RzidUacGqamEslIG0vaLTd9TfH7PPJVVuIjGBXAKgB_wi-FgoH06wpKCyEt5FOHXrHfxvAHVU45xF_L2gCXC8Rm0C9H8GxiwZuDw.5cQZdw4xwgxkBOHclAMM5yJXDYtIl_986gtlzTelvt8\u0026dib_tag=se\u0026keywords=hc-sr04+ultrasonic+sensor\u0026qid=1728314856\u0026sprefix=HC-SR04+Ultrasonic+Sensor,aps,1024\u0026sr=8-4)\n2. SG90 Servo Motor\n- Quantity: 1\n- Purchase link: [SG90](https://www.amazon.com/Micro-Helicopter-Airplane-Remote-Control/dp/B072V529YD/ref=sr_1_1?crid=26NMBNLO46FS8\u0026dib=eyJ2IjoiMSJ9.KPXY-1BMD4AoaoJO-RlV6e7C7amAWYjWITcPSXLXG2zRavVbnnPzOpjqZGcwc_7zs0FMRUOqX_6DKNaLZeGLp0lZtcki4KKk8l4bW1FvhkHfEQ1Zfn-Y4UGOIC5UwcoVnWFP1o20XD4xmkAYFpw5qB2VvmoqMVJhLJG5qD3AAR9tvUt1XIYa7VD948GrL0MsH60l4sDy_lnOSuCUZxFcWwYy4rWsmCHwceczUgDiQRTKZTzfqxIEHk7K3EN7FsHT1WqqYAIcMi4fUHEGivJe8-bqkGjNskY85esMS2lynFE.a2QlsUjCq1aRS1bfKfWEo9lCNisCGPLxPD0glniBCdQ\u0026dib_tag=se\u0026keywords=SG90+Servo+Motor\u0026qid=1728315406\u0026sprefix=sg90+servo+motor%2Caps%2C380\u0026sr=8-1)\n3. 1.3-inch OLED Screen\n- Quantity: 1\n- Purchase link: [1.3-inch OLED](https://www.amazon.com/DIYmalls-Display-Screen-Module-128x64/dp/B0CCL88VTG/ref=sr_1_1?crid=DKS7YMJHO96V\u0026dib=eyJ2IjoiMSJ9.oM7nbUfV8fUt1aA3u6HNbF_W5gjCcXVPl5HphE6MNMm0rhyMg8vi4yKagshxzu9jmfenfdVlJDnpuWLYFjU8LANnRDtFQkx7LEtY3JHZJ_K9kkAn5sw4eBCrQlynv2V-D6FohG8pGYmSxQcuI5_Crs_k_4tLh_4Bp1mkfKAG8_lsI7igzmYsZ2gFuMlQcow9bqElZJCmIh2rVIZcmC577QryjVXNiQheFSWWrgySSgM.O7F-4kBFAwl2S14SFISV33xN3B2-AMA-cpzpyHXVGMs\u0026dib_tag=se\u0026keywords=1.3-inch+OLED+Screen\u0026qid=1728314977\u0026sprefix=1.3-inch+oled+screen%2Caps%2C518\u0026sr=8-1)\n4. ESP32 Board\n- Quantity: 1\n- Purchase link: [ESP32](https://www.amazon.com/ESP-WROOM-32-Development-Microcontroller-Integrated-Compatible/dp/B08D5ZD528/ref=sr_1_1?crid=2TRAUGW316QTB\u0026dib=eyJ2IjoiMSJ9.Na5nlliGXytwgT8dOa8kGlXx8Rt9q6wySlhgETYvRAeszt3OtYu80LduyWzHyaKfKpUmWt7-zJbF0gLRxy61Q_QhRoBJEPr92BRRPkI2d4dTjShgDRQkToNpegRs-56rKZEYuvdRpSOiscJx_NmNJFO_uHrJUxRwIT5cVqbt7wslPAddwUalOCpUp6gaxzoK6nfpY_gJnd_iPffcv26rWO1h3LJDuemkNh_Nwqyyz-o.5DC3psoxXOO4yuME3WBP2KKEOsvgs28e0-xPVfLLXuA\u0026dib_tag=se\u0026keywords=esp32+board\u0026qid=1728314997\u0026sprefix=ESP32+Board%2Caps%2C585\u0026sr=8-1)\n5. SYB-170 Test Board\n- Quantity: 1\n- Purchase link: [Test Board](https://www.amazon.com/Aexit-Universal-Tiepoint-Solderless-Breadboard/dp/B07DDBDMQ4/ref=sr_1_2?crid=1GGISP93BAC0D\u0026dib=eyJ2IjoiMSJ9.UlZ49eWCsbbvypv6solRaqBzhUim46joXtChPDTaoKHnqxVWdF-NmQz2qDZ3Jp2U_ghbCjSuw9kXYrOtZ2ZcqIUlciB69P2OeTM6gyqyROQdtWoxHmAJ_T3TwZGMoGGej4r4ukZA2V8ddvx3r8_LW4Gr07LhE0XbJjt16Ko9MG75HWItFDUq-yOMS4dvr-z1NvJSEsrcE4PSgMO6iY7DahNifQEetJKHwnklH170rE8.R1Ukqpb4wd8t_GOvG10aQct_xlwe89hABLcPBB9hMf0\u0026dib_tag=se\u0026keywords=SYB-170+Test+Board\u0026qid=1728315461\u0026sprefix=syb-170+test+board%2Caps%2C577\u0026sr=8-2)\n6. Connecting Wires\n- Quantity: multiple\n- Purchase link: [Connecting Wires](https://www.amazon.com/Preformed-Breadboard-Assorted-Solderless-Prototyping/dp/B07WC3YKGQ/ref=sr_1_9?crid=1EOQB6Q7RQPJK\u0026dib=eyJ2IjoiMSJ9.9coO5iQ14I-rcVuj0bUrBVFPSUAKFh1d1NgQ1NQyWwJ7tyKnE0oKrp5kfVevhkrwcoV6CU8uefDsDt8r865sMy44IA4GeW6cpGUVLJONXx6q584JmpuzfgH8BVMRWoaafTxCcKja7i6CSoE-IFKOZiutt0rcAfmhEuVjIwSaoiooK9QsVDVzkWqhjxcv5AjjcZubVjP8gMqi_E1-1LxN2mweBa7q1i0aNLS0hXU9aQg.m2XSZQE8Az9vj7Z-QbaEUxCzMpkZ8ghKGJkA52uNdbc\u0026dib_tag=se\u0026keywords=Connecting+Wires\u0026qid=1728315072\u0026sprefix=connecting+wires%2Caps%2C546\u0026sr=8-9)\n\n\u003ca name=\"IV-Schematic-Diagram\"\u003e\u003c/a\u003e\n## 🚀 D. Schematic Diagram\nSchematic diagram of the project:\n\n![Schematic diagram](./assets/nguyenly.png)\n\n\u003ca name=\"V-Software-Design\"\u003e\u003c/a\u003e\n## 💻 E. Software Design\n- The code is written in C++.\n- Uses the `Ultrasonic.h` library to read data from the ultrasonic sensor.\n- Uses the `ESP32Servo.h` library to control the servo motor.\n- Uses the `U8g2lib.h` library to control the OLED screen.\n- The code is divided into subroutines such as `setup()`, `loop()`, `GetDistance()`.\n- The `GetDistance()` function will return the distance from the sensor to the obstacle.\n- The `loop()` function will sweep the 180-degree angle of the servo motor and display the distance on the OLED screen.\n\nThe HC-SR04 ultrasonic sensor operates on the following principle:\n- The sensor sends an ultrasonic signal to the obstacle through the `Trig` pin at a low level for 2uS within 10uS.\n- The ultrasonic signal will reflect from the obstacle and return to the sensor.\n- The sensor will read the returned value through the `Echo` pin with values ranging from 10 - 38 corresponding to physical distances from 2cm - 50cm.\n```c\n// Determine distance\nint GetDistance() {\ndigitalWrite(SR04_TRIG_PIN, LOW); // Set Trig pin to low level for 2uS\ndelayMicroseconds(2);\ndigitalWrite(SR04_TRIG_PIN, HIGH); // Send ultrasonic wave for 10uS\ndelayMicroseconds(10);\ndigitalWrite(SR04_TRIG_PIN, LOW); // Turn off ultrasonic wave\nunsigned int microseconds = pulseIn(SR04_ECHO_PIN, HIGH, 30000); // Wait for response, limit waiting time\nreturn microseconds / 58; // Calculate distance from travel time\n}\n```\nThe SG90 servo motor operates on the following principle:\n- The servo motor will sweep an angle from 0 to 180 degrees.\n- The servo motor will sweep the angle according to the angle we have set in the code.\n```c\n// Initialize Servo\nradarServo.attach(SERVO_PIN);\nradarServo.write(angle);\n```\n\n\nThe 1.3-inch OLED screen operates on the following principle:\n- The OLED screen uses I2C communication.\n- The OLED screen will display a horizontal scanning radar image.\n- The OLED screen will display the distance on the OLED screen.\n\n```c\ndis = GetDistance();\n    Serial.println(dis);\n\n    // Draw radar line\n    if (dis \u003e= MAX_DISTANCE) {\n      int x = centerX - radius * cos(currentAngle * PI / 180);\n      int y = centerY - radius * sin(currentAngle * PI / 180);\n      u8g2.drawLine(centerX, centerY, x, y);\n    } else {\n      int x = centerX - radius * dis * cos(currentAngle * PI / 180) / MAX_DISTANCE;\n      int y = centerY - radius * dis * sin(currentAngle * PI / 180) / MAX_DISTANCE;\n      u8g2.drawLine(centerX, centerY, x, y);\n    }\n    u8g2.sendBuffer();\n    radarServo.write(currentAngle);\n```\nFull code: [Code](./shortrangeradar.ino)\n\n\u003ca name=\"VI-Authors\"\u003e\u003c/a\u003e\n## ✍️ F. Authors\n- [Nguyen Thanh Ha](https://github.com/hantbk) - 20210298\n- [Do Thanh Dat](https://github.com/DoDat-12) - 20215560\n- [Vu Van Hao](https://github.com/vanhao2310) - 20215572\n- [Quach Dinh Duong](https://github.com/Duongneee) - 20215558\n\n⭐ If you use the project, please give us a star. Thank you!\n\n\n\n\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhantdev%2Fshortrangeradar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhantdev%2Fshortrangeradar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhantdev%2Fshortrangeradar/lists"}