Difference between revisions of "Ks0428 keyestudio Mini Tank Robot Upgraded V2"

From Keyestudio Wiki
Jump to: navigation, search
(Project 12: Ultrasonic Avoiding Tank)
(Project 12: Ultrasonic Avoiding Tank)
 
(One intermediate revision by the same user not shown)
Line 1,510: Line 1,510:
 
Need to initialize the variable“a”“a1”“a2”value to 0 and drag into <span style="color:green">'''setup'''</span> block.<br>
 
Need to initialize the variable“a”“a1”“a2”value to 0 and drag into <span style="color:green">'''setup'''</span> block.<br>
  
Go to <span style="color:green">'''“Control”'''</span>, drag out block[[File:0464-pro3图13.png|100px|frameless|]]; then go to drag the block [[File:Ks0464-313.png|200px|frameless|]],[[File:Ks0464-314.png|200px|frameless|]] and [[Ks0464-315.png|200px|frameless|]] into <span style="color:green">'''setup'''</span> block; click <span style="color:green">'''“Mini_Tank_Robot”'''</span>, drag out the block [[File:Ks0464-36.png|200px|frameless|]]into <span style="color:green">'''setup'''</span> block and set the servo angle to initial 90.<br><br>
+
Go to <span style="color:green">'''“Control”'''</span>, drag out block[[File:0464-pro3图13.png|100px|frameless|]]; then go to drag the block [[File:Ks0464-313.png|200px|frameless|]],[[File:Ks0464-314.png|200px|frameless|]] and [[File:Ks0464-315.png|200px|frameless|]] into <span style="color:green">'''setup'''</span> block; click <span style="color:green">'''“Mini_Tank_Robot”'''</span>, drag out the block [[File:Ks0464-36.png|200px|frameless|]]into <span style="color:green">'''setup'''</span> block and set the servo angle to initial 90.<br><br>
 
[[File:图片a5.png|500px|frameless|]]<br>
 
[[File:图片a5.png|500px|frameless|]]<br>
  
Line 1,525: Line 1,525:
  
  
Go to <span style="color:green">'''“Mini_Tank_Robot”'''</span>, drag out the block [[File:Ks0464-100.png|100px|frameless|]]into the <span style="color:green">'''do'''</span> statement. And add a <span style="color:green">'''delay'''</span> block '''1000ms'''. <br>
+
Go to <span style="color:green">'''“Mini_Tank_Robot”'''</span>, drag out the block [[File:图片a6.png|100px|frameless|]]into the <span style="color:green">'''do'''</span> statement. And add a <span style="color:green">'''delay'''</span> block '''1000ms'''. <br>
  
 
In order to make the ultrasonic sensor measure the distance several times in the left obstacle and in the right obstacle. <br>
 
In order to make the ultrasonic sensor measure the distance several times in the left obstacle and in the right obstacle. <br>
  
We again drag the block [[File:Ks0464-101.png|200px|frameless|]]into the do statement. Set the servo angle to 180.<br>
+
We again drag the block [[File:Ks0464-101.png|200px|frameless|]]into the do statement. Set the servo angle to 160.<br>
  
 
Go to <span style="color:green">'''“Control”'''</span>, drag out the block [[File:Ks0464-102.png|300px|frameless|]]; duplicate the block [[File:Ks0464-103.png|200px|frameless|]]once and drag it into the step block just made. <br>
 
Go to <span style="color:green">'''“Control”'''</span>, drag out the block [[File:Ks0464-102.png|300px|frameless|]]; duplicate the block [[File:Ks0464-103.png|200px|frameless|]]once and drag it into the step block just made. <br>
Line 1,547: Line 1,547:
  
 
And again go to <span style="color:blue">'''“Logic”'''</span>, drag out the block [[File:Ks0464-385.png|200px|frameless|]]into the <span style="color:green">'''if'''</span> statement; and click the drop-down triangle to select“<span style="color:blue">'''or'''</span>”; then drag the block[[File:Ks0464-386.png|200px|frameless|]] and [[File:Ks0464-387.png|200px|frameless|]]into the input box of block[[File:Ks0464-388.png|200px|frameless|]] .<br>
 
And again go to <span style="color:blue">'''“Logic”'''</span>, drag out the block [[File:Ks0464-385.png|200px|frameless|]]into the <span style="color:green">'''if'''</span> statement; and click the drop-down triangle to select“<span style="color:blue">'''or'''</span>”; then drag the block[[File:Ks0464-386.png|200px|frameless|]] and [[File:Ks0464-387.png|200px|frameless|]]into the input box of block[[File:Ks0464-388.png|200px|frameless|]] .<br>
 +
[[File:Ks0464-389.png|500px|frameless|]]
  
 
<span style="color:blue">Next judge if the distance a1 is greater than that of a2, set the servo angle to 90°, tank robot will rotate to left for 500ms at a speed of PWM255 then go front at a speed of PWM200. </span><br>
 
<span style="color:blue">Next judge if the distance a1 is greater than that of a2, set the servo angle to 90°, tank robot will rotate to left for 500ms at a speed of PWM255 then go front at a speed of PWM200. </span><br>
Line 1,552: Line 1,553:
 
<span style="color:blue">If the distance a1 is smaller than that of a2, set the servo angle to 90°, tank robot will rotate to left for 500ms at a speed of PWM255 then go front at a speed of PWM200.</span><br>
 
<span style="color:blue">If the distance a1 is smaller than that of a2, set the servo angle to 90°, tank robot will rotate to left for 500ms at a speed of PWM255 then go front at a speed of PWM200.</span><br>
  
Go to <span style="color:green">'''“Control”'''</span>, drag the block [[File:Pro8-图片14.png|150px|frameless|]]into the <span style="color:blue">'''do'''</span> statement of block [[File:Ks0464-389.png |150px|frameless|]],<br>
+
Go to <span style="color:green">'''“Control”'''</span>, drag the block [[File:Pro8-图片14.png|150px|frameless|]]into the <span style="color:blue">'''do'''</span> statement of block [[File:Ks0464-389.png |300px|frameless|]],<br>
 
then click the blue gear icon, appear the edit box, drag the [[File:Ks0464-93.png|200px|frameless|]]block into[[File:Pro8-图片15.png|150px|frameless|]] block. So you can get the block: <br>
 
then click the blue gear icon, appear the edit box, drag the [[File:Ks0464-93.png|200px|frameless|]]block into[[File:Pro8-图片15.png|150px|frameless|]] block. So you can get the block: <br>
[[File:Ks0464-390.png|150px|frameless|]]<br>
+
[[File:Ks0464-390.png|300px|frameless|]]<br>
  
Go to <span style="color:blue">'''“Logic”'''</span>, drag the block into the <span style="color:green">'''if'''</span> statement and select“>”; go to <span style="color:purple">'''“Variables”'''</span>, drag out the block into the first input box at the left side of “>”; drag theinto the second input box at the right side of “>” .<br>
+
Go to <span style="color:blue">'''“Logic”'''</span>, drag the block [[File:P3-20.png|200px|frameless|]] into the <span style="color:green">'''if'''</span> statement and select“>”; go to <span style="color:purple">'''“Variables”'''</span>,drag out the block [[File:Ks0464-88.png|200px|frameless|]] into the first input box at the left side of “>”; drag the [[File:Ks0464-89.png|200px|frameless|]]into the second input box at the right side of “>”.<br>
 
 
Go to <span style="color:blue">'''“Logic”'''</span>, drag the block [[File:P3-20.png|200px|frameless|]] into the <span style="color:green">'''if'''</span> statement and select“>”; go to <span style="color:purple">'''“Variables”'''</span>,drag out the block [[File:Ks0464-88.png|200px|frameless|]] into the first input box at the left side of “>”; drag the [[File:Pro8-图片20.png |200px|frameless|]]into the second input box at the right side of “>”.<br>
 
 
Click <span style="color:green">“Mini_Tank_Robot”</span>, drag out the block [[File:Ks0464-101.png|200px|frameless|]] and[[File: Ks0464-392.png|200px|frameless|]] ; set to servo angle '''90''' and PWM '''255'''. <br>
 
Click <span style="color:green">“Mini_Tank_Robot”</span>, drag out the block [[File:Ks0464-101.png|200px|frameless|]] and[[File: Ks0464-392.png|200px|frameless|]] ; set to servo angle '''90''' and PWM '''255'''. <br>
 
Add a <span style="color:green">'''delay'''</span> block 500ms. Then drag out the [[File:Ks0464-393.png|200px|frameless|]] and set to PWM200.<br>
 
Add a <span style="color:green">'''delay'''</span> block 500ms. Then drag out the [[File:Ks0464-393.png|200px|frameless|]] and set to PWM200.<br>
Line 1,573: Line 1,572:
  
 
First drag the block [[File:Ks0464-402.png|200px|frameless|]] into the <span style="color:green">'''setup'''</span> block. <br>
 
First drag the block [[File:Ks0464-402.png|200px|frameless|]] into the <span style="color:green">'''setup'''</span> block. <br>
[[File:Ks0464-403.png|200px|frameless|]]<br>
+
[[File:Ks0464-403.png|400px|frameless|]]<br>
  
Click <span style="color:blue">'''“Variables”'''</span>, drag out the variable block [[File:Ks0464-404.png|200px|frameless|]]; drag the block [[File:Ks0464-405.png|200px|frameless|]]from <span style="color:blue">'''“Math”'''</span> into the random block. <br>     
+
Click <span style="color:purple">'''“Variables”'''</span>, drag out the variable block [[File:Ks0464-404.png|200px|frameless|]]; drag the block [[File:Ks0464-405.png|300px|frameless|]]from <span style="color:blue">'''“Math”'''</span> into the random block. <br>     
 
The random number can be set at will, in this case from 1 to 100.<br>
 
The random number can be set at will, in this case from 1 to 100.<br>
We drag the block [[File:Ks0464-406.png|200px|frameless|]] above the block [[File:Ks0464-407.png|200px|frameless|]].<br>
+
We drag the block [[File:Ks0464-406.png|300px|frameless|]] above the block [[File:Ks0464-407.png|200px|frameless|]].<br>
  
  
Line 1,585: Line 1,584:
 
Go to <span style="color:blue">'''“Logic”'''</span>, drag out the block[[File:P3-20.png|200px|frameless|]] ; and drag out the block [[File:Ks0464-409.png|200px|frameless|]]from “Math” into the first input box at the left side of “=”;  then go to “Variables”, drag out the block [[File:Ks0464-401.png|200px|frameless|]]into the input box at the left side of “+” , replacing box 1; click the drop-down triangle to choose “%”, replacing“+”; change the second box1 to 2.<br>
 
Go to <span style="color:blue">'''“Logic”'''</span>, drag out the block[[File:P3-20.png|200px|frameless|]] ; and drag out the block [[File:Ks0464-409.png|200px|frameless|]]from “Math” into the first input box at the left side of “=”;  then go to “Variables”, drag out the block [[File:Ks0464-401.png|200px|frameless|]]into the input box at the left side of “+” , replacing box 1; click the drop-down triangle to choose “%”, replacing“+”; change the second box1 to 2.<br>
 
And drag the block [[File:Ks0464-411.png|200px|frameless|]]from <span style="color:blue">'''“Math”'''</span> into the input box at the right side of“=”. <br>
 
And drag the block [[File:Ks0464-411.png|200px|frameless|]]from <span style="color:blue">'''“Math”'''</span> into the input box at the right side of“=”. <br>
Get complete block like this:<br>
+
Get complete block like this:<br><br>
[[File:Ks0464-412.png|200px|frameless|]]<br>
+
[[File:Ks0464-412.png|300px|frameless|]]<br>
  
 
We duplicate this piece of code block [[File:Ks0464-413.png|200px|frameless|]]done before once. <br>
 
We duplicate this piece of code block [[File:Ks0464-413.png|200px|frameless|]]done before once. <br>
 
Just replace [[File:Ks0464-414.png|200px|frameless|]] with the block [[File:Ks0464-412.png|200px|frameless|]]. And drag them into the <span style="color:green">'''else'''</span> statement.<br>
 
Just replace [[File:Ks0464-414.png|200px|frameless|]] with the block [[File:Ks0464-412.png|200px|frameless|]]. And drag them into the <span style="color:green">'''else'''</span> statement.<br>
[[File:Ks0464-416.png|200px|frameless|]]
+
[[File:Ks0464-416.png|400px|frameless|]]
  
 
<span style="color:blue">Finally judge whether the front obstacle distance measured by ultrasonic sensor is greater than 20cm, tank robot will go front at a speed of PWM200.</span><br>
 
<span style="color:blue">Finally judge whether the front obstacle distance measured by ultrasonic sensor is greater than 20cm, tank robot will go front at a speed of PWM200.</span><br>

Latest revision as of 18:07, 11 October 2019


Keyestudio Mini Tank Robot Upgrade V2



About the tutorial

Here comes a keyestudio mini tank robot upgraded V2. This tank robot is essentially a two-drive tracked vehicle.
The tank robot mainly uses the UNO R3 control board, L298P driver shield and sensor shield V5, no soldering and easy to play.
Mini tank robot is a learning application development system of microcontroller based on Mixly blocks coding platform.
The tank robot kit is designed specifically for those who are interested in learning about Arduino and electronics.

