Ever wanted to build a sonar? We have been searching online for Radar or Sonar building tutorial, there are problems come in the way, either we are not familiar with Processing Development Environment(PDE) or the system is hard to build. So we are thinking to make a sonar system which program and completely display in graphical programming software Kittenblock, developed based on Scratch 3.0.
Graphical programming uses drag-and-drop blocks for programming and is very easy to get started with. Graphical blocks can help beginner to avoid loads of typing and syntax, creating a bridge to learn a powerful and commonly used programming language such as C++.
The sonar system consists of a detecter, the ultrasonic sensor, and a small servo motor for rotating the sonar, the main controller is RosBot baseboard, fully compatible with Kittenblock.
PartsHardware (can be adapted for your needs):
- RosBot Baseboard x1
- Ultrasonic Sensor x1
- Ultrasonic Sensor Adapter x1
- 9g Servo x1
- Dupont wires x6
- Micro-USB cable x1
You will need a base to support the 9g servo and ultrasonic sensor, in this project we use the KittenBot chassis.
Graphical programming software:
- KittenBlock v1.27 (Based on Scratch3.0)
First we will need an adapter for servo motor to rotate the ultrasonic sensor. Put tapping screws into the shaft and secure the adapter, attach the adapter on the servo.
Once you fasten the adapter, you will see the ultrasonic sensor and adapter connected like that.
Turn the ultrasonic sensor very gently all the way in one direction, then to the other direction to figure out the sonar rotating degrees, it should be a little bit over 180 degrees.
In the Kittenblock software, there is a wiring mode, you can organize the wires with ease and learn basic electrical circuit.
Connections for the 9g Micro Servo:
- VCC to 5V
- GND to RosBot's GND
- Signal wire to pin4
Connections for the ultrasonic sensor:
- VCC to 5V
- Trig to D2
- Echo to D3
- GND to GND
Before we start coding, let's load the default firmware to the RosBot Baseboard first.
Open Arduino panel and select "Restore > Arduino" to load default firmware into the edit box. Then press "Upload" button, the embedded Arduino IDE in KittenBlock may automatically compile and upload the default firmware.
Coding Flowchart:
So our sonar display algorithms shown as the following flowchart.
First we need to create three variables for later use, which are degree, distance and raw.
Since the Sonar display panel is using pen feature to draw out, we set the pen size to 2 and shade to 100. The degree variable will be altered from '-90' to '90', we initiate the degree to '-90'.
We repeat the drawing process 180 times, each time in the loop rotate the sensor by one degree, use green pen to draw out the frame.
Then we use a digital filter to handle the signal from ultrasonic sensor, this way we can regulate stable filtered values from ultrasonic sensor.
Set the variable distance to the filtered value, use red pen to draw distance within the range of 250 (Radius). In the end of loop, increase the degree by one degree. The block codes end here and the sonar system will rotate for one cycle.
Step 4: Enjoy Your Very Own SonarTry this fun project and share with us!
Comments
Please log in or sign up to comment.