Ks0071 keyestudio Mini Tank Robot: Difference between revisions

From Keyestudio Wiki
Jump to navigation Jump to search
 
(47 intermediate revisions by the same user not shown)
Line 4: Line 4:


==Introduction==
==Introduction==
Mini tank robot is a learning application development system of microcontroller based on Arduino. 
Mini tank robot is a learning application development system of microcontroller based on Arduino. 
It has functions such as ultrasonic obstacle avoidance, Bluetooth remotecontrol. This kitcontains many interesting programs.
It has functions such as ultrasonic obstacle avoidance, bluetooth remotecontrol. This kit contains many interesting programs.
 It can also be expanded with external circuit modules to haveother functions. This kit is designed to help you interestingly learn Arduino
It can also be expanded with external circuit modules to have further functions. This kit is designed to help you interestingly learn Arduino
You can learn Arduino MCU development ability while having fun.
You can learn Arduino MCU development ability while having fun.


==Parameters==
==Parameters==
1. Motor parameters: 6V, 150rpm/min <br>
1. Motor parameters: 6V, 150rpm/min <br>
2. Use L298P driver module for motor control.<br>
2. Use L298P driver module for motor control.<br>
Line 19: Line 17:


==Component List==
==Component List==
 
<br>[[File:QQ图片20210903173440.png|500px|frameless|thumb]]<br>
1. keyestudio UNO R3 controller * 1<br>
<br>[[File:QQ图片20210903173441.png|500px|frameless|thumb]]<br>
2. keyestudio L298P shield * 1<br>
<br>[[File:QQ图片20210903173.png|500px|frameless|thumb]]<br>
3. keyestudio V5 sensor shield * 1<br>
<br>[[File:QQ图片2021090317354.png|500px|frameless|thumb]]<br>
4. HC-SR04 ultrasonic sensor module * 1<br>
<br>[[File:QQ图片202109031735.png|500px|frameless|thumb]]<br>
5. keyestudio Bluetooth Module (HC-06) * 1<br>
<br>[[File:QQ图片20210903173516.png|500px|frameless|thumb]]<br>
6. Plastic platform (PC) * 1<br>
<br>[[File:QQ图片2021090317.png|500px|frameless|thumb]]<br>
7. Servo motor * 1<br>
8. Transparent Acrylic board * 1<br>
9. Metal holder * 4<br>
10. Tank driver wheel * 2<br>
11. Tank load-bearing wheel * 2<br>
12. Caterpillar band * 2<br>
13. Metal motor * 2<br>
14. Copper coupler * 2<br>
15. 18650 2-cell battery case * 1<br>
16. USB cable (1m) * 1<br>
17. Copper bush * 2<br>
18. Flange bearing * 4<br>
19. Hexagon copper bush (M3*10MM) * 4<br>
20. Hexagon copper bush (M3*45MM) * 4<br>
21. Round Screw (M3*6MM) * 10<br>
22. Round Screw (M4*35MM) * 4<br>
23. Inner hexagon screw (M3*8MM) * 10<br>
24. Inner hexagon screw (M3*20MM) * 6<br>
25. Inner hexagon screw (M3*25MM) * 6<br>
26. Inner hexagon screw (M4*10MM) * 6<br>
27. Inner hexagon screw (M4*50MM) * 2<br>
28. M3 Nut * 6<br>
29. M4 self-locking nut * 2<br>
30. M4 nut * 15<br>
31. Connector wire (150mm, black) * 2<br>
32. Connector wire (150mm, red) * 2<br>
33. F-F Dupont wire (20CM, 4Pin) * 1<br>
34. Supporting part (27*27*16MM, blue) * 2<br>
35. Winding wire (12CM) * 1<br>
 
* Self-prepare part<br>
18650 rechargeable battery * 2<br>
18650 charger * 1<br>


==Application of Arduino==
==Application of Arduino==
<br>[[File:712.png|500px|frameless|thumb]]<br>
<br>[[File:712.png|500px|frameless|thumb]]<br>


===Introduction===
===Introduction===
What’s Arduino?<br>
What’s Arduino?<br>
Arduino is an open-source hardware project platform. This platform includes a circuit board with simple I/O function and program development environment software. It can be used to develop interactive products. For example, it can read signals of multiple switches and sensors, and control light, servo motor and other various physical devices. It’s widely applied in robot field.
Arduino is an open-source hardware project platform. This platform includes a circuit board with simple I/O function and program development environment software. It can be used to develop interactive products. For example, it can read signals of multiple switches and sensors, and control light, servo motor and other various physical devices. It’s widely applied in robot field.