You can find out those awesome improvements as follows:

In all robot projects, you are able to learn the Mixly blocks coding and Arduino program. It allows you to quickly learn graphic programming in entertaining, nurturing your interest in science and logical thinking.


Technical Parameters

  • 1)Motor parameters: 6V, 150rpm/min. 
  • 2)Motor control by L298P driver shield with power switch.
  • 3)Equipped with Bluetooth wireless module, can remotely control the robot after pairing with mobile Bluetooth.
  • 4)With IR receiver module, pairing infrared remote control to control the tank robot.
  • 5)With Photocell module, detecting the light intensity on both sides of tank robot to control the tank robot.
  • 6)With the ultrasonic module, measuring the distance between the obstacles and tank robot.
  • 7)Can access to external 7~12V power supply; match various sensor modules to realize various functions according to your imagination.
  • 8)Providing the Mixly software and test code, easy to play and simple.



Packing List


thumb

thumb

thumb

thumb
thumb

thumb


Get Started with Mixly and ARDUINO

1)Installing Arduino IDE

When program the UNO development board, you can download the Arduino integrated development environment from the link:


See more contents at:


Ks0436-9.png

The functions of each button on the Toolbar are listed below:
IDE.png

IDE 1.png Verify/Compile Check the code for errors
IDE 2.png Upload Upload the current Sketch to the Arduino
IDE 3.png New Create a new blank Sketch
IDE 4.png Open Show a list of Sketches
IDE 5.png Save Save the current Sketch
IDE 6.png Serial Monitor Display the serial data being sent from the Arduino


Or you can browse the KEYESTUDIO website at this link, https://www.keyestudio.com/ and then click on the WIKI Tutorial.
图片wiki.png



2)Introduction for Mixly Blocks

Mixly is a free open-source graphical Arduino programming software, based on Google’s Blockly graphical programming framework, and developed by Mixly [email protected] BNU.
It is a free open-source graphical programming tool for creative electronic development; a complete support ecosystem for creative e-education; a stage for maker educators to realize their dreams.
More info please check the link to download the Mixly blocks software.

Before starting the robot projects, please click the link to get the basic understanding of Mixly software.
Ks0446图片8.png



3)Import Robot Library

For the robot kit, we have developed keyestudio tank robot library.
Don’t forget to import the keyestudio mini tank robot library to Mixly software before coding the robot projects.
Must import the robot car library first, or else you CANN'T check all the test code.


0428图片11.png

Unzip the Mini_Tank_Robot library package, you can see the Mini_Tank_Robot XML.document.
0428图片12.png

Then import this document into Mixly library. Import custom library successfully!
0428图片13.png

You are able to click “Manager” to manage all imported libraries.
Note: sometimes it may exists a conflict between libraries, so should keep only correct car library when using and delete other library.

0428图片14.png



Get Started with Hardware Projects


Project 1: Built-in LED

Keyestudio UNO R3

When it comes to using the UNO R3 as core of our robot, the UNO is the best board to get started with electronics and coding.
If this is your first experience tinkering with the platform, the UNO is the most robust board you can start playing with.
Well, let's at first have a look at this UNO R3 board.

Here is an explanation chart of what every element and interface of the board does:
Ks0001-pinout.png

KS0001 5-1.png ICSP (In-Circuit Serial Programming) Header

In most case, ICSP is the AVR,an Arduino micro-program header consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often called the SPI (serial peripheral interface) and can be considered an "extension" of the output. In fact, slave the output devices under the SPI bus host.
When connecting to PC, program the firmware to ATMEGA328P-PU.

KS0001 5-2.png Power LED Indicator

Powering the Arduino, LED on means that your circuit board is correctly powered on. If LED is off, connection is wrong.

KS0001 5-3.png Digital I/O

Arduino UNO has 14 digital input/output pins (of which 6 can be used as PWM outputs). These pins can be configured as digital input pin to read the logic value (0 or 1). Or used as digital output pin to drive different modules like LED, relay, etc. The pin labeled “〜” can be used to generate PWM.

KS0001 5-4.png GND ( Ground pin headers)

Used for circuit ground

KS0001 5-5.png AREF

Reference voltage (0-5V) for analog inputs. Used with analogReference().

KS0001 5-6.png SDA

IIC communication pin

KS0001 5-7.png SCL

IIC communication pin

KS0001 5-8.png ICSP (In-Circuit Serial Programming) Header

In most case, ICSP is the AVR,an Arduino micro-program header consisting of MOSI, MISO, SCK, RESET, VCC, and GND. Connected to ATMEGA 16U2-MU. When connecting to PC, program the firmware to ATMEGA 16U2-MU.

KS0001 5-9.png RESET Button

You can reset your Arduino board, for example, start the program from the initial status. You can use the RESET button.

KS0001 5-10.png D13 LED

There is a built-in LED driven by digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.

KS0001 5-11.png USB Connection

Arduino board can be powered via USB connector. All you needed to do is connecting the USB port to PC using a USB cable.

KS0001 5-12.png ATMEGA 16U2-MU

USB to serial chip, can convert the USB signal into serial port signal.

KS0001 5-13.png TX LED

Onboard you can find the label: TX (transmit) When Arduino board communicates via serial port, send the message, TX led flashes.

KS0001 5-14.png RX LED

Onboard you can find the label: RX(receive ) When Arduino board communicates via serial port, receive the message, RX led flashes.

KS0001 5-15.png Crystal Oscillator

Helping Arduino deal with time problems. How does Arduino calculate time? by using a crystal oscillator.
The number printed on the top of the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16MHz.

KS0001 5-16.png Voltage Regulator

To control the voltage provided to the Arduino board, as well as to stabilize the DC voltage used by the processor and other components.
Convert an external input DC7-12V voltage into DC 5V, then switch DC 5V to the processor and other components.

KS0001 5-17.png DC Power Jack

Arduino board can be supplied with an external power DC7-12V from the DC power jack.

KS0001 5-18.png IOREF

Used to configure the operating voltage of microcontrollers. Use it less.

KS0001 5-19.png RESET Header

Connect an external button to reset the board. The function is the same as reset button (labeled 9)

KS0001 5-20.png Power Pin 3V3

A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.

KS0001 5-21.png Power Pin 5V

Provides 5V output voltage

KS0001 5-22.png Vin

You can supply an external power input DC7-12V through this pin to Arduino board.

KS0001 5-23.png Analog Pins

Arduino UNO board has 6 analog inputs, labeled A0 through A5.
These pins can read the signal from analog sensors (such as humidity sensor or temperature sensor), and convert it into the digital value that can read by microcontrollers) Can also used as digital pins, A0=D14, A1=D15, A2=D16, A3=D17, A4=D18, A5=D19.

KS0001 5-24.png Microcontroller

Each Arduino board has its own microcontroller. You can regard it as the brain of your board.
The main IC (integrated circuit) on the Arduino is slightly different from the panel pair. Microcontrollers are usually from ATMEL. Before you load a new program on the Arduino IDE, you must know what IC is on your board. This information can be checked at the top of IC.



Let’s make a simple test for the UNO built-in LED (D13).
We will work on blinking an LED. That’s right - it’s as simple as turning a light on and off!
Now enough talking - let’s get started with the LED project.

Blinking an LED
It’s pretty simple to turn a built-in led on and off. We only require UNO R3 control board and a USB cable to enter the wonderful programming world.
Connect your UNO R3 board to the computer’s USB port using a USB cable for communication.

0428图片15.png


Test Code:
Open Mixly blocks platform to get started with coding.
First, click IN/OUT, drag the “DigitalWrite PIN# (0)Stat(HIGH)” block.

0428图片16.png

This block is used to set the level HIGH or LOW of Digital pin.

  • Select HIGH is to set the HIGH level.
  • Select LOW is to set the LOW level.
  • The HIGH level is the state of high voltage, generally recorded as 1.
  • High voltage, high current, the LED lights.
  • The LOW level is the state of low voltage, generally recorded as 0.
  • Low voltage, low current, the LED Not lights.

To observe the LED blink obviously, we need to add a Delay block.
Check the test code below and upload it to your UNO R3 board.
0428图片17.png

What you should see:
Drag the test code to Mixly window; remember to select the proper board and COM port.
Then compile and upload the code to your control board. Upload success message will appear on the bottom bar.
The UNO built-in LED (label “L”) will turn on for 1 second, and then turn off for 1 second, alternately and circularly.

0428图片18.png

0428图片19.png



Project 2: Displaying Images

The robot run status will show on keyestudio 8x16 LED matrix panel. So first let’s learn how to program this 8x16 LED matrix panel.

keyestudio 8x16 LED matrix panel


Hardware Introduction:
Keyestudio 8x16 LED matrix panel comes with 128 LEDs and AIP1640 chip welded on the back.
The matrix panel has 128 bright LEDs arranged in 8x16 on the front. On the back there are a AIP1640 chip and a 4Pin interface (GND, VCC, SDA, SCL). Through controlling the AIP1640 chip, control the 128 LEDs on the panel turn on or off, displaying the images you want to show on the LED matrix. For easy wiring, it includes an HX-2.54 4Pin cable.


Parameters:

  • Operating Voltage: DC 3.3-5V
  • Power loss: 400mW
  • Oscillation frequency: 450KHz
  • Driving current: 200mA
  • Working temperature: -40°C to 80°C
  • Communication method: I2C communication


0428图片21.png


Hookup Guide
Stack the V5 sensor shield onto motor drive shield, then stack them on UNO R3 board. Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication. Connect the two 18650 batteries for power supply.
0428图片22.png


Coding:
The 8x16 LED panel shows a “V”, front, stop icons; then clear the icons, with an time interval of 2000ms.
Go to “Control” , drag out the blockP5-1.png. Then go to “Mini_Tank_Robot” , drag and drop the block 428-pro4-4.png into the setup block. And click the drop-down triangle behind start to select “clear”, in order to clear the displayed pattern on the 8x16 LED panel.

And go to “Mini_Tank_Robot” , drag out the block 428-pro4-4.png; go to “Control” , drag out the delay block428-pro2-3.png; can randomly set the delay time; here we set to delay 2000ms.
428-pro2-4.png

Then duplicate the above code string three times; click the drop-down triangle behind start to respectively select “front”、”STOP”、“clear”; keep delay block in 2000ms.

Upload the code to see the effect!
0428图片23.png


Test Result:
0428图片24.png
Upload the code to UNO board, then turn the slide switch to ON position. The keyestudio 8x16 LED matrix panel shows the icons V,0428图片31.png ,STOP, and then clear the icons, with an interval of 2 seconds.
0428图片25.png

0428图片27.png

0428图片28.png



Little Knowledge:
1.In the code, we’ve set the display patterns of LED panel. You can choose 7 patterns. If choose clear, it will clear the pattern showed on the LED panel.
0428图片29.png


2.What happens when you change the number in one or both of the delay(2000):0428图片30.png This delay period is in milliseconds, so if you want the LED display as low or fast, change the value, try 500 or 3000.



Extension Practice:
1.Make the LED panel display 7 patterns in a cycle, with a delay time of 500ms for each pattern. (reference program)
428-pro2-5.png


Project 3: Photo Resistor

To build a light following robot in the robot projects, first let’s now get the basic understanding of keyestudio photo-resistor module.

keyestudio photo-resistor module


Hardware Introduction:
A photo-resistor or light-dependent resistor (LDR) or photocell is a light-controlled variable resistor.
The resistance of photo-resistor varies with incident light intensity.
If the incident light intensity is high, the resistance decreases; if the light intensity is low, the resistance increases.
We use the characteristics of the photo-resistor to design the circuit and generate the photo-resistor module.
Connecting the signal pin of photocell module to Analog port, when the stronger the light intensity, the greater the voltage of analog port, the greater the analog value is.
On the contrary, the weaker the light intensity, the smaller the voltage of analog port, the smaller the analog value is.
Based on that, we can use the photocell module to read the analog value, so get the ambient light intensity.
It can be applied in light-sensitive detector circuits, intelligent switch design and light- and dark-activated switching circuits.


Parameters:

  • Interface: 3Pin
  • Working voltage: 3.3V-5V(DC)
  • Output signal: analog signal


Hookup Guide
Stack the V5 sensor shield onto motor drive shield, then stack them on UNO R3 board. Connect the LED panel and 2 photocell modules to sensor shield V5.
Connect the left photocell sensor (-, +, S) to sensor shield (G(GND)、V(VCC)、A1); the right photocell to sensor shield (G(GND)、V(VCC)A2).
0428图片33.png


Coding:
The left and the right photocell sensors have been connected well.
We can design the program to read the photosensitive light change of photocell sensors via serial port.
So we can use the block 0428图4.png or 0428图5.png, printing out the contents on the serial monitor.
Because there are two photocell sensors, we first build two variables to separately store the light intensity measured by both photocell sensors.

