The purpose of this project is to build an obstacle avoidance robot without further knowledge of Arduino programming. Let's get rid of Arduino coding, learn and make an obstacle avoidance robot by using Scratch3.0 based software within two hours.
This project is a perfect fit for beginners. If you are interested in fun projects, but lack of programming skills, let's start it from here now!Parts
Software you need to download
- The Kittenblock v1.24 (based on Scratch3.0)
Hardware Bill of Materials
- KittenBot Anodized Aluminum Chassis
- Rubber wheel with Motor Hub
- KittenBot Rosbot Baseboard
- Ultrasonic Sensor and Adapter
- 9g Servo
- 2x DC motors
- KittenBot ESP8266 Wifi module (Optional)
- Battery pack with AA batteries or a 9V Battery
Attach your dc motors to the sides of chassis, plug the rubber wheel to motors.
Mount the 9g servo to chassis, then plug adapter to the servo. Lastly, mount your Robot Baseboard onto the chassis.Step 2: Assemble the Ultrasonic sensor
After setting up the robot, it's time to match Ultrasonic sensor to the adapter. Put tapping screws into the shaft in order to fasten adapter to the 9g servo.
Turn the Ultrasonic sensor very gently all the way in one direction, then to the other direction to figure out the middle point. Once you think you have it, make sure your Ultrasonic sensor is looking straight ahead.Step 3: Wiring
Next, you can hook up those wires to the baseboard.
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
- GND to GND
- Pin1 to D2
For this robot the left motor goes to the "A" channel. This leaves the right motor goes to 'B' channel. The black wire and the red wire each is in the first and second terminal, which indicate as "A+" and "A-".
- Left Motor Black wire to A+
- Left Motor Red wire to A-
- Right Motor Black wire to B+
- Right Motor Red wire to B-
If your robot is going backward, reverse motors' wiring to A-A+ and B-B+.Step 4: The WiFi module (optional)
Commonly, we use Micro-USB cable to make a connection. If you need more open space for testing, there is another way to communicate mainboard with software. You can make a WiFi connection by using KittenBot ESP8266 WiFi module.
Once plug in the WiFi module and give power to the board, connect your WiFi network to a hotspot starts with "ESP_".
Open up the software, select "ESP_" then hit yes.Coding
Upon using the KittenBlock software, 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.Step 1
First, create a variable “distance" under data section.Step 2
Next, you may want to receive Ultrasonic sensor signal as in distance. Since Ultrasonic sensor wire connected to D2, put 2 in the port of trig and echo.Step 3
The robot needs to check the surrounding for avoiding obstacle. Turn the Ultrasonic sensor in degrees as you set.Step 4
Now you get to the DC motor parts. The logic is when the distance is less than a value, stop the robot and make a sharp right turn, you can even back off a little bit in case the momentum drives robot too far.Step 5
Look through the codes, a simple multithreading is used to control servo's rotation, get the data from ultrasonic sensor and drive the DC motors in the same time.Step 6
When the logic is set, click the green flag to execute all the blocks. Try to modify each parameter to get the best performance out of your robot.
If you want to see what you have done in terms of Arduino codes. Open Arduino panel then hit "Translate" to get the complete Arduino codes.