===Arduino installation and program upload:===
===Arduino installation and program upload:===
First, download the Arduino development software, click below hyperlink:<br>  
First, download the Arduino development software, click below hyperlink:<br>  
[http://183.6.240.129/7326097.s21d-7.faiusrd.com/0/ABUIABAAGAAgx72stAUomOnzwAQ?f=arduino-1.5.6-r2-windows.rar&v=1451957958&wsiphost=local arduino-1.5.6-r2-windows.rar]<br>
[http://183.6.240.129/7326097.s21d-7.faiusrd.com/0/ABUIABAAGAAgx72stAUomOnzwAQ?f=arduino-1.5.6-r2-windows.rar&v=1451957958&wsiphost=local arduino-1.5.6-r2-windows.rar]<br>
Downloaded file is a arduino-1.5.6-r2-windows.zip compressed folder, unzip it to your hard drive.<br>
Downloaded file is a arduino-1.5.6-r2-windows.zip compressed folder, unzip it to your hard drive.<br>
Double click Arduino-1.5.6 .exe. Click “I agree”;<br>
Double click Arduino-1.5.6 .exe.   Click “I agree”;


<br>[[File:713.png|500px|frameless|thumb]]<br>
<br>[[File:713.png|500px|frameless|thumb]]<br>
Line 90: Line 52:
<br>[[File:716.png|500px|frameless|thumb]]<br>
<br>[[File:716.png|500px|frameless|thumb]]<br>


Below is how Arduino 1.5.6 looks like.  
Below figure is what Arduino 1.5.6 looks like.  


<br>[[File:717.png|500px|frameless|thumb]]<br>
<br>[[File:717.png|500px|frameless|thumb]]<br>
Line 96: Line 58:
'''Next, let’s install Arduino driver.''' <br>
'''Next, let’s install Arduino driver.''' <br>
For different operating system, there may be slight difference in installation method. Below is an example in WIN 7.<br>
For different operating system, there may be slight difference in installation method. Below is an example in WIN 7.<br>
When you connect Arduino Uno to your computer the first time, right click “Computer” —>  “Properties”—> “Device manager”, you can see “Unknown devices”. <br>
When you connect Arduino Uno to your computer at the first time, right click “Computer” —>  “Properties”—> “Device manager”, you can see “Unknown devices”. <br>


<br>[[File:718.png|500px|frameless|thumb]]<br>
<br>[[File:718.png|500px|frameless|thumb]]<br>
Line 120: Line 82:
<br>[[File:7113.png|500px|frameless|thumb]]<br>
<br>[[File:7113.png|500px|frameless|thumb]]<br>


After driver is installed, go to “Device manager” again. Right click “Computer” —>  “Properties”—> “Device manager”, you can see UNO device as below figure shows, also the Com port info.   
After driver is installed, go to “Device manager” again. Right click “Computer” —>  “Properties”—> “Device manager”, you can see UNO device as below figure shows, also with the Com port info.   


<br>[[File:7114.png|500px|frameless|thumb]]<br>
<br>[[File:7114.png|500px|frameless|thumb]]<br>


Following is a sketch uploading example called “Hello World!”. <br>
Following is a sketch uploading example called “Hello World!”. <br>
First, open Arduino IDE. In this example sketch, we program Arduino to display “Hello World!” in serial monitor when it receives a specific character string “R”; also the on-board D13 LED will blink once each time it receives “R”.<br>
First, open Arduino IDE. In this example sketch, we program Arduino to display “Hello World!” on serial monitor when it receives a specific character string “R”; also the on-board D13 LED will blink once each time it receives “R”.<br>
First, set up board; In “Tools”, select “Arduino Uno”. <br>
First, set up board; In “Tools”, select “Arduino Uno”. <br>


Line 146: Line 108:
<br>[[File:7122.png|500px|frameless|thumb]]<br>
<br>[[File:7122.png|500px|frameless|thumb]]<br>


Congratulations! Your first sketch uploading is a success!
Congratulations! Your first sketch uploading is successful!
 
== Installation Method ==
 
1. Attach the supporting part to the metal holder with a inner hexagon screw.
 
 
<br>[[Image:0071==1.png|800px|frameless]]<br>
 
 
Then add a nut to fix the screw.
 
<br>[[File:0071==2.png|800px|frameless]]<br>
 
2.Plug a copper coupler into a metal motor;
 
<br>[[Image:0071==3.png|800px|frameless]]<br>
 
<br>[[Image:0071==4.png|800px|frameless]]<br>
 
Then, reinforce them with a screwdriver.
 
<br>[[Image:0071==5.png|800px|frameless]]<br>
 
3.Fix the metal motor to the metal holder with two inner hexagon screws.
 
<br>[[Image:0071==6.png|800px|frameless]]<br>
 
4. Plug a tank driver wheel into the metal motor and reinforce them with an inner hexagon screw.
 
<br>[[Image:QQ图片20210906103449.png|800px|frameless]]<br>
 
5. The tank load-bearing wheel is bolted to one screw and a copper bush.
 
<br>[[Image:QQ图片20210906103554.png|800px|frameless]]<br>
 
Then fix them with a flange bearing.
 
<br>[[Image:QQ图片20210906103706.png|800px|frameless]]<br>
 
6.Put the tank driver wheel through a screw hole of the metal holder and the load-bearing wheel right into the caterpillar.
 
<br>[[Image:QQ图片20210906103813.png|800px|frameless]]<br>
 
Next screw a flange bearing to fix the metal holder and the wheel.
 
<br>[[Image:QQ图片20210906103814.png|800px|frameless]]<br>
 
Then put a nut upon the flange bearing to reinforce.
 
<br>[[Image:QQ图片20210906104635.png|800px|frameless]]<br>
 
Finally combine the left part with the right part together.
 
<br>[[Image:QQ图片20210906104636.png|800px|frameless]]<br>
 
7.Attach the battery case to another metal holder with two flat head screws, using two nuts to fix them.
 
<br>[[Image:0071==7.png|800px|frameless]]<br>
 
8. Fix four inner hexagon screws to the metal holder using 4 nuts.
 
<br>[[Image:0071==18.png|800px|frameless]]<br>
 
9. The battery is bolted to the supporting part with four nuts.
 
<br>[[Image:0071==19.png|800px|frameless]]<br>
 
10.Attach another metal holder to the four screws and then reinforce them with four nuts.
 
<br>[[Image:0071==20.png|800px|frameless]]<br>
 
11.Plug four inner hexagon screws through the supporting part.
 
<br>[[Image:0071==21.png|800px|frameless]]<br>
 
Then screw 4 copper bushes to the four hexagon screws.
 
<br>[[Image:0071==22.png|800px|frameless]]<br>
 
12.Screw 8 copper bushes upon a acrylic board using 8 inner hexagon screws.
 
<br>[[Image:0071==8.png|800px|frameless]]<br>
 
13.The acrylic board is bolted to the four copper bushes with 4 hexagon screws.
 
<br>[[Image:0071==23.png|800px|frameless]]<br>
 
14. Cut the white cross to fit the size of the black cross and the attach the white one to the black one.
 
<br>[[Image:0071==24.png|800px|frameless]]<br>
 
Then fix the white cross with four tapping screws.
<br>[[Image:0071==25.png|800px|frameless]]<br>
 
15.Put the blue platform upon the cross,
 
<br>[[Image:QQ图片20210906112138.png|800px|frameless]]<br>
 
Then fix the platform using a tapping screw.
 
<br>[[Image:0071==9.png|800px|frameless]]<br>
 
16. Attach the two holder together, and then fix them with two tapping screws.
 
<br>[[Image:0071==10.png|800px|frameless]]<br>
<br>[[Image:0071==11.png|800px|frameless]]<br>
 
17.The whole platform is bolted to four short copper bushes using four inner hexagon screws.
 
<br>[[Image:0071==12.png|800px|frameless]]<br>
 
18.Tie the ultrasonic sensor up with the black holder using two pieces of ribbon.
 
<br>[[Image:0071==13.png|800px|frameless]]<br>
 
19.Attach the REV4 controller to the other four short copper bushes using four inner hexagon screws.
<br>[[Image:0071==14.png|800px|frameless]]<br>
 
20. Plug the L298P shield into the controller;
<br>[[Image:0071==15.png|800px|frameless]]<br>
 
Next plug the V5 sensor shield into the L298P shield;
<br>[[Image:0071==16.png|800px|frameless]]<br>
 
Finally plug the bluetooth into the serial ports on the V5 shield.
<br>[[Image:0071==17.png|800px|frameless]]<br>


==Project Details==
==Project Details==


===Project 1: Ultrasonic Sensor===
===Project 1: Ultrasonic Sensor===
<br>[[File:aa.png|500px|frameless|thumb]]<br>
<br>[[File:aa.png|500px|frameless|thumb]]<br>


'''Introduction'''
'''Introduction'''<br>
 
The HC-SR04 Ultrasonic Sensor is a very affordable proximity distance sensor that has been used mainly for object avoidance in various robotics projects. It essentially gives your Arduino eyes spacial awareness and can prevent your robot from crashing or falling off a table. It has also been used in turret applications, water level sensing, and even as a parking sensor. This simple project will use the HC-SR04 sensor with an Arduino and a Processing sketch to provide a neat little interactive display on your computer screen.
The HC-SR04 Ultrasonic Sensor is a very affordable proximity distance sensor that has been used mainly for object avoidance in various robotics projects. It essentially gives your Arduino eyes spacial awareness and can prevent your robot from crashing or falling off a table. It has also been used in turret applications, water level sensing, and even as a parking sensor. This simple project will use the HC-SR04 sensor with an Arduino and a Processing sketch to provide a neat little interactive display on your computer screen.
<br>[[File:bb.png|500px|frameless|thumb]]<br>
<br>[[File:bb.png|500px|frameless|thumb]]<br>


'''Specification'''
'''Specification'''<br>
 
Working Voltage: DC 5V<br>
Working Voltage: DC 5V<br>
Working Current: 15mA<br>
Working Current: 15mA<br>
Line 171: Line 255:
Echo Output Signal Input TTL lever signal and the range in proportion <br>
Echo Output Signal Input TTL lever signal and the range in proportion <br>


 
'''Connection Diagram'''<br>
'''Connection Diagram'''
 
<br>[[File:cc.png|500px|frameless|thumb]]<br>
<br>[[File:cc.png|500px|frameless|thumb]]<br>
<br>[[File:dd.png|500px|frameless|thumb]]<br>
<br>[[File:dd.png|500px|frameless|thumb]]<br>
<br>[[File:ee.png|500px|frameless|thumb]]<br>
<br>[[File:ee.png|500px|frameless|thumb]]<br>


 
'''Sample Code'''<br>
'''Sample Code'''
Wiring Method:<br>
 
VCC to Arduino 5v <br>
VCC to Arduino 5v <br>
GND to Arduino GND<br>
GND to Arduino GND<br>
Echo to Arduino pin 4<br>
Echo to Arduino pin 4<br>
Trig to Arduino pin 5<br>  
Trig to Arduino pin 5<br>
<pre>
<pre>
#define echoPin 4 // Echo Pin
#define echoPin 4 // Echo Pin
#define trigPin 5 // Trigger Pin
#define trigPin 5 // Trigger Pin
Line 236: Line 315:
</pre>
</pre>


'''Result'''
'''Result'''<br>
 
After connection and uploading, when ultrasonic sensor senses obstacle within sensing area, it is measuring the distance between itself and obstacle and the value of distance is displayed on serial monitor as shown in below figure.
After connection and uploading, when ultrasonic sensor senses obstacle within sensing area, it is measuring the distance between itself and obstacle and the value of distance is displayed on serial monitor as shown in bellow figure.
 
<br>[[File:ff.png|500px|frameless|thumb]]<br>
<br>[[File:ff.png|500px|frameless|thumb]]<br>




=== '''Project 2: Bluetooth Module'''===  
=== '''Project 2: Bluetooth Module'''===  
 
[[File:ks0071 2-1.png|thumb]]
<br>[[File:ks0071 2-1.png|500px|frameless|thumb]]<br>


'''Introduction'''<br>
'''Introduction'''<br>
Line 261: Line 336:
Safety Feature: Authentication and encryption<br>
Safety Feature: Authentication and encryption<br>
Supported Configuration: Bluetooth serial port (major and minor)<br>
Supported Configuration: Bluetooth serial port (major and minor)<br>
Supply Voltage: +3.3 VDC 50mA<br>
Supply Voltage: 5V DC 50mA<br>
Operating Temperature: -20 to 55℃<br>
Operating Temperature: -20 to 55℃<br>
<span style=color:red>Note: Before uploading test code, we can’t insert Bluetooth module, otherwise the program will fail to be uploaded. After uploading test code successfully, connect Bluetooth and Bluetooth module , pair and connect APP.</span>


'''Connection Diagram'''<br>
'''Connection Diagram'''<br>
<br>[[File:gg.png|500px|frameless|thumb]]<br>
<br>[[File:gg.png|500px|frameless|thumb]]<br>


'''Sample Code'''<br>
'''Sample Code'''<br>
<pre>
<pre>
int val;  
int val;  
Line 291: Line 365:


'''Result'''<br>
'''Result'''<br>
After powered up, power indicator D1 is on, and LED on Bluetooth module is blinking; open Bluetooth on mobile phone, pair them, input 1234, and finish pairing as shown in Figure 1 ; open APP—Bluetooth serial communication assistant, connect it to Bluetooth, select normal mode, complete connection, and LED on Bluetooth module is on as shown in Figure 2; input an “a” in the assistant, and display “keyesdudio” in it as shown in Figure 3.


After power-on, power indicator D1 is on, and LED on Bluetooth module is blinking; open Bluetooth on mobile phone, pair them, input 1234, and finish pairing as shown in Figure 1 ; open APP—Bluetooth serial communication assistant, connect it to Bluetooth, select normal mode, complete connection, and LED on Bluetooth module is on as shown in Figure 2; input an “a” in the assistant, and display “keyesdudio” in it as shown in Figure 3.
Figure 1 - - - - -  - - - - - - -  Figure 2   - - - - - - - -  - - - - -  Figure 3
 
Figure 1
 
<br>[[File:hh.png|500px|frameless|thumb]]<br>
 
Figure 2
 
<br>[[File:ii.png|500px|frameless|thumb]]<br>
 
Figure 3
 
<br>[[File:jj.png|500px|frameless|thumb]]<br>
 
 
 


=== '''Project 3: Obstacle-avoidance Tank '''===
<br>[[File:Ks0071 2-5.png|500px|frameless|thumb]]  [[File:ii.png|500px|frameless|thumb]]  [[File:Ks0071 2-6.png|500px|frameless|thumb]]<br>


=== '''Project 3: Obstacle Avoidance Tank '''===
<br>[[File:71.png|500px|frameless|thumb]]<br>
<br>[[File:71.png|500px|frameless|thumb]]<br>


'''Introduction'''<br>
'''Introduction'''<br>
This project is a simple obstacle avoidance tank robot system based on Arduino, including the software and hardware design. The controller part is a UNO board. Ultrasonic sensor and servo motors are used to detect whether there are obstacles ahead, and feedback the signal to UNO. UNO will analyze the signal to determine and control the motors movement to adjust Tank moving direction. Therefore the tank robot can automatically avoid obstacles.
This project is a simple obstacle avoidance tank robot system based on Arduino, including the software and hardware design. The controller part is a UNO board. Ultrasonic sensor and servo motors are used to detect whether there are obstacles ahead, and feedback the signal to UNO. UNO will analyze the signal to determine and control the motors movement to adjust Tank moving direction. Therefore the tank robot can automatically avoid obstacles.


'''Working Principle'''<br>
'''Working Principle'''<br>
Ultrasonic ranging: the controller sends out a a high level signal of more than 10μs, when the output pin receives the high level signal, the timer will be on; when the signal changes to low level, we can read the time period of the timer, which is the time used for this ultrasonic wave transceiving. Together with its transmission speed, we can calculate the distance.
Ultrasonic ranging: the controller sends out a a high level signal of more than 10μs, when the output pin receives the high level signal, the timer will be on; when the signal changes to low level, we can read the time period of the timer, which is the time used for this ultrasonic wave transceiving. Together with its transmission speed, we can calculate the distance.<br>
 
After we use the ultrasonic sensor to detect the distance from an obstacle, we can control the movement of the Tank according to the data.<br>
After we use the ultrasonic sensor to detect the distance from an obstacle, we can control the movement of the Tank according to the data.
    
    
If the distance from the obstacle is < 10cm, the Tank moves backward; if the distance is >=25cm, the Tank moves forward; if the distance is <25cm, we control the movement of the servo motors to measure the distance of the left and right. If both the distance are <10cm, the Tank moves backward; if the distance are both >= 10cm, and distance on the left is more than the distance on the right, the Tank moves to the left; if distance on the left is <= the distance on the right, the Tank moves to the right.  
If the distance from the obstacle is < 10cm, the Tank moves backward; if the distance is >=25cm, the Tank moves forward; if the distance is <25cm, we control the movement of the servo motors to measure the distance of the left and right. If both the distance are <10cm, the Tank moves backward; if the distance are both >= 10cm, and distance on the left is more than the distance on the right, the Tank moves to the left; if distance on the left is <= the distance on the right, the Tank moves to the right. <br>


'''Schematic and Connection Diagram'''<br>
'''Schematic and Connection Diagram'''<br>
 
<br>[[File:ks0071 1-2.png|500px|frameless|thumb]]<br>
<br>[[File:ks0071 3-1.png|500px|frameless|thumb]]<br>
<br>[[File:72.png|500px|frameless|thumb]]<br>
<br>[[File:72.png|500px|frameless|thumb]]<br>


Line 512: Line 570:
'''Result'''<br>
'''Result'''<br>
After power-on, the car runs and will avoid obstacle automatically when catching obstacle.
After power-on, the car runs and will avoid obstacle automatically when catching obstacle.




=== '''Project 4: Bluetooth Control Tank Robot '''===  
=== '''Project 4: Bluetooth Control Tank Robot '''===  
<br>[[File:73.png|500px|frameless|thumb]]<br>
<br>[[File:73.png|500px|frameless|thumb]]<br>


'''Introduction'''<br>
'''Introduction'''<br>
This project is a tank robot system based on Bluetooth communication, including software and hardware design. The controller part is a UNO board. A Bluetooth module is used to receive the Bluetooth signal from the cellphone and feedback the signal to the UNO. UNO will analyze the signal to determine and control the motors movement to adjust car moving direction. Therefore the tank robot can be controlled by cellphone.
This project is a tank robot system based on Bluetooth communication, including software and hardware design. The controller part is a UNO board. A Bluetooth module is used to receive the Bluetooth signal from the cellphone and feedback the signal to the UNO. UNO will analyze the signal to determine and control the motors movement to adjust car moving direction. Therefore the tank robot can be controlled by cellphone.


'''Working Principle'''<br>
'''Working Principle'''<br>
1. The Bluetooth module is connected to UNO; the module communicates with cell phone through a Bluetooth APP.  
1. The Bluetooth module is connected to UNO; the module communicates with cell phone through a Bluetooth APP. <br>
 
2. The Bluetooth APP on the cell phone will pass information of “U”“D”“L”“R”“S” to the Bluetooth module. <br>
2. The Bluetooth APP on the cell phone will pass information of “U”“D”“L”“R”“S” to the Bluetooth module.  
3. The Bluetooth module will pass the information to the UNO, so the UNO can determine car movement according to the information received.<br>
 
4. When the UNO receives a “U”, the car goes straight forward; when it receives a “D”, the car goes backward; “L” for turning left; “R” for turning right; and “S” for stop.<br>
3. The Bluetooth module will pass the information to the UNO, so the UNO can determine car movement according to the information received.
 
4. When the UNO receives a “U”, the car goes straight forward; when it receives a “D”, the car goes backward; “L” for turning left; “R” for turning right; and “S” for stop.


'''Bluetooth Usage'''<br>
'''Bluetooth Usage'''<br>
Connect main board +5V to Bluetooth VCC, GND to Bluetooth GND, TX to Bluetooth RX and RX to Bluetooth TX.
Connect main board +5V to Bluetooth VCC, GND to Bluetooth GND, TX to Bluetooth RX and RX to Bluetooth TX.<br>
Remember to open the Bluetooth on your phone; when you open the Bluetooth APP, it will remind you.Pair up Bluetooth device on your phone, search and pair. <br>
Remember to open the Bluetooth on your phone; when you open the Bluetooth APP, it will remind you.Pair up Bluetooth device on your phone, search and pair.  
Pair up device, PIN No. is 1234. <br>
 
Open Bluetooth APP and pair up Bluetooth device. After it’s paired, the Bluetooth module can communicate with cell phone. <br>
Pair up device, PIN No. is 1234.  


Open Bluetooth APP and pair up Bluetooth device. After it’s paired, the Bluetooth module can communicate with cell phone.  
<span style=color:red>Note: Before uploading test code, we can’t insert Bluetooth module, otherwise the program will fail to be uploaded. After uploading test code successfully, connect Bluetooth and Bluetooth module , pair and connect APP.</span>


'''Schematic and Connection Diagram'''<br>
'''Schematic and Connection Diagram'''<br>
 
<br>[[File:ks0071 2-3.png|500px|frameless|thumb]]<br>
<br>[[File:ks0071 3-1.png|500px|frameless|thumb]]<br>
<br>[[File:74.png|500px|frameless|thumb]]<br>
<br>[[File:74.png|500px|frameless|thumb]]<br>


Line 615: Line 664:
Connected to Bluetooth APP, the movement of the car is controlled by the APP.
Connected to Bluetooth APP, the movement of the car is controlled by the APP.


 
=== '''Project 5: Ultrasonic Ranging Tank Robot '''===  
 
<br>[[File:75.png|500px|frameless|thumb]]<br>
 
=== '''Project 5: ltrasonic Ranging Tank Robot '''===  
 
<br>[[File:73.png|500px|frameless|thumb]]<br>


'''Introduction'''<br>
'''Introduction'''<br>
In project 3, we use the ultrasonic sensor module for the tank to realize obstacle avoidance function. In project 4, we use a HC-06 Bluetooth module for the tank, so the tank can be controlled form a cellphone terminal.
In project 3, we use the ultrasonic sensor module for the tank to realize obstacle avoidance function. In project 4, we use a HC-06 Bluetooth module for the tank, so the tank can be controlled form a cellphone terminal.<br>
   
   
This project is based on project 3 and project 4. Here, we apply echo sounding method for the ranging. The trig end of ultrasonic sensor will launch ultrasonic wave in a specific direction. At the same time, the timer begins to count; when the ultrasonic wave encounters an obstacle, it’s reflected back; when the echo end receives the signal, the timer stops the count. With the traveling speed of the wave and the traveling time, we can calculate the distance between the launching point and the obstacle.  
This project is based on project 3 and project 4. Here, we apply echo sounding method for the ranging. The trig end of ultrasonic sensor will launch ultrasonic wave in a specific direction. At the same time, the timer begins to count; when the ultrasonic wave encounters an obstacle, it’s reflected back; when the echo end receives the signal, the timer stops the count. With the traveling speed of the wave and the traveling time, we can calculate the distance between the launching point and the obstacle. <br>
   
   
Also,we will use the HC-06 Bluetooth module for the Tank to communicate with the terminal. The tank will send the measured distance to the terminal, so we can see clearly the distance between the tank and the obstacle while the tank is on.  
Also,we will use the HC-06 Bluetooth module for the Tank to communicate with the terminal. The tank will send the measured distance to the terminal, so we can clearly  see the distance between the tank and the obstacle while the tank is moving. <br>
 
This robot can be used in outdoor exploration or terrain exploration in a confined space.  <br>
This robot can be used in outdoor exploration or terrain exploration in a confined space.   
 




'''Schematic and Connection Diagram'''<br>
'''Schematic and Connection Diagram'''<br>
<br>[[File:ks0071 3-1.png|500px|frameless|thumb]]<br>
<br>[[File:ks0071 3-1.png|500px|frameless|thumb]]<br>
<br>[[File:74.png|500px|frameless|thumb]]<br>
<br>[[File:76.png|500px|frameless|thumb]]<br>


'''Sample Code'''<br>
'''Sample Code'''<br>
Line 825: Line 867:
Connected to Bluetooth APP, the movement of the car is controlled by the APP.
Connected to Bluetooth APP, the movement of the car is controlled by the APP.


==Video==
==Resources ==
Install video:http://www.keyestudio.com/wp/2016/05/ks0071-keyestudio-mini-tank-robot-smart-car/
 
Demonstration Video:http://www.keyestudio.com/wp/2016/08/ks0071-keyestudio-mini-tank-robot-demonstration-video/
'''Video''' <br>
http://video.keyestudio.com/KS0071/
 
'''Download APP, Library, and code:'''<br>
 
https://fs.keyestudio.com/KS0071
 
<br>
 
==Buy from ==
'''Official Website'''
 
http://www.keyestudio.com/keyes-mini-tank-robot.html
 
'''Amazon Store'''
 
https://www.amazon.com/Keyestudio-Bluetooth-Robot-Aluminum-Arduino/dp/B01F38JY7I/
 
 


[[category:Smart Car]]
[[category:Smart Car]]

Latest revision as of 12:09, 6 September 2021

keyestudio Mini Tank Robot


thumb

Introduction

Mini tank robot is a learning application development system of microcontroller based on Arduino.  It has functions such as ultrasonic obstacle avoidance, bluetooth remotecontrol. This kit contains many interesting programs. It can also be expanded with external circuit modules to have further functions. This kit is designed to help you interestingly learn Arduino.  You can learn Arduino MCU development ability while having fun.

Parameters

1. Motor parameters: 6V, 150rpm/min 
2. Use L298P driver module for motor control.
3. Equipped with Ultrasonic module, can detect whether there are obstacles ahead, and the distance between the Tank robot and the obstacles to realize obstacle avoidance function.
4. Equipped with Bluetooth wireless module, can remotely control the robot after pairing with mobile phone Bluetooth.
5. Can be connected to external 7 ~ 12V power supply; with various sensor modules, it can realize various functions.

Component List


thumb

thumb

thumb

thumb

thumb

thumb

thumb

Application of Arduino


thumb

Introduction

What’s Arduino?
Arduino is an open-source hardware project platform. This platform includes a circuit board with simple I/O function and program development environment software. It can be used to develop interactive products. For example, it can read signals of multiple switches and sensors, and control light, servo motor and other various physical devices. It’s widely applied in robot field.

Arduino installation and program upload:

First, download the Arduino development software, click below hyperlink:
arduino-1.5.6-r2-windows.rar
Downloaded file is a arduino-1.5.6-r2-windows.zip compressed folder, unzip it to your hard drive.
Double click Arduino-1.5.6 .exe. Click “I agree”;


thumb

Click “Next”;


thumb

And then “Install”;


thumb

Wait for the installation to be completed, click close.


thumb

Below figure is what Arduino 1.5.6 looks like.


thumb

Next, let’s install Arduino driver.
For different operating system, there may be slight difference in installation method. Below is an example in WIN 7.
When you connect Arduino Uno to your computer at the first time, right click “Computer” —> “Properties”—> “Device manager”, you can see “Unknown devices”.


thumb

Click “Unknown devices”, select “Update Driver software”.


thumb

In this page, click “Browse my computer for driver software”.


thumb

Find the “drivers” file.


thumb

Click “Next”; select “Install this driver software anyway” to begin the installation.


thumb

Installation completed; click “Close”.


thumb

After driver is installed, go to “Device manager” again. Right click “Computer” —> “Properties”—> “Device manager”, you can see UNO device as below figure shows, also with the Com port info.


thumb

Following is a sketch uploading example called “Hello World!”.
First, open Arduino IDE. In this example sketch, we program Arduino to display “Hello World!” on serial monitor when it receives a specific character string “R”; also the on-board D13 LED will blink once each time it receives “R”.
First, set up board; In “Tools”, select “Arduino Uno”.


thumb

Next, set up COM port; In “Tools”, select “COM3”.


thumb

After selection, you can see indicated area is the same with settings in “Device manager”.


thumb

Copy the example sketch and paste it to the IDE; click “Verify thumb” to check compiling mistakes; click “Upload thumb” to upload the program to the board.


thumb

After uploading is done, open “serial monitorthumb ”; enter “R”; click “Send”, the serial monitor will display “Hello World!” and the D13 LED will blink once.


thumb

Congratulations! Your first sketch uploading is successful!

Installation Method

1. Attach the supporting part to the metal holder with a inner hexagon screw.



0071==1.png


Then add a nut to fix the screw.


0071==2.png

2.Plug a copper coupler into a metal motor;


0071==3.png


0071==4.png

Then, reinforce them with a screwdriver.


0071==5.png

3.Fix the metal motor to the metal holder with two inner hexagon screws.


0071==6.png

4. Plug a tank driver wheel into the metal motor and reinforce them with an inner hexagon screw.


QQ图片20210906103449.png

5. The tank load-bearing wheel is bolted to one screw and a copper bush.


QQ图片20210906103554.png

Then fix them with a flange bearing.


QQ图片20210906103706.png

6.Put the tank driver wheel through a screw hole of the metal holder and the load-bearing wheel right into the caterpillar.


QQ图片20210906103813.png

Next screw a flange bearing to fix the metal holder and the wheel.


QQ图片20210906103814.png

Then put a nut upon the flange bearing to reinforce.


QQ图片20210906104635.png

Finally combine the left part with the right part together.


QQ图片20210906104636.png

7.Attach the battery case to another metal holder with two flat head screws, using two nuts to fix them.


0071==7.png

8. Fix four inner hexagon screws to the metal holder using 4 nuts.


0071==18.png

9. The battery is bolted to the supporting part with four nuts.


0071==19.png

10.Attach another metal holder to the four screws and then reinforce them with four nuts.


0071==20.png

11.Plug four inner hexagon screws through the supporting part.


0071==21.png

Then screw 4 copper bushes to the four hexagon screws.


0071==22.png

12.Screw 8 copper bushes upon a acrylic board using 8 inner hexagon screws.


0071==8.png

13.The acrylic board is bolted to the four copper bushes with 4 hexagon screws.


0071==23.png

14. Cut the white cross to fit the size of the black cross and the attach the white one to the black one.


0071==24.png

Then fix the white cross with four tapping screws.
0071==25.png

15.Put the blue platform upon the cross,


QQ图片20210906112138.png

Then fix the platform using a tapping screw.


0071==9.png

16. Attach the two holder together, and then fix them with two tapping screws.


0071==10.png

0071==11.png

17.The whole platform is bolted to four short copper bushes using four inner hexagon screws.


0071==12.png

18.Tie the ultrasonic sensor up with the black holder using two pieces of ribbon.


0071==13.png

19.Attach the REV4 controller to the other four short copper bushes using four inner hexagon screws.
0071==14.png

20. Plug the L298P shield into the controller;
0071==15.png

Next plug the V5 sensor shield into the L298P shield;
0071==16.png

Finally plug the bluetooth into the serial ports on the V5 shield.
0071==17.png

Project Details

Project 1: Ultrasonic Sensor


thumb

Introduction
The HC-SR04 Ultrasonic Sensor is a very affordable proximity distance sensor that has been used mainly for object avoidance in various robotics projects. It essentially gives your Arduino eyes spacial awareness and can prevent your robot from crashing or falling off a table. It has also been used in turret applications, water level sensing, and even as a parking sensor. This simple project will use the HC-SR04 sensor with an Arduino and a Processing sketch to provide a neat little interactive display on your computer screen.
thumb

Specification
Working Voltage: DC 5V
Working Current: 15mA
Working Frequency: 40Hz
Max Range: 4m
Min Range: 2cm
Measuring Angle: 15 degree
Trigger Input Signal: 10µS TTL pulse
Echo Output Signal Input TTL lever signal and the range in proportion

Connection Diagram

thumb

thumb

thumb

Sample Code
Wiring Method:
VCC to Arduino 5v
GND to Arduino GND
Echo to Arduino pin 4
Trig to Arduino pin 5

#define echoPin 4 // Echo Pin
#define trigPin 5 // Trigger Pin
#define LEDPin 13 // Onboard LED
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance

void setup() {
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}

void loop() {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */ 
 digitalWrite(trigPin, LOW); 
 delayMicroseconds(2); 

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10); 
 
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 
 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;
 
 if (distance >= maximumRange || distance <= minimumRange){
 /* Send a negative number to computer and Turn LED ON 
 to indicate "out of range" */
 Serial.println("-1");
 digitalWrite(LEDPin, HIGH); 
 }
 else {
 /* Send the distance to the computer using Serial protocol, and
 turn LED OFF to indicate successful reading. */
 Serial.println(distance);
 digitalWrite(LEDPin, LOW); 
 }
 
 //Delay 50ms before next reading.
 delay(50);
}

Result
After connection and uploading, when ultrasonic sensor senses obstacle within sensing area, it is measuring the distance between itself and obstacle and the value of distance is displayed on serial monitor as shown in below figure.
thumb


Project 2: Bluetooth Module

Ks0071 2-1.png

Introduction
This Bluetooth module can easily achieve serial wireless data transmission. Its operating frequency is among the most popular 2.4GHz ISM frequency band (i.e. Industrial, scientific and medical). It adopts Bluetooth 2.1+EDR standard. In Bluetooth 2.1, signal transmit time of different devices stands at a 0.5 seconds interval so that the workload of bluetooth chip can be reduced substantially and more sleeping time can be saved for bluetooth. This module is set with serial interface, which is easy-to-use and simplifying overall design/development cycle.

Specification
Bluetooth Protocol: Bluetooth 2.1+ EDR standard
USB Protocol: USB v1.1/2.0
Operating Frequency: 2.4GHz ISM frequency band
Modulation Mode: Gauss frequency Shift Keying
Transmit Power: ≤ 4dBm, second stage
Sensitivity: ≤-84dBm at 0.1% Bit Error Rate
Transmission Speed: 2.1Mbps(Max)/160 kbps(Asynchronous); 1Mbps/1Mbps(Synchronous)
Safety Feature: Authentication and encryption
Supported Configuration: Bluetooth serial port (major and minor)
Supply Voltage: 5V DC 50mA
Operating Temperature: -20 to 55℃

Note: Before uploading test code, we can’t insert Bluetooth module, otherwise the program will fail to be uploaded. After uploading test code successfully, connect Bluetooth and Bluetooth module , pair and connect APP.

Connection Diagram

thumb

Sample Code

int val; 
int ledpin=13; 
void setup() 
{ 
Serial.begin(9600);
 pinMode(ledpin,OUTPUT); 
} void loop()
{ val=Serial.read(); 
if(val=='a')
 { 
digitalWrite(ledpin,HIGH); 
delay(250); 
digitalWrite(ledpin,LOW); 
delay(250);
 Serial.println("keyestudio");
}}

Result
After powered up, power indicator D1 is on, and LED on Bluetooth module is blinking; open Bluetooth on mobile phone, pair them, input 1234, and finish pairing as shown in Figure 1 ; open APP—Bluetooth serial communication assistant, connect it to Bluetooth, select normal mode, complete connection, and LED on Bluetooth module is on as shown in Figure 2; input an “a” in the assistant, and display “keyesdudio” in it as shown in Figure 3.

Figure 1 - - - - - - - - - - - - Figure 2 - - - - - - - - - - - - - Figure 3


thumb thumb thumb

Project 3: Obstacle Avoidance Tank


thumb

Introduction
This project is a simple obstacle avoidance tank robot system based on Arduino, including the software and hardware design. The controller part is a UNO board. Ultrasonic sensor and servo motors are used to detect whether there are obstacles ahead, and feedback the signal to UNO. UNO will analyze the signal to determine and control the motors movement to adjust Tank moving direction. Therefore the tank robot can automatically avoid obstacles.

Working Principle
Ultrasonic ranging: the controller sends out a a high level signal of more than 10μs, when the output pin receives the high level signal, the timer will be on; when the signal changes to low level, we can read the time period of the timer, which is the time used for this ultrasonic wave transceiving. Together with its transmission speed, we can calculate the distance.
After we use the ultrasonic sensor to detect the distance from an obstacle, we can control the movement of the Tank according to the data.

If the distance from the obstacle is < 10cm, the Tank moves backward; if the distance is >=25cm, the Tank moves forward; if the distance is <25cm, we control the movement of the servo motors to measure the distance of the left and right. If both the distance are <10cm, the Tank moves backward; if the distance are both >= 10cm, and distance on the left is more than the distance on the right, the Tank moves to the left; if distance on the left is <= the distance on the right, the Tank moves to the right.

Schematic and Connection Diagram

thumb

thumb

Sample Code

/*   
    L = Left 
    R = Right 
    F = forward 
    B = backward
*/
#include <Servo.h> 
int pinLB = 12;     // define pin 12 
int pinLF = 3;     // define pin 3 
int pinRB = 13;    // define pin 13 
int pinRF = 11;    // define pin 11 
////////////////////////////////
int inputPin = 4;    // define pin for sensor echo
int outputPin =5;    // define pin for sensor trig

int Fspeedd = 0;      // forward speed
int Rspeedd = 0;      // right speed
int Lspeedd = 0;      // left speed
int directionn = 0;   // forward=8 backward=2 left=4 right=6 
Servo myservo;        // set myservo
int delay_time = 250; // settling time after steering servo motor moving B
int Fgo = 8;         // Move F
int Rgo = 6;         // move to the R
int Lgo = 4;         // move to the L
int Bgo = 2;         // move B
void setup()
 {
  Serial.begin(9600);     // Define motor output pin 
  pinMode(pinLB,OUTPUT); // pin 12
  pinMode(pinLF,OUTPUT); // pin 3 (PWM)
  pinMode(pinRB,OUTPUT); // pin 13
  pinMode(pinRF,OUTPUT); // pin 11 (PWM) 
  pinMode(inputPin, INPUT);    // define input pin for sensor
  pinMode(outputPin, OUTPUT);  // define output pin for sensor   
  myservo.attach(9);    // Define servo motor output pin to D9 (PWM)
 }
void advance()     // move forward
    { 
    digitalWrite(pinLB,LOW);    // right wheel moves forward
digitalWrite(pinRB, LOW);  // left wheel moves forward
    analogWrite(pinLF,255);   
    analogWrite(pinRF,255);
    }
void stopp()         // stop 
    {
     digitalWrite(pinLB,HIGH);
     digitalWrite(pinRB,HIGH);
     analogWrite(pinLF,0);
     analogWrite(pinRF,0); 
    }
void right()        // turn right (single wheel)
    {
   digitalWrite(pinLB,HIGH);  // wheel on the left moves forward
   digitalWrite(pinRB,LOW); // wheel on the right moves backward
   analogWrite(pinLF, 255);
   analogWrite(pinRF,255);   
    }
void left()         // turn left (single wheel)
    {
   digitalWrite(pinLB,LOW);  // wheel on the left moves backward
   digitalWrite(pinRB,HIGH); // wheel on the right moves forward
   analogWrite(pinLF, 255);
   analogWrite(pinRF,255);  
    }
  
void back()          // move backward
    {
     digitalWrite(pinLB,HIGH);  // motor moves to left rear
     digitalWrite(pinRB,HIGH);  // motor moves to right rear
     analogWrite(pinLF,255);  
     analogWrite(pinRF,255);     
    }
void detection()        // measure 3 angles (0.90.179)
    {      
      int delay_time = 250;   // stabilizing time for servo motor after moving backward
      ask_pin_F();            // read the distance ahead
     if(Fspeedd < 10)         // if distance ahead is <10cm
      {
      stopp();               // clear data 
      delay(100);
      back();                // move backward for 0.2S
      delay(200);
      }       
      if(Fspeedd < 25)         // if distance ahead is <25cm
      {
        stopp();  
        delay(100);             // clear data 
        ask_pin_L();            // read distance on the left
        delay(delay_time);      // stabilizing time for servo motor
        ask_pin_R();            // read distance on the right  
        delay(delay_time);      // stabilizing time for servo motor  
        
        if(Lspeedd > Rspeedd)   // if distance on the left is >distance on the right
        {
          directionn = Lgo;      // move to the L
        }
        
        if(Lspeedd <= Rspeedd)   // if distance on the left is <= distance on the right
        {
         directionn = Rgo;      // move to the right
        } 
         if (Lspeedd < 10 && Rspeedd < 10)   // if distance on left and right are both <10cm
        {
         directionn = Bgo;      // move backward        
        }}
      else                      // if distance ahead is >25cm     
      {
        directionn = Fgo;        // move forward      
      }}    
void ask_pin_F()   // measure the distance ahead 
    {
      myservo.write(90);
      digitalWrite(outputPin, LOW);   // ultrasonic sensor transmit low level signal 2μs
      delayMicroseconds(2);
      digitalWrite(outputPin, HIGH);  // ultrasonic sensor transmit high level signal10μs, at least 10μs
      delayMicroseconds(10);
      digitalWrite(outputPin, LOW);    // keep transmitting low level signal
      float Fdistance = pulseIn(inputPin, HIGH);  // read the time in between
      Fdistance= Fdistance/5.8/10;       // convert time into distance (unit: cm) 
      Fspeedd = Fdistance;              // read the distance into Fspeedd
    }  
 void ask_pin_L()   // measure distance on the left 
    {
      myservo.write(5);
      delay(delay_time);
      digitalWrite(outputPin, LOW);   // ultrasonic sensor transmit low level signal 2μs
      delayMicroseconds(2);
      digitalWrite(outputPin, HIGH);  // ultrasonic sensor transmit high level signal10μs, at least 10μs
      delayMicroseconds(10);
      digitalWrite(outputPin, LOW);    // keep transmitting low level signal
      float Ldistance = pulseIn(inputPin, HIGH);  // read the time in between
      Ldistance= Ldistance/5.8/10;       // convert time into distance (unit: cm)
      Lspeedd = Ldistance;              // read the distance into Lspeedd
    }  
void ask_pin_R()   //  measure distance on the right 
    {
      myservo.write(177);
      delay(delay_time);
      digitalWrite(outputPin, LOW);   // ultrasonic sensor transmit low level signal 2μs
      delayMicroseconds(2);
      digitalWrite(outputPin, HIGH);  // ultrasonic sensor transmit high level signal10μs, at least 10μs
      delayMicroseconds(10);
      digitalWrite(outputPin, LOW);    // keep transmitting low level signal
      float Rdistance = pulseIn(inputPin, HIGH);  // read the time in between
      Rdistance= Rdistance/5.8/10;       // convert time into distance (unit: cm)
      Rspeedd = Rdistance;              // read the distance into Rspeedd
    }  
    void loop()
  {
    myservo.write(90);  // home set the servo motor, ready for next measurement
    detection();        // measure the angle and determine which direction to move   
   if(directionn == 2)  // if directionn= 2             
   {
     back(); 
     delay(800);                    //  go backward
     left() ;      
     delay(200);              // Move slightly to the left (to prevent stuck in dead end)
   }
   if(directionn == 6)           // if directionn = 6    
   {
     back();
     delay(100);  
     right();  
     delay(600);                 // turn right
   }
   if(directionn == 4)          // if directionn = 4    
   {  
     back(); 
     delay(600);      
     left(); 
     delay(600);                  // turn left
   }  
   if(directionn == 8)          // if directionn = 8      
   { 
    advance();                 // move forward  
    delay(100);  
   } }

Result
After power-on, the car runs and will avoid obstacle automatically when catching obstacle.


Project 4: Bluetooth Control Tank Robot


thumb

Introduction
This project is a tank robot system based on Bluetooth communication, including software and hardware design. The controller part is a UNO board. A Bluetooth module is used to receive the Bluetooth signal from the cellphone and feedback the signal to the UNO. UNO will analyze the signal to determine and control the motors movement to adjust car moving direction. Therefore the tank robot can be controlled by cellphone.

Working Principle
1. The Bluetooth module is connected to UNO; the module communicates with cell phone through a Bluetooth APP.
2. The Bluetooth APP on the cell phone will pass information of “U”“D”“L”“R”“S” to the Bluetooth module.
3. The Bluetooth module will pass the information to the UNO, so the UNO can determine car movement according to the information received.
4. When the UNO receives a “U”, the car goes straight forward; when it receives a “D”, the car goes backward; “L” for turning left; “R” for turning right; and “S” for stop.

Bluetooth Usage
Connect main board +5V to Bluetooth VCC, GND to Bluetooth GND, TX to Bluetooth RX and RX to Bluetooth TX.
Remember to open the Bluetooth on your phone; when you open the Bluetooth APP, it will remind you.Pair up Bluetooth device on your phone, search and pair.
Pair up device, PIN No. is 1234.
Open Bluetooth APP and pair up Bluetooth device. After it’s paired, the Bluetooth module can communicate with cell phone.

Note: Before uploading test code, we can’t insert Bluetooth module, otherwise the program will fail to be uploaded. After uploading test code successfully, connect Bluetooth and Bluetooth module , pair and connect APP.

Schematic and Connection Diagram

thumb

thumb

Sample Code

/*   
    L = Left 
    R = Right 
    F = forward 
    B = backward
*/
int pinLB = 12;     // define pin 12 
int pinLF = 3;     // define pin 3 
int pinRB = 13;    // define pin 13 
int pinRF = 11;    // define pin 11 
int val;
void setup()
 {
  Serial.begin(9600);     // define pin for motor output 
  pinMode(pinLB,OUTPUT); // pin 12
  pinMode(pinLF,OUTPUT); // pin 3 (PWM)
  pinMode(pinRB,OUTPUT); // pin 13
  pinMode(pinRF,OUTPUT); // pin 11 (PWM) 
 }
void advance()     // move forward
    { 
    digitalWrite(pinLB,LOW);    // right wheel moves forward
    digitalWrite(pinRB, LOW);  // left wheel moves forward
    analogWrite(pinLF,255);   
    analogWrite(pinRF,255);
    }
void stopp()         // stop
    {
     digitalWrite(pinLB,HIGH);
     digitalWrite(pinRB,HIGH);
     analogWrite(pinLF,0);
     analogWrite(pinRF,0); 
    }
void right()        // turn right (single wheel)
    {
   digitalWrite(pinLB,HIGH);  // left wheel moves forward
   digitalWrite(pinRB,LOW); // right wheel moves backward
   analogWrite(pinLF, 255);
   analogWrite(pinRF,255);   
    }
void left()         // turn left (single wheel)
{
   digitalWrite(pinLB,LOW);  // left wheel moves forward
   digitalWrite(pinRB,HIGH); // right wheel moves backward
   analogWrite(pinLF, 255);
   analogWrite(pinRF,255);  
    }
  void back()          // move backward
    {digitalWrite(pinLB,HIGH);  // motor moves to left rear
     digitalWrite(pinRB,HIGH);  // motor moves to right rear
     analogWrite(pinLF,255);  
     analogWrite(pinRF,255);     
    }
void loop()
    { val=Serial.read(); 
    if(val=='U')advance();
    if(val=='D')back();
    if(val=='L')left() ;
    if(val=='R')right();
if(val=='S')stopp();
}

Result
Connected to Bluetooth APP, the movement of the car is controlled by the APP.

Project 5: Ultrasonic Ranging Tank Robot


thumb

Introduction
In project 3, we use the ultrasonic sensor module for the tank to realize obstacle avoidance function. In project 4, we use a HC-06 Bluetooth module for the tank, so the tank can be controlled form a cellphone terminal.

This project is based on project 3 and project 4. Here, we apply echo sounding method for the ranging. The trig end of ultrasonic sensor will launch ultrasonic wave in a specific direction. At the same time, the timer begins to count; when the ultrasonic wave encounters an obstacle, it’s reflected back; when the echo end receives the signal, the timer stops the count. With the traveling speed of the wave and the traveling time, we can calculate the distance between the launching point and the obstacle.

Also,we will use the HC-06 Bluetooth module for the Tank to communicate with the terminal. The tank will send the measured distance to the terminal, so we can clearly see the distance between the tank and the obstacle while the tank is moving.
This robot can be used in outdoor exploration or terrain exploration in a confined space.


Schematic and Connection Diagram

thumb

thumb

Sample Code

/*   
    L = Left 
    R = Right 
    F = forward 
    B = backward
*/
#include <Servo.h> 
int pinLB = 12;     // define pin 12 
int pinLF = 3;     // define pin 3 
int pinRB = 13;    // define pin 13 
int pinRF = 11;    // define pin 11 
int inputPin = 4;    // define pin for sensor echo
int outputPin =5;    // define pin for sensor trig
int Fspeedd = 0;      // forward speed
int Rspeedd = 0;      // right speed
int Lspeedd = 0;      // left speed
int directionn = 0;   // forward=8 backward=2 left=4 right=6 
Servo myservo;        // set myservo
int delay_time = 250; // settling time after steering servo motor moving B
int Fgo = 8;         // Move F
int Rgo = 6;         // move to the R
int Lgo = 4;         // move to the L
int Bgo = 2;         // move B
void setup()
 {
  Serial.begin(9600);     // Define motor output pin 
  pinMode(pinLB,OUTPUT); // pin 12
  pinMode(pinLF,OUTPUT); // pin 3 (PWM)
  pinMode(pinRB,OUTPUT); // pin 13
  pinMode(pinRF,OUTPUT); // pin 11 (PWM) 
  pinMode(inputPin, INPUT);    // define input pin for sensor
  pinMode(outputPin, OUTPUT);  // define output pin for sensor   
  myservo.attach(9);    // Define servo motor output pin to D9 (PWM)
 }
void advance()     // move forward
    { 
    digitalWrite(pinLB,LOW);    // right wheel moves forward
digitalWrite(pinRB, LOW);  // left wheel moves forward
    analogWrite(pinLF,255);   
    analogWrite(pinRF,255);
    }
void stopp()         // stop 
    {
     digitalWrite(pinLB,HIGH);
     digitalWrite(pinRB,HIGH);
     analogWrite(pinLF,0);
     analogWrite(pinRF,0); 
    }
void right()        // turn right (single wheel)
    {
   digitalWrite(pinLB,HIGH);  // wheel on the left moves forward
   digitalWrite(pinRB,LOW); // wheel on the right moves backward
   analogWrite(pinLF, 255);
   analogWrite(pinRF,255);   
    }
void left()         // turn left (single wheel)
    {
   digitalWrite(pinLB,LOW);  // wheel on the left moves backward
   digitalWrite(pinRB,HIGH); // wheel on the right moves forward
   analogWrite(pinLF, 255);
   analogWrite(pinRF,255);  
    }
  
void back()          // move backward
    {
     digitalWrite(pinLB,HIGH);  // motor moves to left rear
     digitalWrite(pinRB,HIGH);  // motor moves to right rear
     analogWrite(pinLF,255);  
     analogWrite(pinRF,255);     
    }
void detection()        // measure 3 angles (0.90.179)
    {      
      int delay_time = 250;   // stabilizing time for servo motor after moving backward
      ask_pin_F();            // read the distance ahead
     if(Fspeedd < 10)         // if distance ahead is <10cm
      {
      stopp();               // clear data 
      delay(100);
      back();                // move backward for 0.2S
      delay(200);
      }
      if(Fspeedd < 25)         // if distance ahead is <25cm
      {
        stopp();  
        delay(100);             // clear data 
        ask_pin_L();            // read distance on the left
        delay(delay_time);      // stabilizing time for servo motor
        ask_pin_R();            // read distance on the right  
        delay(delay_time);      // stabilizing time for servo motor  
        
        if(Lspeedd > Rspeedd)   // if distance on the left is >distance on the right
        {
          directionn = Lgo;      // move to the L
        }
         if(Lspeedd <= Rspeedd)   // if distance on the left is <= distance on the right
        {
         directionn = Rgo;      // move to the right
        } 
        if (Lspeedd < 10 && Rspeedd < 10)   // if distance on left and right are both <10cm
        {
         directionn = Bgo;      // move backward        
        } }
      else                      // if distance ahead is >25cm     
      {
        directionn = Fgo;        // move forward      
      }}    
void ask_pin_F()   // measure the distance ahead 
    {
      myservo.write(90);
      digitalWrite(outputPin, LOW);   // ultrasonic sensor transmit low level signal 2μs
      delayMicroseconds(2);
      digitalWrite(outputPin, HIGH);  // ultrasonic sensor transmit high level signal10μs, at least 10μs
      delayMicroseconds(10);
      digitalWrite(outputPin, LOW);    // keep transmitting low level signal
      float Fdistance = pulseIn(inputPin, HIGH);  // read the time in between
      Fdistance= Fdistance/5.8/10;       // convert time into distance (unit: cm) 
      Fspeedd = Fdistance;              // read the distance into Fspeedd
  Serial.print("Fspeedd = ");
  Serial.print(Fspeedd );
  Serial.println("  cm");   
    }  
 void ask_pin_L()   // measure distance on the left 
    {
      myservo.write(5);
      delay(delay_time);
      digitalWrite(outputPin, LOW);   // ultrasonic sensor transmit low level signal 2μs
      delayMicroseconds(2);
      digitalWrite(outputPin, HIGH);  // ultrasonic sensor transmit high level signal10μs, at least 10μs
      delayMicroseconds(10);
      digitalWrite(outputPin, LOW);    // keep transmitting low level signal
      float Ldistance = pulseIn(inputPin, HIGH);  // read the time in between
      Ldistance= Ldistance/5.8/10;       // convert time into distance (unit: cm)
      Lspeedd = Ldistance;              // read the distance into Lspeedd
  Serial.print("Lspeedd = ");
  Serial.print(Lspeedd );
      Serial.print("  cm  ");
    }  
void ask_pin_R()   //  measure distance on the right 
    {
      myservo.write(177);
      delay(delay_time);
      digitalWrite(outputPin, LOW);   // ultrasonic sensor transmit low level signal 2μs
      delayMicroseconds(2);
      digitalWrite(outputPin, HIGH);  // ultrasonic sensor transmit high level signal10μs, at least 10μs
      delayMicroseconds(10);
      digitalWrite(outputPin, LOW);    // keep transmitting low level signal
      float Rdistance = pulseIn(inputPin, HIGH);  // read the time in between
      Rdistance= Rdistance/5.8/10;       // convert time into distance (unit: cm)
      Rspeedd = Rdistance;              // read the distance into Rspeedd
  Serial.print(" Rspeedd = ");
  Serial.print(Rspeedd );
      Serial.println("  cm");
    }  
void loop()
  {
    myservo.write(90);  // home set the servo motor, ready for next measurement
    detection();        // measure the angle and determine which direction to move   
   if(directionn == 2)  // if directionn= 2             
   {
     back(); 
     delay(800);                    //  go backward
     left() ;      
     delay(200);              // Move slightly to the left (to prevent stuck in dead end)
   }
   if(directionn == 6)           // if directionn = 6    
   { back();
     delay(100);  
     right();  
     delay(600);                 // turn right
   }
   if(directionn == 4)          // if directionn = 4    
   { back(); 
     delay(600);      
     left(); 
     delay(600);                  // turn left
   }  
   if(directionn == 8)          // if directionn = 8      
   { advance();       // move forward  
    delay(100);  
   }}

Result
Connected to Bluetooth APP, the movement of the car is controlled by the APP.

Resources

Video
http://video.keyestudio.com/KS0071/

Download APP, Library, and code:

https://fs.keyestudio.com/KS0071


Buy from

Official Website

http://www.keyestudio.com/keyes-mini-tank-robot.html

Amazon Store

https://www.amazon.com/Keyestudio-Bluetooth-Robot-Aluminum-Arduino/dp/B01F38JY7I/