Go to “Variables”, drag out the block 0428图6.png; and go to “Math”, drag the block 0428图7.pnginto the block 0428图6.png. Then duplicate this code block once, and separately change the “item” into “left_light” and “right_light”.
0428图9.png

In this way, we have built the variable blocks 0428图10.png and 0428图11.png.

A variable is like a box, and a new variable is like making a box; we can give the box a name, like we just called it “left_light”. The things placed inside the box can be changed, like we can place oranges, apples, pears, etc.
The function of the variable box in this program is to load the light intensity value. With this box called “left_light”, we can store the light intensity value measured by left_light sensor. So every time I mention left_light, it refers to the light intensity value measured by left_light sensor at that time.

Go to “Variables”, drag out the block 0428图12.png; and go to “Mini_Tank_Robot”, drag the block 0428图13.pnginto the block just made. 0428图14.png
Then duplicate this code block once, and change left_light into right_light; click the drop-down triangle to select the right_light_sensor. 0428图15.png

Go to “SerialPort”, drag out the block 0428图16.png; and drag the block 0428图17.png from “Text” into the Serial print block just made. Then duplicate this code block three times; change the first “hello” into “left_light_value=”; drag out the block 0428图10.png from “Variables” to replace the second “hello”; delete the third “hello”, leaving a blank space; change the fourth “hello” into “right_light_value=”

Then go to “SerialPort”, drag out the block 0428图19.png; and drag the block 0428图10.png from “Variables” into the Serial printIn block just made.
0428图21.png

To make the data refresh slowly, we add a delay block 0428图22.png from “Control” and set to 500ms.
Don’t forget to add setup and Serial baud rate 9600!
Go to “Control” , drag out the setup blockP5-1.png; and drag out the block P5-2.png into the setup block you just made. Then drag the block 0428图25.png and 0428图26.png beneath the Serial baud rate 9600 block.
0428图27.png

If the data measured by left photocell sensor is greater than 600, or the data measured by the right photocell sensor is is greater than 600, LED panel shows a front icon, otherwise, shows a “V”.

Here we can use the condition statementP3-13.png or P3-14.png.But the blockP3-14.png is more efficient thanP3-13.png.
Go to “Control”, drag out the blockP3-13.png, then click the blue gear icon, appear the edit box, drag the block P3-17.png into Pro8-图片15.png block. So you can get the blockP3-14.png .

Next, go to the “Logic” , drag out the block P3-20.png and select “>”, then drag out the block0428图10.png from the “Variables” into the first input box at the left side of “>” ; drag thePro8-图片20.png from the “Math” into the second input box at the right side of “>” and change the value to 600; like this:0428图33.png
We duplicate this block once, and drag out the block0428图34.png, replacing the0428图10.png .
And again go to the “Logic” , drag out the blockP3-25.png into the if statement; respectively drag the block0428图33.png and 0428图38.png into the input box of blockP3-25.png.
0428图40.png

Drag out the block428-pro4-4.png from “Mini_Tank_Robot” into the do statement, and click the drop-down triangle to choose the front. And Duplicate the block428-pro4-4.png once and drag into the else statement.
0428图42.png

Connect the UNO R3 control board to PC using a USB cable; upload the complete code to test the light intensity!

0428图1.png


Test Result:
Upload the code success, open the monitor and set the baud rate to 9600.
The monitor window will print out the analog value of ambient light.
0428图片36.png

If the measured value of one side is greater than 600, the LED matrix panel will show the front icon 0428图片31.png; otherwise, show the V.
0428图片38.png

0428图片37.png


Little Knowledge:

1.In the code, we use the library 0428图片39.pngto read the analog value of the left photocell sensor (A1); using the block 0428图片40.png also makes sense.
The signal pin of the right photocell sensor is A2.
0428图2.png

2.Ks0446图片30.png means the baud rate is set to 9600;
0428图片43.pngPrint the specified number, text or other value on serial monitor.
0428图片44.pngPrint the specified number, text or other value on newline of monitor.

3.0428图片45.pngmeans that if condition 1 is satisfied, it's going to be A, otherwise it's going to be B.
When using, you can find the if...do...statement block in the Mixly Control Block. Then click the gear icon on the block to drag out the else or else if block you need to use.
0428图片46.png

4.0428图片47.pngThis is a logical statement. It’s available as long as can satisfy any one of the two conditions.



Extension Practice:
1.Change the control logic of 2 analog values read by 2 photocell sensors to make the LED panel show different patterns. (reference program)
0428图3.png


Project 4: Ultrasonic Detecting Obstacles

HC-SR04 ultrasonic module


Hardware Introduction:
The ultrasonic module will emit the ultrasonic waves after trigger signal. When the ultrasonic waves encounter the object and are reflected back, the module outputs an echo signal, so it can determine the distance of object from the time difference between trigger signal and echo signal.

We can use the ultrasonic sensor to detect whether there is an obstacle ahead. It is commonly used to measure the distance between the front obstacle and robot.
In the process of robot DIY, we can use the measured distance by ultrasonic sensor to build functional robots, such as automatic avoiding, following, etc.

In the experiment, we use the ultrasonic sensor to measure the distance between the robot and front obstacle, controlling the keyestudio 8x16 LED matrix panel show the images.


Specifications:

  • Operating Voltage: DC 5V
  • Operating Current: 15mA
  • Operating Frequency: 40khz
  • Max Range: 2--3m
  • Min Range: 2cm
  • Measuring Angle: 15 degree
  • Trigger Input Signal: 10µS TTL pulse


Hookup Guide
Connect the ultrasonic sensor to sensor shield V5, VCC pin to 5V(V), Trig pin to digital 5 (S), Echo pin to digital 4 (S), GND pin to GND(G).
Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication.

0428图片49.png


Coding:
The ultrasonic sensor is connected to sensor shield V5, VCC pin to 5V(V), Trig pin to digital 5 (S), Echo pin to digital 4 (S), GND pin to GND(G).; Trig pin is to trigger signal and Echo pin is to receive echo signal.
Next need to write the program to get the specific distance measured by ultrasonic sensor.

Go to “Control” , drag out the “setup” block P5-1.png;
Drag out the block P5-2.png from “SerialPort” into the “setup” block.
Go to the “SerialPort” again, drag out the blockP5-3.png and P5-4.png
Go to “Text”, drag out the block P5-5.png into the block P5-3.png, and change the word “hello” to “distance=”.
Then go to “Small_Turtle_Robot”, drag and drop the ultrasonic block 428-pro4-1.png into “Serial printIn” block;
To make the value print slowly, we add a delay block.
And again go to “Control”, drag the delay blockPro4-图片3.png; set the delay time in 500ms.

428-pro4-2.png



In the following, try to realize another two distance situations:
When the measured distance between the ultrasonic sensor and front obstacles is smaller than 10cm, LED panel displays a STOP pattern.
When the measured distance between the ultrasonic sensor and front obstacles is greater than 10cm, LED panel displays a V pattern.

To judge whether the distance is smaller than 10cm or greater than 10cm, here we can use the condition statement P3-13.png or P3-14.png. But the block P3-14.png is more efficient than P3-13.png .
Go to “Control”, drag out the blockP3-13.png, then click the blue gear icon, appear the edit box, drag the P3-17.png block into Pro8-图片15.png block. So you can get the block P3-14.png.

Next, go to “Logic”, drag the block P3-20.png into the if statement, and drag out the block 428-pro4-1.png from the “Mini_Tank_Robot” into the first input box at the left side of “=”; drag the Pro8-图片20.png from the “Math” into the second input box at the right side of “=” ; change the“=” to“<” , change the value 0 to 10; like this:428-pro4-3.png.

Drag out the block428-pro4-4.png from “Mini_Tank_Robot” into the do statement, click the drop-down triangle to choose the STOP. And Duplicate the block 428-pro4-4.png once and drag into the else statement.

428-pro4-5.png

Upload the code success, open the serial monitor to check the distance between ultrasonic sensor and an obstacle.
428-pro4-6.png



Test Result:
Upload the code success, open the monitor and set the baud rate to 9600.
When place an obstacle in front of the ultrasonic sensor, the measured distance between an obstacle and sensor is showed on the monitor. The unit is cm.
0428图片52.png

When the measured distance is less than 10cm, 8x16 LED panel shows STOP; otherwise, shows V.
0428图片54.png

0428图片53.png


Little Knowledge:

1.In the code, we use the 0428图片55.png to measure the distance between ultrasonic sensor and obstacle ahead, with a unit of cm.

2.Ks0446图片30.png: means the baud rate is set to 9600;
428-pro4-7.png: print the distance value on the newline of monitor.

3.0428图片45.pngmeans that if condition 1 is satisfied, it's going to be A, otherwise it's going to be B.
When using, you can find the if...do...statement block in the Mixly Control Block. Then click the gear icon on the block to drag out the else or else if block you need to use.
0428图片46.png



Extension Practice:
1.You can reset the control logic. Change the distance value measured by ultrasonic sensor to make the LED panel show different patterns. (reference program)
428-pro4-8.png


Project 5: Infrared Receiving


  • IR Remote Control:
KS0364 - 图片8.png

There is no doubt that infrared remote control is commonly seen in our daily life. It's hard to imagine our world without it.
An infrared remote control can be used to control a wide range of home appliances such as television, audio, video recorders and satellite signal receivers.
Well, in the following let’s get a better understanding of the infrared remote control.

Infrared remote control is composed of infrared transmitting and infrared receiving systems. That is, consist of an infrared remote control, an infrared receiver module and a microcontroller that can decode. You can refer to the figure below.
 
Ks0436-201.png

The 38K infrared carrier signal transmitted by an infrared remote controller is encoded by an encoding chip inside the remote controller. It is composed of a pilot code, user code, data code, and data inversion code.
The time interval between pulses is used to distinguish whether it is a signal 0 or 1. (when the ratio of high level to low level is about 1:1, considered as signal 0.) And the encoding is just well composed of signal 0 and 1.

The user code of the same button on remote controller is unchanged. Using difference data distinguish the key pressed on the remote control.
When press down a button on the remote control, it will send out an infrared carrier signal. And when infrared receiver receives that signal, its program will decode the carrier signal, and through different data codes, thus can judge which key is pressed.
The microcontroller is decoded by an received signal 0 or 1 to determine which key is pressed by the remote control.


  • IR Receiver Module:

As for an infrared receiver module, it is mainly composed of an infrared receiving head. This device integrates with reception, amplification and demodulation. Its internal IC has been demodulated, outputting Digital signal. Suitable for IR remote control and infrared data transmission.
The infrared receiver module has only three pins (Signal, VCC, GND), very convenient to communicate with Arduino and other microcontrollers.

IR Receiver Module


Parameters of IR Receiver:

  • 1)Operating Voltage: 3.3-5V(DC)
  • 2)Interface: 3PIN
  • 3)Output Signal: Digital signal
  • 4)Receiving Angle: 90 degrees
  • 5)Frequency: 38khz
  • 6)Receiving Distance: 18m


Hookup Guide:
Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication.
Connect the infrared receiver sensor (pin -、+、S) to the sensor shield (G(GND)、V(VCC)、A0). If the digital ports are not enough, analog port can be used as digital port. Analog port A0 corresponds to digital port14; A1 corresponds to digital port15.

0428图片60.png


Coding:
Now write the program. When aligning at the IR receiver, press the key on the IR remote control, available to check the input signal change of IR receiver on the serial monitor.
Go to “Control”, drag out theP9-1.pngblock; and drag theP9-2.pngblock from “SerialPort” into the “setup” block.
Next, IR receiver will receive the infrared signal when press different keys on the IR remote control.

We first click the imported library “Mini_Tank_Robot”, drag out the block428-pro5-1.png; drag the blockP9-4.png from “SerialPort” into the infrared receiver block just made.
Then go to “Variables”, drag out the block P9-5.pnginto the blockP9-4.png.

So the infrared receiver can receive the infrared signal.
428-pro5-2.png

Upload this code, open the serial monitor; aimed at the infrared receiver sensor, press the key on the IR remote control, IR receiver will receive the infrared signal, and indicator turns on red. And you can see the key encoding on the serial monitor.

P9-8.png

Next move on to realize the IR receiver controlling matrix displaying pattern with IR remote control.

Press the front key P9-9.png on the IR remote control, dot matrix displays a front pattern; press the key P9-10.png , dot matrix displays STOP pattern. So here we call the if statement P9-11.png from the “Control”. According to the measured result, we know the infrared encoding(string value) of front key P9-9.png is FF629D; the infrared encoding(string value) of key P9-10.png is FF02FD.
As the command key of IR remote control is hexadecimal code, the front must add 0x.

If ir_rec=0xFF629D, press the front key P9-9.png on the IR remote control,dot matrix displays a front pattern.

Go to the “Logic”, drag out the block P3-20.png into the if statement, and drag out the block P9-16.pngfrom the “Variables” into the first input box at the left side of “=”; drag the Pro8-图片20.pngfrom the “Math” into the second input box at the right side of “=” and type “0xFF629D” , like this:0464-pro6图1.png.

Click “Mini_Tank_Robot” , drag out the block 428-pro5-3.png into the do statement and click the drop-down triangle to choose front.


