STM32 Based Quadcopter For Obstacle Avoidance Using Ultrasonic Sensor Prof. Priya Gupta Electronics & Telecommunication Department K J Somaiya Institute of Technology Mumbai, India priya.ag@somaiya.edu Muiz Tanki Fredrick Ambrose Electronics & Telecommunication Department K J Somaiya Institute of Technology Mumbai, India fredrick.a@somaiya.edu Aarti Kumbhar Sahil Naik Electronics & Telecommunication Department K J Somaiya Institute of Technology Mumbai, India sahil.naik1@somaiya.edu Jainam Shah Electronics & Telecommunication Department K J Somaiya Institute of Technology Mumbai, India muiz.tanki@somaiya.edu Electronics & Telecommunication Department K J Somaiya Institute of Technology Mumbai, India aarti.k@somaiya.edu Electronics & Telecommunication Department K J Somaiya Institute of Technology Mumbai, India jas@somaiya.edu Abstract—This research paper presents the development of a drone system that is based on a quadcopter and utilizes an ultrasonic sensor for evaluating obstacles and measuring altitude. The project employs an STM32 microcontroller and Arduino programming to establish a quadcopter platform that is both affordable and educational. The system encompasses various functionalities such as auto-leveling and altitude maintenance. The hardware components and calibration procedures are extensively elucidated to ensure a flight that is safe and dependable. The paper highlights the importance of calibrating the sensor, balancing the motors and propellers, and effectively implementing obstacle avoidance and altitude measurement capabilities. In conclusion, this project offers a comprehensive resolution for self-sufficient drone navigation and control. Keywords—Obstacle avoidance, Ultrasonic Sensor, STM32 I. Quadcopter, Drone, INTRODUCTION Over the past few years, the rise in unmanned aerial vehicles (UAVs), commonly referred to as drones, has sparked a surge of interest in self-governing flight systems. Drones are used in a variety of fields, such as monitoring, farming, and delivering packages, where they must navigate intricate environments with accuracy and safety. The success of self-governing drone systems depends on their ability to detect and avoid obstacles in real-time, ensuring secure operation. This research article presents a comprehensive examination of integrating ultrasonic sensors for obstacle avoidance and altitude measurement in a quadcopter-based drone system. In our quest to develop an effective and economical solution, we leverage the power of STM32F103C8T6 microcontrollers, combined with Arduino programming, to establish a versatile and informative platform. The core objectives of this study are to achieve a minimalistic yet robust codebase and to minimize overall project costs while ensuring effective obstacle detection and altitude control. Our system relies on strategically placing four to six ultrasonic sensors, allowing the drone to perceive its surroundings and respond to obstacles instantaneously. We delve into the complexities of selecting appropriate hardware, calibration methods, and sensor fusion algorithms to create a reliable and adaptable obstacle avoidance system. XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE Additionally, accurate altitude measurement plays a vital role in achieving stable flight, particularly in challenging terrain or during independent missions. Throughout this study, we emphasize the importance of sensor calibration, motor-propeller equilibrium, and precise control algorithms to optimize the system's efficiency. We investigate the difficulty of integrating sensors, assembling hardware, and developing software to offer a comprehensive approach to quadcopter-based drone autonomy. As the UAV industry continues to progress, the discoveries from this investigation contribute to the advancement of safer and more capable drone systems, with various applications ranging from independent monitoring to search and rescue operations. The successful implementation of ultrasonic sensors for obstacle avoidance and altitude measurement in our quadcopter-based drone system represents a significant stride towards enhancing the capabilities and safety of self-governing UAVs. II. DRONE DESIGN A. To create a quadcopter-based drone system with a focus on educational and hobbyist applications. Here's an overview of the key elements of this drone design: B. Flight Controller: The heart of the design is the STM32 quadcopter flight controller, which is programmed using the Arduino IDE. This flight controller serves as the central processing unit for stabilizing the drone, managing sensor data, and executing flight control algorithms. C. Cost Efficiency: An essential aspect of the design philosophy is to keep costs to a minimum, making it accessible to a wide range of enthusiasts and students. The goal is to create a complete drone system for under Rs 15,000, including essential components like the battery, charger, remote control, and telemetry system. D. Hardware Selection: The drone design specifies a list of hardware components, including the STM32F103C8T6 microcontroller, MPU-6050 gyro/accelerometer, Flysky FS-T6 6-CH TX Transmitter with IA6B Receiver, resistors, LEDs, and more. These components are chosen for their compatibility and cost-effectiveness. E. Balancing and Calibration: Proper motor and propeller balancing, along with sensor calibration, are critical steps in ensuring stable and safe flight. The design provides guidance on balancing props and calibrating sensors to optimize performance. F. Software Development: The software of the drone is crucial to flight stability and control. To provide transparency and user-friendliness, the flight controller code is extensively documented and commented on. This enables code explorers to go into the code, tweak it, and adapt it to their unique needs. TX Transmitter & for receiver we use Flysky FS-iA6B Receiver. On the schematic, only the ground and signal wires of ESC 2, 3, and 4 are connected, which is the correct configuration. The +5V (BEC) from ESC 1 is also connected, supplying power to the flight controller. If your ESC lacks a built-in BEC/+5V, you must supply power using a 5V step-down regulator connected to the flight battery. You will need a 1 x Mini DC 7~28V to DC 5V step-down converter for this purpose. L. FTDI Adapter: The FTDI adapter is used for programming and communicating with the STM32 microcontroller. It provides a USB-to-serial interface, allowing you to upload code and debug the microcontroller using a computer. The FTDI adapter is connected to the UART (Universal Asynchronous Receiver-Transmitter) pins of the STM32 to establish communication. M. LiPo Battery: The LiPo battery is the power source for the drone's electronics, including the STM32 microcontroller. By connecting the LiPo battery to the STM32, you provide it with the necessary power to operate. The battery is typically regulated to a suitable voltage for the microcontroller's power supply. Figure 1. Block Diagram of Connections between components of drone G. Flight Controller: Choose a flight controller board with sufficient processing power and sensor inputs. Ensure it supports sensor integration, such as accelerometers and gyroscopes for stability control. Implement flight control algorithms to stabilize the drone using sensor data. H. Control and Navigation Algorithms: Implement control and navigation algorithms that take the obstacle detection data into account and adjust the drone's flight path to avoid collisions. I. Testing and Validation: Conduct rigorous testing and validation of our obstacle avoidance system. This may involve simulated testing, controlled indoor flights, and outdoor field tests. Collect data to evaluate the system's performance. If you look at Fig. 1 in this schematic diagram, you'll notice that we're using our main component, the STM32F103C8T6, connected to the voltage divider R3 and R4. These resistors divide the flight battery voltage by 11, allowing us to monitor the battery voltage during flight. J. The LED will illuminate when the battery voltage drops too low, and the motor RPM will automatically increase to compensate for the decreasing battery voltage during flight. It's crucial to install the 1kΩ and 10kΩ resistors; otherwise, the quadcopter will not fly perfectly, and the battery warning system will not function. Mounting the gyro in the incorrect orientation can lead to an immediate upside-down flip of the quadcopter. Ensure you use thin double-sided tape for mounting, avoiding foam tape or any other damping material, as these can reduce performance. K. Ensure that the transmitter has adjustable endpoints and subtrims by referring to its manual for these specific functions. The transmitter we use is the Flysky FS-T6 6-CH N. Overall, the FTDI adapter enables programming and communication with the STM32, while the LiPo battery supplies power to the microcontroller and other drone components. In summary, this drone design provides an accessible and cost-effective platform for building a quadcopter-based drone system. implementing obstacle avoidance in a drone is a complex task that requires a deep understanding of drone hardware, software development, control systems, and sensor integration. III. SYSTEM DESIGN A. The system design of the obstacle avoidance drone involves integrating an ultrasonic sensor with existing components such as the frame, motors, microcontroller, and gyro/accelerometer. The sensor sends ultrasonic waves and measures the time taken for the waves to bounce back, allowing for distance calculation. The STM32F103C8T6 microcontroller processes the sensor data and controls the drone's movements. The implementation includes connecting the sensor to the microcontroller, programming the microcontroller to interpret the sensor data, and adjusting the drone's movements based on the obstacle detection. Further testing and refinement are needed for optimal performance. B. Frame: We are using a 450 size frame with an integrated power distribution board. This frame provides the structure and support for the rest of the components. C. Motors and Props: The drone is equipped with four 1000kV motors and 10x4.5 props. These motors generate the necessary thrust to lift and maneuver the drone. D. ESCs: We have a motor/ESC combo, which means the Electronic Speed Controllers (ESCs) are integrated with the motors. ESCs regulate the speed and direction of the motors. E. Flight Controller: We are using an STM32F103C8T6 microcontroller as the flight controller. This microcontroller handles the processing and control of the drone's flight. F. Sensors: The MPU-6050 gyro/accelerometer is used for stability and orientation control. It provides data on the drone's attitude and motion. G. Transmitter & Receiver: The Flysky FS-T6 6-CH TX Transmitter is used for controlling the drone remotely. It sends signals to the receiver on the drone to control its movements. The FS-iA6B Receiver is a component used in the drone system to establish communication between the transmitter and the flight controller. It operates on a specific frequency and receives signals transmitted from the transmitter. H. Power: The drone is powered by a 3S/2200mAh/30C lipo battery, which is connected through a XT60 connector. I. Charging: You have a 2S/3S lipo battery charger for charging the drone's battery. J. LEDs: The drone is equipped with 3mm LEDs in red, yellow, and green for visual indicators. IV. LITERATURE SURVEY The research paper introduces a quadcopter-based drone system incorporating ultrasonic sensors for obstacle avoidance and altitude measurement using an STM32 microcontroller. Drones, vital in various industries, demand precise navigation through complex terrains for safety. This study focuses on integrating ultrasonic sensors into the drone platform, utilizing STM32 microcontrollers with Arduino programming for cost-effectiveness. It emphasizes achieving robust obstacle detection and accurate altitude control while minimizing project costs. Detailed hardware descriptions, calibration methods, and sensor fusion algorithms are discussed. The successful integration of ultrasonic sensors enhances drone safety and autonomy, marking a significant step forward in UAV technology. ● ● ● ● B. Overall, integrating the ultrasonic sensor and obstacle avoidance feature with the YMFC-32 quadcopter project adds an additional layer of intelligence and autonomy to the drone's capabilities, making it more versatile and efficient in its operations. ● ● ● Connect the motors to the ESCs and mount them securely on the frame. Connect the ESCs to the flight controller (STM32F103C8T6) according to the pinout diagram. Connect the MPU-6050 gyro/accelerometer to the flight controller. Connect the Flysky FS-T6 transmitter to the flight controller. Mount the glass fiber prototyping PCB and solder the components according to the schematic. Connect the ultrasonic sensors to the flight controller for obstacle avoidance. VI. CONCLUSION In conclusion, our project contributes to the field of drone technology by providing a practical and reliable obstacle avoidance solution using ultrasonic sensors. This research opens doors for safer and more autonomous drone operations in real-world environments. The successful integration of ultrasonic sensors and the development of a robust algorithm represent important contributions to the field. As technology continues to evolve, there is ample opportunity for further refinement and expansion of our system to address emerging challenges and applications in the drone industry. REFERENCES 1. 2. 3. V. IMPLEMENTATION A. To implement obstacle detection and avoidance, the ultrasonic sensor can continuously measure the distance to obstacles in the quadcopter's flight path. If an obstacle is detected within a certain range, the flight controller can send commands to the quadcopter's motors to adjust its flight path and avoid the obstacle. This can be achieved by programming the flight controller to interpret the sensor data and make appropriate adjustments to the quadcopter's flight parameters. With the obstacle avoidance feature, the quadcopter will be able to autonomously navigate its surroundings and avoid collisions with obstacles. This enhances the safety and maneuverability of the drone, making it suitable for various applications such as aerial photography, surveillance, or even delivery services. Connect the XT60 connector to the power distribution board and connect the battery. 4. 5. Suherman, Rizky Ananda Putra and Maksum Pinem “Ultrasonic Sensor Assessment for Obstacle Avoidance in Quadcopter-based Drone System” in 2020 3rd International Conference on Mechanical, Electronics, Computer, and Industrial Technology (MECnIT) p50-53, IEEE 2020 M. Guanglei, P. Haibing, “The application of ultrasonic sensor in the obstacle avoidance of quad-rotor UAV,” in 2016 IEEE Chinese Guidance, Navigation and Control Conference (CGNCC) p 976-981, IEEE, 2016. H. Anis, AH, Fadhillah, S. Darma, S. Soekirno, “Automatic Quadcopter Control Avoiding Obstacle Using Camera with Integrated Ultrasonic Sensor”, in Journal of Physics: Conference Series vol. 1011, no. 1, p 012046, IOP Publishing, 2018. Masatoshi Hamanaka, and Fujio Nakano “Surface-Condition Detection System of Drone-Landing Space using Ultrasonic Waves and Deep Learning” 2020 International Conference on Unmanned Aircraft Systems (ICUAS) Athens, Greece. September 1-4, 2020 p1452-1459, IEEE 2020. MC De Simone, Z. B., Rivera, D. Guida, “Obstacle avoidance system for unmanned ground vehicles by using ultrasonic sensors”, Machines, vol.6, no. 2, p18, 2018.