in this tutorial we will learn about how to make a simple radar system using Magicbit core dev board. For this purpose we use HC-SR04 ultrasonic sensor and to displaying data, we use processing environment. Lets get start.
Theory and MethodologyFirst, lets discuss how does this work. The principle is very easy. First we rotate our sensor around vertical axis in 180 degree range continuously. During that motion we take the data about distance to nearest object from ultrasonic sensor at every angle. For this process we use Magicbit core board. After, we have to establish the connection with processing environment for showing our data. Therefor we use serial communication protocol with suitable baud rate. Then we design our radar system interface by using processing IDE. In that IDE we configure our serial communication for get real time data via serial. So we do real time communication with Magicbit and show the the data which send from Magicbit to the processing IDE.
Hardware setupFor this project we mainly used three hardware components. They are Magicbit, servo motor and ultrasonic sensor. The connection between all these parts are shown in below Figure.
Ultrasonic sensor used 3.3 v for power up. Therefor we used right lower port of Magicbit board to connect ultrasonic sensor to Magicbit. But servo motor is used 5V for proper working, Therefor we used left lower port to connect servo motor with Magicbit. In this case, we use Magic bit servo connector module. But if you don't have that module you can use three jumper wires to connect 5V to 5V, Gnd to Gnd and signal pin to 26 pin on magicbit.
After build the circuit we have small mechanical part to build. set single side servo connector to servo motor using small nut. Then fix the sensor on that connector using some L shaped bracket or proper way. After the whole system we fixed on breadboard. But you can use other surface to mount servo and Magicbit.
Software SetupThe software side is littlebit complex. For proper understand you can refer the following links to before move on next part.
https://magicbit-arduino.readthedocs.io/en/latest/
https://hello.processing.org/editor/
let's look at Arduino IDE code and how that code is work.
For driving servo we use ESP32 servo library. This library almost include in magic bit board manager in Arduino IDE. To deal with ultrasonic sensor we use newPing library. This can be download from following link.
https://bitbucket.org/teckel12/arduino-new-ping/downloads/
Download the zip file and and go tools>include library>add Zip library in Arduino. now select your downloaded zip file of new pin library. For communicate with processing we used serial communication with 115200 baud rate. This is most proper frequency for ESP32. At every angle we send our data to computer using this protocol. Distance to the nearest front object from the sensor, direction of rotation and rotate angle are include in this data. Using two for loops we rotate our servo in two direction. While one degree rotation we sent serial data at 4 times. The reason for that you can understand in processing part explanation.
now it's time to look at processing environment. This is java based programming software. we can write sketch of our programme in this sketch in processing IDE. we can also generate visual output from running our programme. Also you can take output as 2D and 3d objects. Not only that, this can used for image processing and many more things.
In the processing sketch first we design our data display interface using simple graphic functions. At the start of the code we establish our serial communication by including serial libraries. In the setup function you have to do some change according which USB port you used to connect Magicbit with computer. you can check your port using Arduino IDE when you setup the Arduino IDE to uploading the code. Then change com port name in setup part in processing sketch. when the serial data is available, Serialevent function is automatically triggering. Therefor the main logic of the code is include in serial event for prevent the angles and data missing. when new data is available, we draw a line in the screen according to our angle.At that time if there is no object detect, then full line is green colored. If not then some portion of the line will be red according to distance from sensor to object. Also the according rotation direction we draw another 200 lines near to that line with decreasing level of green color. between each Main we have 0.25 degree difference. Therefor we get 4 readings at a time from Magicbit in each degree rotation. Because of that we can create beautiful searching hand in screen.
after uploading code success fully to magic and set hardware part successfully open the processing IDE and run the code by clicking run button. Now you have very simple radar system.
you can customize the codes as you wish what you want to display.
Troubleshooting.processing sketch is not running.
- wait some time. Because of the start up time is depend on your PC and GPU performance.
- check the serial port number is correct on processing sketch.
- check the USB connection is fixed correctly.
- check the connection between ultrasonic sensor and Magicbit.
- open the serial monitor and check the data is coming from Arduino. If not, then problem is your Arduino code or on your USB connection.
servo is not working
- check the USB connection is fixed correctly
- check the wiring
- check the servo is in good condition.
Comments