428-pro5-4.png
Duplicate the above code string once; change “0xFF629D” to “0xFF02FD” and click the drop-down triangle to select STOP.
428-pro5-5.png

The program is finished well! Upload the complete code to see the effect.
0428图片61.png


Test Result:
Upload the code success, then open the serial monitor and set the baud rate to 9600.
Aimed at the IR receiver sensor, press down the key of remote control, you will see the corresponding encode of key on the monitor.
If you long press the button, it will easily appear a messy code like FFFFFF shown as below.
0428图片62.png

0428图片63.png

If receive the up button value from IR remote control, LED matrix panel shows the 0428图片31.pngicon; if receive the OK key value, shows STOP.
0428图片64.png

0428图片65.png


Below we have listed out each button value of keyestudio remote control. So you can keep it for reference.
thumb



Little Knowledge:
1.0428图片67.pngIn the code, we direct use the library; the signal pin of IR receiver module is A0; the IR receiver receives an infrared signal and outputs 16-bit encoding, printing out on serial monitor (baud rate 9600).

2.We can test out the 16-bit encoding of each button on the infrared remote control by source code. Or you can see the button encoding chart shown above.


Extension Practice:
1.Making the LED panel show different patterns by infrared remote control.
428-pro5-6.png

2.Driving the 2 motors’ turning direction and speed by infrared remote control.
(refer to project 8- motor driving) Combine infrared receiver and motors driving knowledge to build an infrared remote control car.
428-pro5-7.png



Project 6: Bluetooth Module

keyestudio HM-10 Bluetooth-4.0 V3

Description:
Bluetooth technology is a wireless standard technology that enables short-distance data exchange between fixed devices, mobile devices, and building personal area networks (using UHF radio waves in the ISM band of 2.4 to 2.485 GHz).
The Keyestudio HM-10 Bluetooth-4.0 V3 Module is a master-slave machine. When use as the Host, it can send commands to the slave actively; when use as the Slave, it can only receive commands from the host.
The HM-10 Bluetooth module supports the Bluetooth 4.0 protocol, which not only supports Android mobile, but also supports iOS system.


Technical Details:

  • 1)Bluetooth protocol: Bluetooth Specification V4.0 BLE
  • 2)No byte limit in serial port Transceiving
  • 3)In open environment, realize 100m ultra-distance communication with iphone4s
  • 4)USB protocol: USB V2.0
  • 5)Working frequency: 2.4GHz ISM band
  • 6)Modulation method: GFSK(Gaussian Frequency Shift Keying)
  • 7)Transmission power: -23dbm, -6dbm, 0dbm, 6dbm, can be modified by AT command.
  • 8)Sensitivity: ≤-84dBm at 0.1% BER
  • 9)Transmission rate: Asynchronous: 6K bytes ; Synchronous: 6k Bytes
  • 10)Security feature: Authentication and encryption
  • 11)Supporting service: Central & Peripheral UUID FFE0, FFE1
  • 12)Power consumption: Auto sleep mode, stand by current 400uA~800uA, 8.5mA during transmission.
  • 13)Power supply: 5V DC
  • 14)Working temperature: –5 to +65 Centigrade


thumb


Pins Description:

thumb


Wiring Diagram:
connect the VCC to 5V,GND to GND, TXD to RXD, RXD to TXD.
thumb


Test Code:
When uploading the code, CANNOT connect the Bluetooth module; otherwise uploading fails!
You are supposed to upload the code to control board, then connect the Bluetooth module.


thumb


Result:
First should install the APP on the cellphone. Download the APP from the link: https://wiki.keyestudio.com/KS0455_keyestudio_HM-10_Bluetooth-4.0_V3_Compatible_with_HC-06_Pins


  • For Android APP:

APP installed well, you can see the icon thumb on your Android phone.
After wiring, upload the test code to UNO R3 board and then connect the Bluetooth module. Powered on, Bluetooth module’s built in LED flashes.
Open the Android APPthumb, click to scan device. As shown below.
thumb

Click Scan Device to search the Bluetooth.
thumb

Click the first device thumb to connect the Bluetooth.
Connected, built-in LED on the Bluetooth module is normally on. APP interface will show the state connected.
thumb

On the bar enter letter a, and click to send, APP will print out the character “keyestudio” and D13 indicator on the UNO R3 board will flash once.
Continue to send the letter a, APP prints out multiple “keyestudio” character and D13 indicator flashes.
thumb


  • For mac/iOS APP

You need to download the mac/iOS compatible APP in APP store.
First we enter the APP store, search hm10, and select the hm10 bluetooth serial lite.
thumb


Click to install the APP, as shown below.
thumb


APP installed well, a Bluetooth iconthumb will pop up on your phone. Click to enter the APP.

Upload the test code to control board successfully, then plug in the Bluetooth module.
Open the Bluetooth APP, click thumb to start searching and pairing the Bluetooth module. Click thumbto start connecting HM-10 Bluetooth module.
Connected, the built-in LED on the Bluetooth module will be from quick flash to normally on.

thumb

On the input bar enter a letter a, and click to send, APP will print out the character “keyestudio” and D13 indicator on the UNO R3 board will flash once.
Continue to send the letter a, APP prints out multiple “keyestudio” characters and D13 indicator flashes.
thumb



Project 7: Adjusting Servo Angle

Servo


Introduction:
Servo motor is a position control rotary actuator. It mainly consists of housing, circuit board, core-less motor, gear and position sensor.
Included with your servo motor you will find a variety of black mounts that connect to the shaft of your servo.
You may choose to attach any mount you wish for the circuit. It will serve as a visual aid, making it easier to see the servo spin.

Working principle:
The receiver or MCU outputs a signal to the servomotor. The motor has a built-in reference circuit that gives out reference signal, cycle of 20ms and width of 1.5ms. The motor compares the acquired DC bias voltage to the voltage of the potentiometer and outputs a voltage difference.

Servo motor comes with many specifications. But all of them have three connection wires, distinguished by brown, red, orange colors (different brand may have different color).
Brown one is for GND, red one for power positive, orange one for signal line.

thumb

The rotation angle of servo motor is controlled by regulating the duty cycle of PWM (Pulse-Width Modulation) signal. The standard cycle of PWM signal is 20ms (50Hz).
Theoretically, the width is distributed between 1ms-2ms, but in fact, it's between 0.5ms-2.5ms. The width corresponds the rotation angle from 0° to 180°.
But note that for different brand motor, the same signal may have different rotation angle.

thumb


Parameters:

  • Operating voltage: DC 4.8V〜6V
  • Angle range: about 180°(in 500→2500μsec)
  • Pulsewidth range: 500→2500μsec
  • No-load speed: 0.12±0.01 sec/60(DC 4.8V);  0.1±0.01 sec/60(DC 6V)
  • No-load current: 200±20mA(DC 4.8V);  220±20mA(DC 6V)
  • Stop torque: 1.3±0.01kg/cm(DC 4.8V);  1.5±0.1kg/cm(DC 6V)
  • Stop current: ≦850mA(DC 4.8V);  ≦1000mA(DC 6V)
  • Standby current: 3±1mA(DC 4.8V);  4±1mA(DC 6V)
  • Operation temperature: -10℃〜50℃
  • Save temperature: -20℃〜60℃
  • Motor wire length: 250 ± 5 mm


Connection Diagram:
Connect the servo pin to digital pin 9

thumb


Sample Code:
We can set the HIGH/LOW for corresponding pins in the Mixly blocks software, so as to adjust the servo angle; furthermore, we specially create the robot library, so easy to control the servo angle with simplified code.


Code 1: without the library
To get better understand of specific working principle of servo, need to set up a variable for the servo pulsewidth and initialize the initial value of the pulsewidth to 0.
Click “Variables”, drag out the blockP10-1.png; and drag the blockP10-2.png from “Math” into the block P10-1.png; change “item”into“pulsewidth”and assign the value to 0.
Go to “Control”, drag out the block 0464-pro8图4.png and drag the block0464-pro8图5.png into setup .

A variable is like a box, and a new variable is like making a box; we can give the box a name, like we just called it “pulsewidth”. The things placed inside the box can be changed, like we can place oranges, apples, pears, etc.
The function of the variable box in this program is to load the servo pulsewidth value. With this box called “pulsewidth”, we can store the pulsewidth value received by servo in it. So every time I mention pulsewidth, it refers to the servo pulsewidth at that time.

The servo is connected to digital pin 9 and initial angle value is 90°. Go to “Functions” , drag out the block0464-pro8图6.png, then click the blue gear icon, appear the edit box, drag the0464-pro8图7.png block into 0464-pro8图8.png twice; respectively change ‘x’ to servopin and myangle. Get the block like this: 0464-pro8图9.png
And again go to “Functions” , drag out the block0464-pro8图10.png; then go to “Math” , drag out the block P10-2.png twice and into the block0464-pro8图10.png.

Set the servo pin to digital pin 9; angle to 90.
thumb

Due to the rotation Angle of servomotor is by adjusting the duty cycle of PWM (pulse width modulation) signal. Pulse width modulation, the width, not the width of the object, but a high level (active) signals in a cycle of the length of duration. The larger the duty cycle, the wider the pulse width.
In fact, the pulse width is between 0.5ms and 2.5ms, corresponding to the servo Angle between 0°and 180°.

Go to “Control”, drag out the block 0464-pro8图12.png and into the block0464-pro8图9.png. The variable "i" is unchanged. Take 50 pulses of the servo (i.e. 50 square wave signals) as an example, changing from 0 to 50 step 1.

Click “Variables”, drag the block 0464-pro8图14.png into the block0464-pro8图12.png and go to “Math”, drag out the block 0464-pro8图15.png and duplicate once to make as 0464-pro8图16.png, then drag this block into the pulsewidth block0464-pro8图14.png ; change the first “+” to“×”. Click “Variables”, drag the block 0464-pro8图18.png into the first box 1 and change the second box 1 to 11, the third box 1 to 500. So get the block like this:0464-pro8图19.png

Through the formula implicit in this code block, we can calculate the pulse width using the servo Angle.

Go to “IN/OUT”, drag out the block0464-pro8图20.png; and click “Variables”, drag the block 0464-pro8图18.png into the pin box, and set to Stat HIGH.
Drag out the delay block0464-pro8图22.png and drag a variable block 0464-pro8图23.png into the delay block; change the Milliseconds to microseconds.
0464-pro8图24.png

The pulsewidth in this code block is the high-level time set in the servo signal at 90°in one pulse period, with unit of microsecond, and sends 50 square wave signals, each of which has a high-level time of 1490 (90*11+500) microseconds.


thumb

Next duplicate this piece of block0464-pro8图24.png once; set to LOW and click the drop-down triangle to select ms.
Go to “Math” , drag out the block 0464-pro8图15.png and duplicate once to make as 0464-pro8图16.png , replacing the block0464-pro8图29.png .
The period of the standard PWM (Pulse Width Modulation) signal is fixed at 20ms.

Change the second box 1 to 20; change the first“+” to“-”; duplicate the block 0464-pro8图29.png into second box 1, replacing 1. change the second“+” to“÷”; change the third box 1 to 1000. So get the block like this: 0464-pro8图30.png

The pulsewidth in this code block is the low-level time set in the servo signal at 90°in one pulse period, with unit of microsecond, and sends 50 square wave signals, each of which has a low-level time of 18.51 (20-1490/1000) microseconds.

Upload the complete code to see the result!


thumb


Code 2: using the library
Click “Small_Turtle_Robot”,drag out the servo block0464-pro8图31.png; go to “Control”, drag out the block 0464-pro8图22.png and set to delay 500ms.
Duplicate the code string once and set the angle to 180.

thumb


Test Result:
Upload the Code 1 success, turn the slide switch to right position. The servo motor will rotate to 90 degrees.
Upload the Code 2 success, turn the slide switch to right position. The servo motor will rotate back and forth from 0°to 180°.



Little Knowledge:
1.In the code 1, we direct regulate the servo angle by servo control principle.
0428图片73.png this piece of block is to set the procedure; connect the servo signal pin to D9 and set the servo angle to 90°

2.For procedure code, send 50 square signals; Each square signal has a HIGH level time of 1490 (90*11+500) microseconds; LOW level time of 18.51 (20-1490/1000) milliseconds.
thumb

3.In the code 2, we direct use the library to set the servo angle. Set the servo signal pin to D9.



Extension Practice:
1.Refer to the servo regulation principle and code1 method. Try rotating the servo angle to 0°, 45°and 180°

Example Code 1:
thumb

Example Code 2:
thumb

Example Code 3:
thumb


2.Set the servo angle with library. Make the servo angle first turn gradually from 0°to 180°, then rotate from 180°to 0°gradually, alternately and circularly.
thumb


Project 8: Motor Driving and Speed Control

keyestudio L298P motor shield


Introduction:
There are many ways to drive the motor. Our tank robot uses the most commonly used L298P solution. L298P is an excellent high-power motor driver IC produced by STMicroelectronics. It can directly drive DC motors, two-phase and four-phase stepping motors. The driving current up to 2A, and output terminal of motor adopts eight high-speed Schottky diodes as protection.

We have designed the motor driver shield based on the L298P circuit.
When using, just simply stack L298P motor shield onto UNO R3 board, or stack the sensor shield V5 onto L298P motor shield and connect the sensor modules to the sensor shield.

When power the motor shield with an external voltage DC 7-12V, face up the slide switch, turn the switch to left position, turning off the voltage; turn the switch to right position, supplying power to the motor drive shield, UNO R3 and V5 sensor shield, easy and simple.

For software, we can set the HIGH or LOW to corresponding pin or set the PWM value, to control the rotating direction and speed of 2 motors, thus navigate the robot motions. Furthermore, we create the robot library to drive the robot, more simple and easy to play.


Parameters:

  • 1)Control chip: L298P
  • 2)Logic part input voltage: DC5V
  • 3)Driving part input voltage: DC 7-12V
  • 4)Logic part working current: <36mA
  • 5)Driving part working current: <2A
  • 6)Maximum power dissipation: 25W (T=75℃)
  • 7)Working temperature: -25℃~+130℃


thumb


Motor Driving:
Stack the motor shield onto UNO R3 and connect the 2 motors. Refer to the below table settings. We can control the robot motion by driving the 2 motors via digital pin and PWM pin.
The PWM value is in the range of 0-255. The greater the value, the faster the motors turn.

thumb


Hookup Guide:
Note: the 4Pin terminal block is marked with silkscreen 1234. The red line of right rear motor is connected to terminal block 1, black line should connect to terminal block 2. The red line of left front motor is connected to terminal block 3, black line should connect to terminal block 4.
thumb


Coding:
Code 1: without the library
Navigate the tank robot to go front for 2 seconds, backward for 2 seconds, rotate to left for 2 seconds, rotate to right for 2 seconds, stop for 2 seconds.
We go to write the code for the left and the right motor to turn forward.

Go to “In/Out”, drag out the block P6-1.png and P6-2.png; separately duplicate these two blocks once, set to digital pin 13 and pin 12; change the analog pin 3 to pin 11 and pin 3. Pin 13 and pin 12 set to LOW; assign both pin11 and pin 3 value to 200.
Next go to drag out the block P6-3.png from “Control”, and set to 2000ms.
thumb

So now we complete the code for robot turning forward for 2 seconds.

Next move on to write the code for robot turning back, rotating to the left, rotating to the right and stop.
Duplicate the finished code string above three times;
Set the pin 13 and pin 12 to HIGH, assign both pin 11 and pin 3 value to 200, so that both the left and the right motor will turn backward, thus the robot will turn back.
thumb

Set the pin 13 to HIGH and pin 12 to LOW , assign both pin 11 and pin 3 to 200, so that the left motor turns back and the right motor turns front, thus the robot will rotate to the left.
thumb

Set the pin 13 to LOW and pin 12 to HIGH, assign both pin 11 and pin 3 to 200, so that the left motor turns front and the right motor turns back, thus the robot will rotate to the right.
thumb

Go to “In/Out” again, drag out the blockP6-2.pngand duplicate once, set to pin 3 and pin 11, assign the value 0; then add a delay block 2000ms.

Upload the complete code to see the final result!
thumb


Code 2: using the library
Click the “Mini_Tank_Robot” , drag out the block 428-pro8图11.png and set to PWM200; so the robot will move front at a speed of PWM200.
This block428-pro8图12.png has the same function as the string block 428-pro8图13.png.
Next go to drag out the block P6-3.png from “Control” , and set to 2000ms.
Click the “Mini_Tank_Robot” , drag out the block428-pro8图15.png,428-pro8图16.png ,428-pro8图17.png and 428-pro8图18.png; set to PWM200; respectively add a delay block in 2000ms.


thumb


Test Result:
Upload the code success, turn the slide switch to the right position.
The robot will go forward for 2 seconds, backward for 2 seconds, then rotate to left for 2 seconds, rotate to right for 2 seconds, stop for 2 seconds, alternatively and circularly.



Little Knowledge:
1.Both Code1 and Code2 has the same function. You can open the Mixly window to check out the C language code.
thumb

2.The PWM value is in the range of 0-255. The greater the value we set, the faster the motors turn.



Extension Practice:
1.Refer to the motor driving logic and code set; try to reset a new moving track for your smart car.
For example, we set a new program for tank robot moving at a speed of PWM150.
The tank robot goes backward for 2 seconds, forward for 4 seconds, rotate to right for 2 seconds, rotate to left for 3 seconds, forward for 2 seconds then back for 0.5 second, stop for 1 second, alternatively and circularly.

thumb




Get Started with Robot Projects

After learn the basic knowledge of robot hardware, now get ready to give the tank robot capability to conquer everything!
thumb

Let’s assemble all the tank robot parts together! It’s time up to build your own amazing tank robot.


Project 9: Tank Robot Installation

0428图片4.png

At the first glance of the tank robot packaging, all parts is neatly and completely placed in the box.
Great! follow the steps below to get started with installing this amazing tank robot!


Step 1:install the tank bottom motor

Prepare the parts as follows:

  • M4*12MM inner hex screw * 2
  • M3*8MM inner hex screw * 4
  • M4 nut * 2
  • Blue supporting parts *2
  • Metal holder *2
  • Copper Coupler *2
  • Metal Motor *2
  • L-type M1.5 inner hex wrench *1
  • L-type M2.5 inner hex wrench *1
  • L-type M3 inner hex wrench *1


To begin with, separately fix a blue supporting part onto a metal holder using a M4*12MM screw and a M4 nut. use the L-type M3 inner hex wrench to screw up. Pay more attention to the punch hole.

thumb

thumb

Then screw the Copper Coupler to the metal DC motor. note that each Copper Coupler comes with a M3*4MM set screw. You should first screw out the M3*4MM set screw inside the Copper Coupler with a L-type M1.5 inner hex wrench. And then mount the two Copper Couplers to 2 metal DC motors and screw up with the two M3*4MM set screws.
thumb

After that, separately mount metal DC motor onto metal holder with four M3*8MM inner hex screws. use the L-type M2.5 inner hex wrench and self-prepared wrench to screw up.See details below.
thumb

Finally, you can get the bottom motor holder shown below.
thumb


Step 2:install the tank driver wheel

Prepare the parts as follows:

  • M4*12MM inner hex screw * 1
  • M4*50MM inner hex screw * 1
  • Tank Load-bearing wheel * 2
  • Flange Bearing * 2
  • Copper bush *2
  • Caterpillar Band *2
  • M4 self-locking nut * 2
  • L-type M3 inner hex wrench *1


Mount the Tank Load-bearing wheel into the metal DC motor using a M4*12MM inner hex screw. And use L-type M3 inner hex wrench to screw up.Shown below.
thumb

Then connect the tank loading-bearing wheel, copper bush, flange bearing and M4*50MM inner hex screw.
thumb

After that, you will get the parts below.
thumb

Fix the tank loading-bearing wheel, Caterpillar Band with the flange bearing and M4 self-locking nut. And use L-type M3 inner hex wrench and self-prepared wrench to screw up M4 self-locking nut.
thumb

More details is showed below:
thumb

Finally you should get the complete tank wheel below.
thumb

thumbthumb


Step 3: install the battery case

Prepare the parts as follows:

  • M3*10MM flat-head screw * 2
  • M3 nut * 2
  • Battery case *1
  • Blue Metal holder *2
  • M4*40MM inner hex screw *4
  • M4 nut *4
  • L-type M2.5 inner hex wrench *1
  • L-type M3 inner hex wrench *1
  • M3*25MM inner hex screw *4
  • M3*45MM dual-pass cooper pillar *4


Fix the battery case onto the metal holder with two M3*10MM flat-head screws and two M3 nuts. And use the L-type M2.5 inner hex wrench and self-prepared wrench to screw up the M3*10MM flat-head screws and M3 nuts.
thumb

Finish the above part. Go to fix the metal holder on the motor wheel with four M4*40MM inner hex screw and four M4 nut.
thumb

You should mount the metal holder connected with a battery case on the blue supporting parts with four M4*40MM inner hex screws.
thumb

Then should mount another metal holder on the back with four M4 nuts. And use the L-type M3 inner hex wrench and self-prepared wrench to screw up the M3*10MM flat-head screws and M3 nuts.
thumb

thumb

Finally screw four M3*25MM inner hex screws and M3*45MM dual-pass copper pillars onto the blue supporting parts. And use the L-type M2.5 inner hex wrench to screw up the M3*25MM inner hex screws and M3*45MM dual-pass copper pillars.
thumb

thumb


Step 4: mount the sensor module

Go to mount the acrylic case and sensor modules.
Prepare the parts as follows:

  • Acrylic top plate * 1
  • M3*8MM inner hex screw * 4
  • M3*10MM dual-pass copper pillar *4
  • M2*11MM dual-pass copper pillar *4
  • M2*10MM round-head screw * 4
  • L-type M2.5 inner hex wrench *1


Screw the M3*8MM inner hex screw and M3*10MM dual-pass copper pillar to the acrylic top plate.
And screw the M2*10MM inner hex screw and M2*11MM dual-pass copper pillar to the acrylic top plate. And use the L-type M2.5 inner hex wrench to screw up.
thumb

thumb


Go to mount the IR receiver module on the acrylic case. Prepare the parts as follows:

  • M3*8MM inner hex screw * 1
  • M3*12MM round-head screw * 2
  • M3 nickel plating nut *5
  • L-type holder *1
  • IR receiver module *1
  • 3pin F-F jumper wire*1
  • Acrylic plate * 1
  • Screwdriver * 1
  • self-prepared wrench

thumb

To begin with, fix the L-type holder on the Acrylic plate with 2 M3*12MM round-head screws and 2 M3 nickel plating nuts. then use the screwdriver and self-prepared wrench to screw up the accessories.
0428-4-5.png0428-4-6.jpg
thumb


Connect the jumper wire to IR receiver module(black wire to pin“-”,red to“+”,yellow to “S”), and screw the IR receiver module on the Acrylic plate with a M3 nickel plating nut and a M3*8MM inner hex screw.then use the L-type M2.5 inner hex wrench and self-prepared wrench to screw up the accessories.
thumbthumb


Then install L-type holder on the acrylic plate using 2 M3*12MM round-head screws and 4 M3 nickel plating nuts.
thumbthumb
thumbthumb


Next go to mount the 2 photocell modules and 8X16 LED panel on the acrylic plate. Prepare the parts as follows:

  • Photocell module * 2
  • 8X16 LED panel *1
  • Acrylic plate * 1
  • M3 nickel plating nut *2
  • M3*12MM round-head screw * 2
  • M2*10MM inner hex screw *4
  • M2 nickel plating nut *4
  • HX-2.54 4P female head jumper wire *1
  • Screwdriver * 1
  • self-prepared wrench

thumb

Fix the 2 photocell modules on the acrylic plate parts with 2 M3*12MM round-head screws and 2 M3 nickel plating nuts.then use the screwdriver and self-prepared wrench to screw up the accessories.
thumbthumb

Mount a 8X16 LED panel on the acrylic plate using 4 M2*10MM round-head screw and 4 M2 nickel plating nuts. then use the screwdriver and self-prepared wrench to screw up the accessories. And connect the HX-2.54 4P jumper wire.
thumb

thumbthumb


Step 5: install the servo plastic platform

Prepare the parts as follows:

  • Servo motor *1
  • Plastic platform parts *1


Note: before install the servo platform. For convenient debugging, you should make sure that the ultrasonic module is facing the front of the tank, and the servo motor’s angle is 90°.
To begin with, we need to set the servo to 90° before installing the servo platform.

thumb

Stack the sensor shield onto the UNO R3 board, then connect the servo motor mounted with white mount to the sensor shield.
(Brown one is for GND, red one for power positive, orange one for signal line)
Connected well, open the Mixly software and upload the test code below to rotate the servo to 90°. (note: before upload the code, need to add the library first)

thumb

For more details, you can refer to Robot Lesson 2 Servo angle control.
You can refer to the detailed Mixly use mentioned in the following section.
thumb


The servo angel is successfully adjusted to 90°.
Next you can start to install the servo plastic platform right now.
thumb

Mount the white cross on the black base plate using four M1.2*5MM self-tapping screws(inside the plastic platform bag).
thumb

Then fix the servo motor on the white cross with a self-tapping screw. Pay more attention to the servo angle in 90° facing front.
thumb

Show details as below:

thumb

After that, fix the both side parts on the servo base plate with two self-tapping screws. Congrats you complete it.
thumb

Show details as below:

thumb


After that, mount the ultrasonic module to the servo platform with black cable ties. Shown below.
thumbthumb

thumb


Step 6: install all the Acrylic plate parts

Install all the Acrylic plate parts and ultrasonic servo platform.
Prepare the parts as follows:

  • M3*12MM round head screw *2
  • M3 nickel plating nut *2
  • M2*5MM round head screw *4
  • Screwdriver *1
  • self-prepared wrench

thumb


Mount the ultrasonic servo platform to the bottom Acrylic plate with 4 M2*10MM round head screws.then use the screwdriver and self-prepared wrench to screw up the accessories.
Pay close attention to servo angle; ensure that the servo angle is in 90° facing front.

thumb

Then screw the 8x16 LED matrix acrylic plate on the to the bottom Acrylic plate with 2 M3*12MM round head screws and 2 M3 nickel plating nuts.
thumb

thumb




Step 7: Complete tank parts and control board

Install all the complete tank parts and mount the control board.
Prepare the parts as follows:

  • M3*6MM inner hex screw *8
  • L298P motor drive shield *1
  • UNO R3 *1
  • V5 sensor shield *1
  • 3pin jumper wire *2
  • L-type M3 inner hex wrench *1


Mount the Acrylic part onto tank bottom wheel part with 4 M3*6MM inner hex screws.then use the L-type M3 inner hex wrench to screw up.
thumb

The connection wires should pass through the holes on Acrylic plate.
thumb

thumb

After that, mount the control board on the tank robot Acrylic plate.
thumb

First connect the jumper wire to the 2 photocell modules
thumb

Install the UNO R3 board onto the acrylic plate with four M3*6MM inner hex screws.
Then stack the L298P shield onto the UNO R3 board and stack the V5 sensor shield onto L298P shield.
thumb



Hookup Guide

Connect well all the sensor modules to the control board.
thumb


Connect the battery case and DC motor to the L298P shield.

The black lead of battery case is connected to negative end “-”; red lead is connected to positive end “+”;

The 4Pin terminal block is marked with silkscreen 1234.

The red line of right rear motor is connected to terminal block 1, black line should connect to terminal block 2.
The red line of left front motor is connected to terminal block 3, black line should connect to terminal block 4.

thumbthumb

thumb


Congrats! complete the tank robot installation.
Begin with the following robot projects, should first upload the test code successfully, then plug in the Bluetooth module; otherwise, the code upload will fail.

thumb

Note that you can use a black winding line to make the wires look better and neat.
The tank robot is installed well. Learn the robot projects to give your tank robot the powerful capability.


Project 10: Light Follow Tank

0428图片113.png


Circuit Design:
We can combine the hardware knowledge -- photoresistor module, motor driving, to build a light following robot!
In the circuit process, we use 2 photoresistor modules to detect the light intensity at the both side of robot. Read the analog value to rotate the 2 motors, thus drive the tank robot run.

The specific logic of light following robot is shown as the table below:
0428图片114.png


Based on the circuit design, we can start building our own light following tank robot.
Follow the wiring diagram and test code below.


Hookup Guide:
0428图片115.png

Note: the 4Pin terminal block is marked with silkscreen 1234.
The red line of right rear motor is connected to terminal block 1, black line should connect to terminal block 2.
The red line of left front motor is connected to terminal block 3, black line should connect to terminal block 4.
Connect the left photocell sensor (-, +, S) to sensor shield (G(GND)、V(VCC)、A1); the right photocell to sensor shield (G(GND)、V(VCC)A2).


Coding:
The left and the right photocell sensors have been connected well.
We can design the program to read the photosensitive light change of photocell sensors via serial port.
So we can use the block 0428图4.png or 0428图5.png, printing out the contents on the serial monitor.
Because there are two photocell sensors, we first build two variables to separately store the light intensity measured by both photocell sensors.

Go to “Variables”, drag out the block 0428图6.png; and go to “Math”, drag the block 0428图7.pnginto the block 0428图6.png. Then duplicate this code block once, and separately change the “item” into “left_light” and “right_light”.
0428图9.png

In this way, we have built the variable blocks 0428图10.png and 0428图11.png.
Go to “Variables”, drag out the block 0428图12.png; and go to “Mini_Tank_Robot”, drag the block 0428图13.pnginto the block just made. 0428图14.png
Then duplicate this code block once, and change left_light into right_light; click the drop-down triangle to select the right_light_sensor. 0428图15.png

Go to “SerialPort”, drag out the block 0428图16.png; and drag the block 0428图17.png from “Text” into the Serial print block and change the “hello” into “left_light_value=”; then go to “SerialPort”, drag out the block 0428图19.png; and drag the block 0428图10.png from “Variables” into the Serial printIn block just made.

0428图-1.png

Duplicate this piece of code block once and change the “left_light_value=” into “right_light_value=”; “left_light” to “right_light”
To make the data refresh slowly, we add a delay block 0428图22.png from “Control” and set to 500ms.
Don’t forget to add setup and Serial baud rate 9600!

Go to “Control” , drag out the setup blockP5-1.png; and drag out the block P5-2.png into the setup block you just made. Then drag the block 0428图25.png and 0428图26.png beneath the Serial baud rate 9600 block.
0428图-2.png

If both the left and the right photocell sensors meet the conditions of left_light>650 and right_light>650, tank robot will go front at a speed of PWM200;
If both the left and the right photocell sensors meet the conditions of left_light>650 and right_light≤650, tank robot will rotate to left at a speed of PWM200;
If both the left and the right photocell sensors meet the conditions of left_light≤650 and right_light>650, tank robot will rotate to right at a speed of PWM200;
If both the left and the right photocell sensors meet the conditions of left_light≤650 and right_light≤650, tank robot will stop moving.

Here we can use the condition statement0428图-3.png
Go to “Control”, drag out the blockP3-13.png, then click the blue gear icon, appear the edit box, drag the block 0428图-4.png into Pro8-图片15.png block. So you can get the block0428图-3.png .

Due to four conditions we mentioned above, we again go to drag the block 0428图-4.png into the block P3-13.png once and then drag0428图-5.png beneath the 0428图-4.png.

Next, go to the “Logic” , drag out the block P3-20.png and select “>”, then drag out the block0428图10.png from the “Variables” into the first input box at the left side of “>” ; drag thePro8-图片20.png from the “Math” into the second input box at the right side of “>” and change the value to 600; like this:0428图33.png
We duplicate this block once, and drag out the block0428图34.png, replacing the0428图10.png .
And again go to the “Logic” , drag out the blockP3-25.png into the if statement; respectively drag the block0428图33.png and 0428图38.png into the input box of blockP3-25.png.
0428图40.png

Drag out the block0428图-6.png from “Mini_Tank_Robot” into the do statement,and set to PWM200.
0428图-7.png

Next duplicate the block 0428图-8.png once and drag it into else if statement; change to “right_light≤650”
Drag out the block0428图-9.png from “Mini_Tank_Robot” into the do statement, and set the value to PWM200.
Duplicate the block 0428图-8.png once again and drag it into the second else if statement; change to “left_light≤650”
Drag out the block0428图-11.png from “Mini_Tank_Robot” into the do statement, and set the value to PWM200.
Finally drag out the block0428图-12.png from “Mini_Tank_Robot” into the else statement.
0428图-13.png

We’ve written well the program for tank robot to track the light!
Upload the program and change the ambient light intensity to see the moving result.
0428图-14.png
Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.



Result:
Upload the code success to UNO R3 board; turn the slide switch to right position.
The mini tank robot will walk along the light.




Project 11: Ultrasonic Follow Tank

0428图片118.png


Circuit Design:
We combine the hardware knowledge -- LED panel, motor drive, ultrasonic and servo, to build an ultrasonic follow robot!
In the circuit process, we can make use of ultrasonic sensor to detect the distance between tank robot and front obstacles. Control the motor rotating by measured data, thus control the tank robot motion.

The specific logic of ultrasonic follow robot is as shown below:
0428图片119.png


Based on the circuit design, we can start building our own ultrasonic following tank robot.
Follow the wiring diagram and test code below.


Hookup Guide:
0428图片120.png

Note: Stack the V5 sensor shield onto motor drive shield, then stack them on UNO R3 board.
The 4Pin terminal block is marked with silkscreen 1234. The red line of right rear motor is connected to terminal block 1, black line should connect to terminal block 2. The red line of left front motor is connected to terminal block 3, black line should connect to terminal block 4.
Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication.
Connect the ultrasonic sensor to sensor shield V5, VCC pin to 5V(V), Trig pin to digital 5 (S), Echo pin to digital 4 (S), GND pin to GND(G).
Connect the servo motor to motor drive shield (G(GND)、V(VCC)、9). Brown line is for GND, red one for 5V, orange one for digital pin 9.



Coding:
Now write the program to build an ultrasonic following robot.
First set up and initialize the servo angle to 90°,8x16 LED panel displays a pattern “V”after screen clear.
Go to “Control” , drag out block0464-pro3图13.png; and drag out the block 0428-图21.png from “Serial Port” into the setup block. Then go to “Mini_Tank_Robot” , drag and drop the blockKs0464-36.png and 0428-图23.png into setup block; set the servo angle to 90° ; click the drop-down triangle to choose “clear”.
Go to “Control” , drag out block 0428-图24.png and set to delay 200ms. And again drag out the block 0428-图23.png beneath the delay block.

0428-图25.png


Next build a distance variable block.
Click “Variables” , drag out the blockPro8-图片4.png; and drag the block P10-2.png from “Math” into the value behind like Pro8-图片6.png; change “item” into “distance” and assign to value 0. So that already build a variable 0428-图24.png.
Click “Variables” , drag out the blockPro8-图片7.png; and drag the block Pro8-图片9.png from “Mini_Tank_Robot” into the distance block to make as Pro8-图片10.png .

Judge the distance of front obstacle measured by ultrasonic sensor.
Here we can use the judgement statement “if...do...else if...do...else if...do...else...” .
First when the front obstacle distance detected by ultrasonic sensor is greater than and equal to 20cm, and smaller than and equal to 60cm, the robot will go front at a speed of PWM200.

Go to “Control”, drag out the blockP3-13.png, then click the blue gear icon, appear the edit box, drag the block 0428图-4.png into Pro8-图片15.png block twice and then drag0428图-5.pngblock beneath the 0428图-4.pngblock. So you can get the block:Pro8-图片17.png .

Go to “Logic”, drag out the blockP3-20.png and select “≥”; go to “Variables” , drag out the block Pro8-图片13.png into the first input box at the left side of “≥”; drag the Pro8-图片20.png from the “Math” into the second input box at the right side of “≥” ; change the value 0 to 20; like this:0428-图37.png (note you can type the value flexibly.)
We duplicate the block0428-图37.png once, and change to “distance≤60” .

Think back, we use a word “and ” when describe the judgement statement. There is a block in “Logic” to represent both conditions happen at the same time, that is,P10-24.png, to judge the distance from 20 to 60cm.
So we drag the block “distance≥20” and “distance≤60” into the blockP10-24.png and drag the block 0428-图39.png into the if statement.
Followed by drag out the block0428-图40.pngfrom “Mini_Tank_Robot” into the do statement; change the PWM0 into PWM200.


0428-图41.png

Till now, we have completed the program when the front obstacle distance detected by ultrasonic sensor is greater than and equal to 20cm, and smaller than and equal to 60cm, the robot will go front at a speed of PWM200.

Next we move on to write the program. When the front obstacle distance detected by ultrasonic sensor is greater than 10cm and smaller than 20cm, or smaller than 60cm, the robot will stop moving. If the measured distance is smaller than and equal to 10cm, the robot will go back at a speed of PWM200.

We just duplicate the block0428-图42.png once and drag it into the else if statement. And set to “distance>10” and “distance<20” .
Followed by drag out the block 0428-图43.png from “Mini_Tank_Robot” into the do statement.
And duplicate the blockPro8-图片33.png once and drag it into the second else if statement. Set to “distance≤10”.
Followed by drag out the block 0428-图45.pngfrom “Mini_Tank_Robot” into the do statement and set to PWM200.
And again go to duplicate the block0428-图43.png once and drag into the else statement.


0428-图47.png

Now complete the code for ultrasonic following robot. Upload the complete code to operate your tank robot!

Code:
Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.

0428-图48.png


Result:
Upload the code success to UNO R3 board; turn the slide switch to right position.
The servo motor rotates to 90°and 8X16 LED panel shows the icon “V”.
The mini tank robot will walk along the front obstacle.



Project 12: Ultrasonic Avoiding Tank


Circuit Design:
We combine the hardware knowledge -- LED panel, motor drive, ultrasonic and servo, to build an ultrasonic avoiding robot!
In the circuit process, we can make use of ultrasonic sensor to detect the distance between tank robot and front obstacles. Control the motor rotating by measured data, thus control the tank robot motion.

The specific logic of ultrasonic avoiding robot is as shown below:
0428图50.png

0428图51.png


Based on the circuit design, we can start building our own ultrasonic avoiding tank robot.
Follow the wiring diagram and test code below.


Hookup Guide:
0428图片124.png


Code:
Now write the program to build an ultrasonic avoiding robot.

Here need to set up three variables.

Click “Variables”, drag out the block P10-1.png; and drag the blockPro10-图片29.png from “Math” into the block P10-1.png; duplicate twice and respectively change “item” into“a”, “a1”, “a2”.

So we can get the variables Ks0464-87.png, Ks0464-88.pngand Ks0464-89.png.

The variable Ks0464-87.pngstores the front obstacle distance measured by ultrasonic sensor when the servo is at 90°;
The variable Ks0464-88.pngstores the left obstacle distance measured by ultrasonic sensor when the servo is at 160°;
The variable Ks0464-89.pngstores the right obstacle distance measured by ultrasonic sensor when the servo is at 20°.
Need to initialize the variable“a”“a1”“a2”value to 0 and drag into setup block.

Go to “Control”, drag out block0464-pro3图13.png; then go to drag the block Ks0464-313.png,Ks0464-314.png and Ks0464-315.png into setup block; click “Mini_Tank_Robot”, drag out the block Ks0464-36.pnginto setup block and set the servo angle to initial 90.

图片a5.png

Click “Variables”, drag out the block Ks0464-104.png; and drag the block P10-8.png from“Mini_Tank_Robot”into the block just made.
In such way, store the front obstacle distance measured by ultrasonic sensor.

Next judge whether the front obstacle distance measured by ultrasonic sensor is smaller than 20cm, or else greater than and equal to 20cm.

Here we can use the judgement statement “if...do...else...”.

Go to “Control”, drag out the blockPro8-图片14.png , then click the blue gear icon, appear the edit box, drag the Ks0464-93.pngblock into Pro8-图片15.pngblock. So you can get the block P3-14.png.

Go to “Logic”, drag the block P3-20.png into the if statement and select“<”; go to “Variables”, drag out the block Ks0464-87.pnginto the first input box at the left side of “<”; drag the Pro8-图片20.pngfrom the “Math” into the second input box at the right side of “<” ; change the value 0 to 10; like this:Ks0464-377.png

If the distance is smaller than 20cm, tank robot will stop moving for 1000ms; then set the servo angle to 160°, read the a1, delay 500ms; set the servo angle to 0°, read the a2, delay 500ms;


Go to “Mini_Tank_Robot”, drag out the block 图片a6.pnginto the do statement. And add a delay block 1000ms.

In order to make the ultrasonic sensor measure the distance several times in the left obstacle and in the right obstacle.

We again drag the block Ks0464-101.pnginto the do statement. Set the servo angle to 160.

Go to “Control”, drag out the block Ks0464-102.png; duplicate the block Ks0464-103.pngonce and drag it into the step block just made.
Change Ks0464-104.pngthe intoKs0464-105.png; change the variable“i”into“j”; then delay 500ms.
Ks0464-378.png

Next duplicate this piece of code block Ks0464-379.pngonce; set the servo angle 180 to 0; change the variable“j”into“k”; change the Ks0464-105.pnginto Ks0464-109.png.
Ks0464-380.png

Next in the case that the front obstacle distance measured by ultrasonic sensor is smaller than 20cm, judge whether the left obstacle distance a1 is smaller than 50cm, or the right obstacle distance a2 is smaller than 50cm.

Go to “Control”, drag out the block Pro8-图片14.pngbeneath the delay block 500ms, then click the blue gear icon, appear the edit box, drag the Ks0464-93.pngblock into Pro8-图片15.pngblock. So you can get the block P3-14.png.

Go to “Logic”, drag out the block P3-20.png and select “<”; go to “Variables”,drag out the block Ks0464-88.png into the first input box at the left side of “<”; drag the Pro8-图片20.pngfrom the “Math” into the second input box at the right side of “<” ; change the value 0 to 50.Ks0464-382.png

Duplicate this block Ks0464-382.pngonce and replace the Ks0464-88.png withKs0464-89.png.

And again go to “Logic”, drag out the block Ks0464-385.pnginto the if statement; and click the drop-down triangle to select“or”; then drag the blockKs0464-386.png and Ks0464-387.pnginto the input box of blockKs0464-388.png .
Ks0464-389.png

Next judge if the distance a1 is greater than that of a2, set the servo angle to 90°, tank robot will rotate to left for 500ms at a speed of PWM255 then go front at a speed of PWM200.

If the distance a1 is smaller than that of a2, set the servo angle to 90°, tank robot will rotate to left for 500ms at a speed of PWM255 then go front at a speed of PWM200.

Go to “Control”, drag the block Pro8-图片14.pnginto the do statement of block Ks0464-389.png,
then click the blue gear icon, appear the edit box, drag the Ks0464-93.pngblock intoPro8-图片15.png block. So you can get the block:
Ks0464-390.png

Go to “Logic”, drag the block P3-20.png into the if statement and select“>”; go to “Variables”,drag out the block Ks0464-88.png into the first input box at the left side of “>”; drag the Ks0464-89.pnginto the second input box at the right side of “>”.
Click “Mini_Tank_Robot”, drag out the block Ks0464-101.png andKs0464-392.png ; set to servo angle 90 and PWM 255.
Add a delay block 500ms. Then drag out the Ks0464-393.png and set to PWM200.
Ks0464-394.png

We duplicate this piece of code block Ks0464-395.pngonce and drag into else statement; drag out the block Ks0464-396.pngto replace the block Ks0464-397.png and set to PWM 255.
Ks0464-398.png

In the case that the front obstacle distance measured by ultrasonic sensor is smaller than 20cm, judge whether the left obstacle distance a1 is greater than and equal to 50cm, and the right obstacle distance a2 is greater than and equal to 50cm. Next randomly determine the size of distance a1 and a2.

Here should build a variable “random”.

Click “Variables”, drag out the blockKs0464-399.png ; drag the block P10-2.pngfrom “Math” into the block Ks0464-399.pngand change “item” into“random”. So can get the variable Ks0464-401.png.

First drag the block Ks0464-402.png into the setup block.
Ks0464-403.png

Click “Variables”, drag out the variable block Ks0464-404.png; drag the block Ks0464-405.pngfrom “Math” into the random block.
The random number can be set at will, in this case from 1 to 100.
We drag the block Ks0464-406.png above the block Ks0464-407.png.


We need to determine whether the random number is odd or even, if it's even, set the servo angle to 90°, tank robot will rotate to left for 500ms at a speed of PWM255 then go front at a speed of PWM200.
If the distance a1 is smaller than that of a2, set the servo angle to 90°, tank robot will rotate to right for 500ms at a speed of PWM255 then go front at a speed of PWM200.

Go to “Logic”, drag out the blockP3-20.png ; and drag out the block Ks0464-409.pngfrom “Math” into the first input box at the left side of “=”; then go to “Variables”, drag out the block Ks0464-401.pnginto the input box at the left side of “+” , replacing box 1; click the drop-down triangle to choose “%”, replacing“+”; change the second box1 to 2.
And drag the block Ks0464-411.pngfrom “Math” into the input box at the right side of“=”.
Get complete block like this:

Ks0464-412.png

We duplicate this piece of code block Ks0464-413.pngdone before once.
Just replace Ks0464-414.png with the block Ks0464-412.png. And drag them into the else statement.
Ks0464-416.png

Finally judge whether the front obstacle distance measured by ultrasonic sensor is greater than 20cm, tank robot will go front at a speed of PWM200.

Go to “Mini_Tank_Robot”, drag out the block Ks0464-393.png into the last else statement and set to PWM 200.
The program for ultrasonic avoiding function has written well.
Upload the complete code to your tank robot!

Ks0464-418.png

Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.



Result:
Upload the code success to UNO R3 board; turn the slide switch to right position.
The mini tank robot will automatically avoid the front obstacle to go ahead.
0428图片126.png


Project 13: Infrared Remote Control Tank


Circuit Design:
We combine the hardware knowledge -- LED panel, motor drive, and IR receiver, to build an infrared remote control robot!
In the IR receiver section, we’ve listed out each key value of remote control.
In this circuit design, we can set the key value in the code to navigate the tank robot movement, showing the motion state on the 8X16 LED matric panel.

The specific logic of infrared remote control robot is as shown below:
0428图52.png


Based on the circuit design, we can start building our own remote control tank robot.
Follow the wiring diagram and test code below.


Hookup Guide:
0428图片128.png

Note: Stack the V5 sensor shield onto motor drive shield, then stack them on UNO R3 board.
The 4Pin terminal block is marked with silkscreen 1234. The red line of right rear motor is connected to terminal block 1, black line should connect to terminal block 2. The red line of left front motor is connected to terminal block 3, black line should connect to terminal block 4.
Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication.
Connect the infrared receiver sensor (pin -、+、S) to the sensor shield (G(GND)、V(VCC)、A0).



Code:
Special note:
Done uploading the test code, infrared remote control CANNOT guide the tank robot move. Need to add infrared remote library again.

When an infrared receiver module matches tank robot for use, need to add the IRremote library. The robot speed is controlled by PWM pin11 and pin3.
And the PWM of pin3 and pin11 is called by timer2. But the library of infrared receiver is defaulted by using timer2. So if the IR receiver module uses default library, it will affect the PWM function of pin11 and pin3.


Adding library:

0428图片129.png

0428图片130.png


Note: must restart the Mixly software, new added library can take effect.


Coding:
Now write the program to build an infrared remote control robot.
First initialize and set the servo angle to 90, the 8x16 LED panel clears the icons then shows a “V” icon.
Go to “Control” , drag out the blockP5-1.png; and drag out the block0428-图21.png from “Serial Port” into the setup block. Then go to “Mini_Tank_Robot” , drag and drop the block 428-pro4-4.png into the setup block and duplicate once; click the drop-down triangle behind start to separately choose “clear” and “start”.
And again go to “Mini_Tank_Robot” , drag out the block 0428-图68.png into the setup block; set the servo angle to 90°.


0428-图69.png

Next, navigate the tank robot move with an IR remote control, and 8x16 LED panel will display the corresponding pattern.

We first click the imported library “Mini_Tank_Robot”, drag out the block428-pro5-1.png; drag the blockP9-4.png from “SerialPort” into the infrared receiver block just made. Then go to “Variables”, drag out the block P9-5.pnginto the blockP9-4.png.

0428-图70.png

Here we need to use the condition statementP9-11.png. Go to “Control” , drag out the blockP9-11.png.
We have listed out the string value of each key on infrared remote control.
The front keyP9-9.pngis FF629D; back key P13-11.png is FFA857; left key P13-12.png is FF22DD; right key P13-13.png is FFC23D; P13-14.pngis FF02FD; P13-15.pngis FF30CF; P13-16.pngis FF7A85.

As the command key of IR remote control is hexadecimal code, the front must add 0x.

If ir_rec=0xFF629D, press the keyP9-9.png on the IR remote control, the robot will go front at a speed of PWM200 and 8x16 LED panel displays a front “V”icon.
Go to the “Logic”, drag out the block P3-20.png into the if statement, and drag out the blockP9-16.png from the “Variables” into the first input box at the left side of “=”; drag thePro8-图片20.png from the “Math” into the second input box at the right side of “=” and type “0xFF629D” , like this:0428-图80.png.

Click the imported library “Mini_Tank_Robot”, drag out the block 0428-图81.pngand 0428-图82.png into do statement; change to PWM200 and click the drop-down triangle to choose front.
0428-图83.png.


If ir_rec=0xFFA857, press the keyP13-11.pngon the IR remote control, the robot will go back at a speed of PWM200 and 8x16 LED panel displays a back pattern.
Duplicate the code block above, change “0xFF629D” to “0xFFA857” . Then click the imported library “Mini_Tank_Robot”, drag out the block 0428-图84.png into do statement, replacing the block0428-图85.png; change to PWM200 and click the drop-down triangle to choose back.
0428-图86.png.

At the same way, if ir_rec=0xFF22DD, press the keyP13-12.png on the IR remote control, the robot will turn left at a speed of PWM200 and 8x16 LED panel displays a leftward pattern.
If ir_rec=0xFFC23D, press the keyP13-13.png on the IR remote control, the robot will turn right at a speed of PWM200 and 8x16 LED panel displays a rightward pattern.
If ir_rec=0xFF02FD, press the keyP13-14.png on the IR remote control, the robot will stop and 8x16 LED panel displays STOP pattern.
If ir_rec=0xFF30CF, press the keyP13-15.png on the IR remote control, the robot will rotate to left at a speed of PWM200 and 8x16 LED panel displays a leftward pattern.
If ir_rec=0xFF7A85, press the keyP13-16.png on the IR remote control, the robot will rotate to right at a speed of PWM200 and 8x16 LED panel displays a rightward pattern.

Duplicate the code block string above five times and respectively change to “0xFF22DD”, “0xFFC23D”, “0xFF02FD”,“0xFF30CF”, “0xFF7A85”.
Click the imported library “Mini_Tank_Robot”, respectively drag out the block0428-图87.png0428-图88.png0428-图89.png0428-图91.pngand 0428-图92.png into do statement; change to PWM200 and click the drop-down triangle to choose left、right、STOP、left、right.
0428-图93.png


Now complete the code for infrared remote control robot. Upload the complete code to navigate your tank robot!

0428-图94.png

Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.



Result:
Upload the code success to UNO R3 board; turn the slide switch to right position.
We can navigate the tank robot by IR remote control, at the same time, the 8X16 LED panel will display the motion status.
0428图片132.png




Project 14: Bluetooth Control Tank

We are now ready to give the tank robot capability -- Bluetooth remote control!
For a control smart robot, there should be a control terminal and a controlled terminal.
In the course, we use the mobile phone as the console (host), and the HM-10 Bluetooth module (slave) connected to the robot as the controlled terminal.
When using, we need to install an APP on the phone, and connect the HM-10 Bluetooth module, then we tap the buttons on the Bluetooth APP to navigate the various motion states of tank robot.

KS0193-图片88.png


Bluetooth Remote Control

Bluetooth technology is a wireless standard technology that enables short-distance data exchange between fixed devices, mobile devices, and building personal area networks (using UHF radio waves in the ISM band of 2.4 to 2.485 GHz).
The robot kit is equipped with the HM-10 Bluetooth module, which is a master-slave machine. When use as the Host, it can send commands to the slave actively; when use as the Slave, it can only receive commands from the host.
The HM-10 Bluetooth module supports the Bluetooth 4.0 protocol, which not only supports Android mobile, but also supports iOS system.

In the experiment, we default use the HM-10 Bluetooth module as a Slave and the cellphone as a Host.
We install the Bluetooth APP on the mobile phone, connecting the Bluetooth module; finally use the Bluetooth APP to control the robot move, or to control the working status of other sensor modules on the robot car.
We provide you with 2 types of mobile APP, for Android and iOS system.

In the experiment, connect the Bluetooth module by mobile Bluetooth APP, tap the front button on the Bluetooth APP to control the 8X16 LED panel displaying front image; release the button, display the “STOP”.


Parameters of HM-10 Bluetooth Module:

thumb

  • Bluetooth protocol: Bluetooth Specification V4.0 BLE
  • No byte limit in serial port Transceiving
  • In open environment, realize 100m ultra-distance communication with iphone4s
  • USB protocol: USB V2.0
  • Working frequency: 2.4GHz ISM band
  • Modulation method: GFSK(Gaussian Frequency Shift Keying)
  • Transmission power: -23dbm, -6dbm, 0dbm, 6dbm, can be modified by AT command.
  • Sensitivity: ≤-84dBm at 0.1% BER
  • Transmission rate: Asynchronous: 6K bytes ; Synchronous: 6k Bytes
  • Security feature: Authentication and encryption
  • Supporting service: Central & Peripheral UUID FFE0, FFE1
  • Power consumption: Auto sleep mode, stand by current 400uA~800uA, 8.5mA during transmission.
  • Power supply: 5V DC
  • Working temperature: -5 to +65 Centigrade


Using Bluetooth APP

  • For Android system:
0428图片138.png

1.Click the Tank_Car compression package to direct install the Tank_Car APP; installed well, appear the icon below on your mobile phone:
thumb

Download the Tank_Car package from the link below:
https://drive.google.com/open?id=18ngvrEB4I8i1s7iYhr8KdWAQ6DiMBt40


Or you can download the keyestudio Tank_Car APP direct from the Google Play:
thumb


2.Tap the Tank_Car icon to enter the Bluetooth APP. As shown below.
thumb

3.Done uploading the code to UNO R3 board, connect the Bluetooth module, the LED on the Bluetooth module will flash.
Then tap the option CONNECT on the APP, searching the Bluetooth.
thumb

4.Click to connect the Bluetooth. HMSoft connected, Bluetooth LED will turn on normally.
thumb

5.First read the character of each key on mobile APP via serial port and know the key function. Tap the button0428图片144.png, 8x16 LED panel will display the front icon. Release the button, display the “STOP”.



For iOS system:
1.Open the APP store
thumb

2.Click to search keyestudio, and you will see the keyes BT car.
thumb

3.Tap to open the keyes BT car 4.To open Bluetooth, click the “Connect” on the upper left corner, searching and connecting Bluetooth.
thumb

5.Tap the Tank_Car icon to enter the control interface.
thumb

thumb



Hookup Guide:
thumb

Note: Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication.
Direct plug the Bluetooth module to pin header (TXD, RXD, GND, 5V) on the sensor shield V5 (TX、RX、-(GND)、+(VCC)).


Coding:
Write the program to know what signal the Bluetooth module sends.
We first click the imported library “Mini_Tank_Robot”, drag out the block428-pro5-1.png; drag the blockP9-4.png from “SerialPort” into the infrared receiver block just made.
Then go to “Variables”, drag out the block P9-5.pnginto the blockP9-4.png.

0428图53.png

Upload this code, open the serial monitor; aimed at the infrared receiver sensor, press the key on the IR remote control, IR receiver will receive the infrared signal, and indicator turns on red. And you can see the key encoding on the serial monitor.

P9-8.png


Below is Tank Robot Bluetooth APP interface and we have listed out what function of each key does:
thumb

thumb


Press the button0428图片144.png on the Bluetooth APP, mobile Bluetooth will send a character “F” to Bluetooth module, Bluetooth module receives the character “F”, printing out the character “F” on serial monitor via UNO board and USB cable, tank robot will go front; release the button, mobile Bluetooth will send a character “S” to Bluetooth module, Bluetooth module receives the character “S”, printing out the character “S” on serial monitor via UNO board and USB cable, tank robot will STOP.

Press the button0428-图50.pngon the Bluetooth APP, mobile Bluetooth will send a character “B” to Bluetooth module, Bluetooth module receives the character “B”, serial monitor printing out the character “B” , tank robot will go back; release the button, sending the character “S” and printing out the character “S” on serial monitor, tank robot will STOP.

Press the button0428-图51.png on the Bluetooth APP, mobile Bluetooth will send a character “L” to Bluetooth module, serial monitor printing out the character “L” , tank robot will rotate to LEFT; release the button, sending the character “S” and printing out the character “S” on serial monitor, tank robot will STOP.

Press the button0428-图52.png on the Bluetooth APP, mobile Bluetooth will send a character “R” to Bluetooth module, serial monitor printing out the character “R” , tank robot will rotate to RIGHT; release the button, sending the character “S” and printing out the character “S” on serial monitor, tank robot will STOP.

Press the button0428-图53.png on the Bluetooth APP, mobile Bluetooth will send a character “S” to Bluetooth module, serial monitor printing out the character “S” , tank robot will STOP.

Press the button0428-图54.png on the Bluetooth APP, mobile Bluetooth will send a character “X” to Bluetooth module, serial monitor printing out the character “X” , start light following function for tank robot; click the STOP button to exist the function.

Press the button0428-图55.png, start the posture function for controlling tank robot; click the button again to exist the function.

Press the button0428-图56.png on the Bluetooth APP, mobile Bluetooth will send a character “Y” to Bluetooth module, serial monitor printing out the character “Y” , start ultrasonic following function for tank robot; click the STOP button to exist the function.

Press the button0428-图57.png on the Bluetooth APP, mobile Bluetooth will send a character “U” to Bluetooth module, serial monitor printing out the character “U” , start obstacle avoiding function for tank robot; click the STOP button to exist the function.

We now already read the character of each key on mobile APP via serial port and figure out the key functions.
Next move on to realize the effect. When press the key0428图片144.pngon the Bluetooth APP, LED panel displays a front pattern; Release the button, 8x16 LED LED panel displays STOP.

So here we call the if...do... statement P9-11.png from the “Control”.
Go to the “Logic” , drag out the block P3-20.png into the if statement, and drag out the blockP14-17.pngfrom the “Variables” into the first input box at the left side of “=”; dragPro9-图片12.png from the “Text” into the second input box at the right side of “=” and type ‘F’ , like this:0428-图62.png.

Click “Mini_Tank_Robot” , drag out the block 428-pro5-3.png into the do statement and click the drop-down triangle to choose front.
Duplicate the above code string once; change ‘F’ to ‘S’ and click the drop-down triangle to select STOP.

thumb


We now already complete the program. Upload the code success, press and release the key0428图片144.pngon the Bluetooth APP, check what phenomenon you will see.


Code:
Pay close attention to:
CANNOT connect the Bluetooth module before upload the code, otherwise, code upload fails. You should upload the code successfully and then plug in the Bluetooth module.


thumb


Test Result:
Make sure you have installed the Bluetooth APP on mobile phone. Power on the motor drive shield, Bluetooth indicator flashes and then open mobile APP to connect the Bluetooth module.
Bluetooth connected, tap the button0428图片144.pngon the Bluetooth APP, 8x16 LED panel will display the front icon. Release the button, display the “STOP”.



Bluetooth Control Robot


We already make the 8x16 LED panel show patterns using the key 0428图片144.png on mobile APP. Based on that, we now extend to control the motor drive shield and other sensor modules using several buttons on the Bluetooth APP, thus build a Bluetooth control robot.

Based on the circuit design, we can start building our own remote control tank robot. Follow the wiring diagram and test code.


Hookup Guide:

thumb

Note: the 4Pin terminal block is marked with silkscreen 1234.
The red line of right rear motor is connected to terminal block 1, black line should connect to terminal block 2. The red line of left front motor is connected to terminal block 3, black line should connect to terminal block 4.
Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication.
Direct plug the Bluetooth module to pin header (TXD, RXD, GND, 5V) on the sensor shield V5 (TX、RX、-(GND)、+(VCC)).



Code:
Note: should upload the code success then plug in Bluetooth module on the tank robot. Otherwise, code upload fails.

thumb



Result:
Stack the motor drive shield onto UNO board. Connect the UNO control board to computer’s USB port with USB cable to upload the code. Turn the slide switch ON.
Make sure you have installed the Bluetooth APP on mobile phone. Power on the motor drive shield, Bluetooth indicator flashes and then open mobile APP to connect the Bluetooth module.
Bluetooth connected, we can use Bluetooth APP to randomly navigate the tank robot.
Tag the button0428图片144.png, go front; tap0428图片155.png, go back; press0428图片156.png, turn left; press0428图片157.png, turn right; press0428图片158.png, stop; press0428图片159.png, start mobile direction sensing control, and tap again this button to exit.
At the same time, 8X16 LED panel will show the robot motion states.
thumb



Project 15: Bluetooth Multi-function Tank


Circuit Design:
How to build a multi-function robot combined with all the functions we’ve learned?
In this circuit, we use a complete code to program the smart car to switch different functions with Bluetooth APP, pretty simple and easy.


Hookup Guide:
0428图片133.png

Note:
The 4Pin terminal block is marked with silkscreen 1234.
The red line of right rear motor is connected to terminal block 1, black line should connect to terminal block 2. The red line of left front motor is connected to terminal block 3, black line should connect to terminal block 4.
Connect the LED panel (GND、VCC、SDA、SCL) to the V5 sensor shield (-(GND)、+(VCC)、SDA、SCL) with 4pin wire for I2C communication.
Direct plug the Bluetooth module to pin header (TXD, RXD, GND, 5V) on the sensor shield V5 (TX、RX、-(GND)、+(VCC)).
Connect the ultrasonic sensor to sensor shield V5, VCC pin to 5V(V), Trig pin to digital 5 (S), Echo pin to digital 4 (S), GND pin to GND(G).
Connect the servo motor to motor drive shield (G(GND)、V(VCC)、9). Brown line is for GND, red one for 5V, orange one for digital pin 9.
Connect the infrared receiver sensor (pin -、+、S) to the sensor shield (G(GND)、V(VCC)、A0).
Connect the left photocell sensor (-, +, S) to sensor shield (G(GND)、V(VCC)、A1); the right photocell to sensor shield (G(GND)、V(VCC)A2).



Source Code:
Write the program to realize the functions we want. Use the button 0428图500.png0428图500.png、 、0428图500.png0428图500.png and 0428图500.pngon the Bluetooth APP to navigate the robot go front, back, rotate to left, rotate to right and stop.
First clear the 8x16 LED panel and initialize the block.
Go to “Control”, drag out block; then go to“Mini_Tank_Robot”, drag and drop the blockinto setup block; click the drop-down triangle to choose clear. And again drag out the blockinto the “setup” block.































Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.

428-bluetooth code.png


Result:
Upload the code success to UNO R3 board; turn the slide switch to right position.
Connected the Bluetooth module with mobile Bluetooth APP, we can navigate the tank robot by Bluetooth remote control.
Tag the different buttons to switch different functions; tap stop button to exit the function.
0428图片1.png



Resources

  • Get all the resources here:

https://1drv.ms/u/s!ArhgRvK6-RyJb5thfQ2--pXcTtE?e=YtpGao

  • Video:

http://video.keyestudio.com/ks0428/


About keyestudio

Located in Shenzhen, the Silicon Valley of China, KEYES DIY ROBOT co.,LTD is a thriving technology company dedicated to open-source hardware research and development, production and marketing.

Keyestudio is a best-selling brand owned by KEYES Corporation, our product lines range from Arduino boards, shields, sensor modules, Raspberry Pi, micro:bit extension boards and smart car to complete starter kits designed for customers of any level to learn Arduino knowledge.

All of our products comply with international quality standards and are greatly appreciated in a variety of different markets throughout the world.
Welcome check more contents from our official website:
http://www.keyestudio.com

Logo图片1.png


For more details of our products, you can check it from the links below.


Customer Service

As a continuous and fast growing technology company, we keep striving our best to offer you excellent products and quality service as to meet your expectation.
We look forward to hearing from you and any of your critical comment or suggestion would be much valuable to us.
You can reach out to us by simply drop a line at: [email protected]
Thank you in advance.


Buy From