Difference between revisions of "Ks0464 keyestudio Smart Little Turtle Robot V3.0"

From Keyestudio Wiki
Jump to: navigation, search
(Bluetooth Remote Control Robot)
(Bluetooth Remote Control Robot)
Line 2,006: Line 2,006:
  
 
<br>
 
<br>
<span style="color:blue"> '''Extension Practice:''' </span><br>
 
1.Based on the project 9 - motor driving, try to drive the robot car without library.<br>
 
2.Take source code as reference. Make full use of Bluetooth APP to lead the robot car’s multiple motions. For instance, go straight in S-shape path.
 
 
  
 
<br>
 
<br>

Revision as of 15:33, 11 October 2019


keyestudio Smart Little Turtle Robot V3.0


Description

People often match a control board, motor drive shield, DC motors, several sensor modules and a bunch of jumper wires to build own robot car. Have you feel very troublesome to connect a bunch of jumper wires?
Here comes keyestudio smart little turtle robot V3 upgraded version.
This new turtle robot simplify the wiring complication, avoiding wrong connection and saving your time.

The upgraded turtle robot still retains the functions like line tracking, obstacle avoidance, IR and Bluetooth control.
Furthermore, you can see terrific improvements as follows:

  • 1)The connectors on the motor drive shield have anti-reverse protection, simple to connect with only one cable.
  • 2)Themotor drive shield comes with a slide switch for power control, and also adds 8 jumper caps to control the DC motor direction, easy for code debugging.
  • 3)Adding a 8*8 dot matrix module to show the robot’s running status.
  • 4)Using Bluetooth HM-10 module; can support Bluetooth 4.0; Bluetooth APP supporting both Android and iOS system.
  • 5)Can freely connect the battery case 18650 or 4-cell AA battery case to supply power for the robot car. Note that batteries are Not Included. Users can freely choose two 18650 batteries or four AA batteries (1.5V) to supply power for the robot car.
  • 6)Clear silk-screen for motor A and B on the PCB plate or you can check it out on the Acrylic plate and motor drive shield. Protect motors from avoid wrong connection;
  • 7)Coding the robot car with Mixly blocks software, simple to code and ready to play.


From the basics up to complex projects, through this kit you can learn to control the robot car with Mixly blocks coding.
It allows you to quickly learn graphic programming in entertaining, nurturing your interest in science and logical thinking.
Take your brain on a fun and inspiring journey through the world of programming and electronics.



Parameters

  • 1)Motor’s voltage range: 1-6V; motor shaft length: 10mm; speed: 6.0V 100rpm/min.
  • 2)Motor control is driven by L298P.
  • 3)Three groups of line tracking modules, to detect black-white line with higher accuracy and can also be used for anti-fall control.
  • 4)Ultrasonic module is used to detect whether there is obstacles or not.
  • 5)Bluetooth wireless module can be paired with Bluetooth device on mobile phone to remotely control the turtle robot.
  • 6)Infrared receiver module matches with an infrared remote control to control the turtle robot.
  • 7)Add a 8*8 dot matrix module, showing the robot states.
  • 8)Can access to the external voltage 6~12V


0464图片3.png


Component List

Each component is tidily packed inside the packaging box. What components you should get to build the robot? We have listed all the components as follows:

0464图片4.png

0464图片5.png

0464-list.png

0464图片7.png

0464图片8.png


Getting 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 Small_Turtle_Robot library.
Don’t forget to import the keyestudio Small_Turtle_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.


0464图片9.png

Unzip the Small_Turtle_Robot library package, you can see the Small_Turtle_Robot XML.document.
0464图片10.png

Then import this document into Mixly library. Import custom library successfully!
0464图片11.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.

0464图片12.png



Getting 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: Light up an LED

keyestudio red LED module

In this course, we create 2 test codes. One for turning LED on and off, blinking effect; the other is to change the brightness of LED using the step and delay function in the code, simulating the breath effect.


Overview:
This is keyestudio red LED module. On the module, you will see a light emitting diode (LED), which has two states ON and OFF.
The LED module leads out three pins of 2.54mm pitch, respectively negative pin (marked -), positive pin (marked +) and signal pin (marked S).
The - pin is connected to ground, + pin is connected to VCC(3.3-5V), S pin is for signal control; you can set the High or Low level to control the LED on and off.

After programming, it will emit red light color. You can combine with other sensors to do various interactive experiments.
You can choose other LED modules to emit different light colors like blue, green, yellow and white.


Wiring Diagram:
Note: stack the motor drive shield on the UNO board; connect red LED module to motor drive shield (pin - for GND, + for 5V, S for digital pin3 (S)). Connect the power to BAT connector.
464图片14.png


Coding:
Now write the program to make the red LED flash.
Go to “Small_Turtle_Robot” , drag out the blockP2-1.png, this block is used to set the HIGH/LOW for digital port;

Click the drop-drown triangle icon to select HIGH for digital pin, with voltage; select LOW for digital pin, with no voltage.
So what should we set the red LED pin output HIGH or LOW to turn on the LED? Through testing, set to HIGH, red LED turns on; set to LOW, red LED turns off.
Go to “Control” , drag out the blockP2-2.png;
Duplicate this piece of code string Ks0464-pro2图3.png once and set to LOW.
We turn on the red LED for one second then off for one second.


Code 1:
464图片15.png


Code 2:
The Arduino controller has 12 common digital pins (digital pin 2-13); the general digital pins can only output HIGH or LOW level.
The pin labeled “〜” is also called PWM (“Pulse-Width Modulation”) pins. The Arduino controller has totally 6 PWM outputs, which are Digital 3, 5, 6, 9, 10 and 11). The PWM pins can steadily output the HIGH and LOW level, and can continuously change HIGH or LOW in a regular time period.

The effect of LED gradually brightening and darkening is controlled by PWM. The PWM can control 0-255 "level" of voltage output.
Go to “Control” , drag out blockKs0464-pro2图4.png; here can set any random number. i is a variable. Red LED brighter is the Level variable increasing from 0 to 255. So we first set the variable i from 0 to 255 step 1.

Go to “IN/OUT” , drag the Ks0464-pro2图5.png block into the step block just made. Select pin 3 and drag a variables block Ks0464-pro2图6.png from “Variables” into the value. And add a Delay block and set to 10ms.

Ks0464-pro2图7.png

This piece of code block means the red LED is gradually brightening per 10 milliseconds with a step of 1.
What about the LED dimming? the red LED darkening is the Level variable increasing from 255 to 0.
We duplicate the above code once; set as i from 255 to 0 step -1.
Upload the complete code to see the result.


Ks0464-pro2图8.png


What you will see
Drag the test code 1 to Mixly window, compile the code and then click on the 'Upload' button.
You will see the message “Upload success” appear on the bottom bar.
Turn the slide switch to ON position.
Eventually, the LED lights up for one second, then off one second, circularly.
464图片17.png

464图片18.png


Upload Code 2 to the UNO R3 board; turn the slide switch to ON position.
The LED will simulate the human breath, gradually brightening and then gradually dimming, alternatively and circularly.
Ks0464-pro2图9.png



  • Little Knowledge:

1.441图15.png In the code 1, we’ve set the signal pin of LED module to D3 in the library. Or be able to randomly set the LED signal pin without library. using the block 441图16.pngalso makes sense.

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

3.In the code 2, we use the block 464图片23.png
The LED signal pin is connected to D3; set the PWM value to 0. The PWM value is in the range of 0-255. The greater the value set, the brighter the LED is.

4.464图片24.pngmeans the variable i increases direct from 0 to 255; each step plus 1.
464图片25.png means the variable i direct reduces direct from 255 to 0; each step minus 1.



  • Extension Practice:

1.Set the LED blink without using library; set the signal pin of LED to D11; turn on for 0.5 second, then off for 0.2 second, alternately and circularly.

Ks0464-pro2图10.png

2.Change the Code 2. Set the LED signal pin connect to D10;
When gradually brightening: PWM value increases from 0 to 255; each step plus 5; delay 30ms.
When gradually dimming: PWM value reduces from 255 to 0; each step minus 5; delay 50ms.

Ks0464-pro2图11.png


Project 3: Light up LED Matrix

464图片26.png

In the previous project, we have simply tested the LED. We now have added a new 8*8 Dot Matrix module to the turtle robot to show the moving states. Amazing display!
Do you know how is the cool advertising display made? It is exactly composed of these small LED matrix. If you want to make a similar display, this keyestudio 8*8 Dot Matrix module will meet you need.


Overview:
This tiny display has 64 LEDs packed into a 8*8 dot matrix. It integrated HT16K33 as driver chip, so with this LED matrix module, you can control it through connecting I2C communication interfaces ( A4-SDA ; A5-SCL).
It is great for displaying image/text or creating bizarre patterns, and is highly portable and convenient to use. Of course you can program it via IDE or via Mixly block. With just a few steps, you are ready to impress others!


Wiring Diagram:
Note: stack the motor drive shield on the UNO board; connect LED matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5). Connect the power to BAT connector.
464图片27.png


Coding:
Now write the program to make the LED matrix display patterns. We first set the pins then design and display the pattern.
Click “Small_Turtle_Robot” , drag out the block0464-pro3图12.png; here default SDA pin to A4, SCL pin to A5. To clear the display patterns set before, need to clear the screen.

Go to “Control” , drag out block0464-pro3图13.png, and drag the block 0464-pro3图12.png into setup block. And again drag the block 0464-pro3图15.png beneath the block just made.
Next design and display the pattern, need to call the block 0464-pro3图16.png and 0464-pro3图17.png.

For instance, tick the ledArray to show the icon you want. When tick the ledArray, it will appear the mark “√”, that is, lit the corresponding led. Here we draw a large square pattern.
Go to “Control” , drag out block441图17.png, set to delay 2000ms. And go to “Small_Turtle_Robot” , drag out the block 0464-pro3图15.png beneath the delay block. And again drag out the block0464-pro3图17.png, click the drop-down triangle to select other patterns.
0464-pro3图21.png

Then add a delay block 2000ms and a display clear block.
And duplicate the piece of code string once; click the drop-down triangle to select pattern stop2.
Upload the finished code to see the display effect!


0464-pro3-code.png


What you will see:
464图片29.png
Drag the test code to Mixly window, compile the code and then click on the 'Upload' button. You will see the message “Upload success” appear on the bottom bar.
Turn the slide switch to ON position.
You should see the keyestudio 8*8 Dot matrix show the square icon for 2 seconds, a smile face icon for 2 seconds, stop displaying for 2 seconds, alternately and circularly.
464图片30.png464图片31.png

464图片32.png



  • Little Knowledge:

1.464图片33.png In the code, we are able to set the I2C communication pin and connect to the proper pin.

2.464图片34.png Means clear the patterns shown on the dot matrix screen.

3.You can define the pattern you want to display; no need to set by yourself; just direct call the patterns in the library.
464图片35.png

4.In the code, we can also set any patterns as we like; just tick in the dot matrix, indicating that the point is lit.
464图片36.png
Set the first pattern as464图片37.png; the second pattern should be LedArray2; And so on...



  • Extension Practice:

1.Set a static icon you like and show on the dot matrix;

0464-pro3图22.png

2.Set a dynamic icon you want to show on the dot matrix.
0464-pro3图23.png

Project 4: Line Tracking Sensor


Overview:
The tracking sensor is actually an infrared sensor. The component used here is the TCRT5000 infrared tube. Its working principle is to use the different reflectivity of infrared light to the color, then convert the strength of the reflected signal into a current signal.
During the process of detection, black is active at HIGH level, but white is active at LOW. The detection height is 0-3 cm.
For keyestudio 3-channel line tracking module, we have integrated 3 sets of TCRT5000 infrared tube on a single board. It is more convenient for wiring and control.
By rotating the adjustable potentiometer on the sensor, it can adjust the detection sensitivity of the sensor.

Special note: before testing, turn the potentiometer on the sensor to adjust the detection sensitivity.
When adjust the LED front the trimpot at the threshold between ON and OFF, the sensitivity is the best.


TECH SPECS:

  • Operating Voltage: 3.3-5V (DC)
  • Interface: 5PIN
  • Output Signal: Digital signal
  • Detection Height: 0-3 cm


441图66.png


Wiring Diagram:
Note: stack the motor drive shield onto UNO control board. connect the line tracking sensor to motor drive shield’s P1 connector (G, V, D6, D7, D8); Connect the pin (-、+、S) of red LED module to the pin G, 5V, D3(S) of motor drive shield with 3P female-to-female jumper wire; connect the power supply to BAT connector.

464图片38.png


Coding:
Now write the program to test the line tracking sensor.
Go to “Control”, drag out the “setup” block; and drag the “Serial baud rate(9600)”block from “SerialPort” into the “setup” block.

To respectively read the left, the center and the right tracking sensor on the line tracking module, we click the “SerialPort” , drag out the blockP8-1.png; drag out the blockP3-2.pngfrom “Text” into the block P8-1.png, and then duplicate the complete block six times. Change the firstP3-2.png to “left_tracking=”; drag out the block P8-5.png from library “Desktop_Car_V3” to replace the second P3-2.png; delete the third hello box, forming a blank box; change the fourth P3-2.pngto
“center_tracking=”.

Duplicate the blockP8-5.png once to replace the fifthP3-2.png and click the drop-down triangle icon to select the “center_tracking”; delete the sixth hello box, forming a blank box; change the seventh P3-2.png to “right_tracking=”.
And again go to “SerialPort”, drag out the block P8-1.png; duplicate the block P8-5.png once and drag it into P8-1.png, click the drop-down triangle icon to select the “right_tracking” And go to “Control”, drag the delay blockPro4-图片3.png; set to delay 1000ms.

P8-15.png

Complete and upload the above code to see the result. It can tell black and white.
Through testing, if line tracking sensor detects white, output LOW 0 and the built-in LED turns on red; detecting black, output HIGH 1 and the built-in LED is off.

We’ve measured what signal the line tracking sensor sends. Next the white LED is turned on when any tracking sensor detects white.
Next write the program that can turn on or off white LED module using line tracking sensor.

To judge whether the left, the center and the right tracking sensor detect black or white, here we can use the condition statement P3-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 blockP3-20.png, and drag out the blockP8-5.png from the “Desktop_Car_V3” 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 “=” ; like this:P8-26.png.
We duplicate the block twice, and respectively click the drop-down triangle icon to select “center_tracking” and “right_tracking”.P8-27.pngP8-28.png.

And again go to the “Logic”, drag out the blockP3-25.png and click the drop-down triangle to select “or”; duplicate the block P8-30.pngonce and make as P8-31.png; drag this block behind into the if statement.

Now respectively drag the blockP8-26.png,P8-27.pngandP8-28.png into the input box of blockP8-31.png.

Click the “Desktop_Car_V3”, drag out the blockP3-29.png into do statement, keep HIGH; duplicate the block once and set to LOW and drag it into else statement.

P8-37.png

Now we have written the code of tracking sensor controlling white LED module. Upload the complete to see the final result!
P8-38.png



Result:
Drag the test code to Mixly window, compile the code and then click on the 'Upload' button.
You will see the message “Upload success” appear on the bottom bar. Turn the slide switch to ON position.
When any TCRT5000 infrared pair transistor on the line tracking sensor detects white, LED module will turn on; otherwise, LED turns off.
464图片41.png



  • Little Knowledge:

1.In the code, we use the library 441图71.png to read the HIGH/LOW of the left sensor (D6); using the block 441图72.png also makes sense.
The signal pin of the middle sensor is D7; the signal pin of the right sensor is D8.

2.Ks0446图片30.png means the baud rate is set to 9600;
0428图片43.png Print the specified number, text or other value on serial monitor.
0428图片44.png Print 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.Pro4-图片-4.pngThis is a logical statement. It’s available as long as can satisfy any one of the three conditions.


  • Extension Practice:

1.Try to change the code without using library to make the same result.
Pro4-图片-5.png



Project 5: Ultrasonic Detecting Obstacles


Overview:
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 LED matrix show the images.
441图47.png


TECH SPECS:

  • Operating Voltage: DC 5V
  • Operating Current: 15mA
  • Operating Frequency: 40khz
  • Maximum Range: 2-3m
  • Minimum Range: 2m
  • Sensing Angle: 15 degrees
  • Trigger Input Signal: 10µS TTL pulse


Wiring Diagram:
Note: stack the motor drive shield onto UNO control board. Connect the ultrasonic sensor to motor drive shield’s P2 connector, VCC pin to V, Trig pin to digital 13 (S), Echo pin to digital 12 (S), G pin to GND(G);
Connect the pin G、V、SDA、SCL of dot matrix module to the pin G、5V、A4、A5 of motor drive shield with female-to-female jumper wire.
Connect the power supply to BAT connector.


464图片44.png


Coding:
The ultrasonic sensor is connected to P2 connector of motor drive shield , VCC pin to V, Trig pin to digital 13 (S), Echo pin to digital 12 (S), G 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 P5-7.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 100ms.
Upload the code success, open the serial monitor to check the distance between ultrasonic sensor and an obstacle.

0464-pro5图9.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, dot matrix display a smile face pattern.
When the measured distance between the ultrasonic sensor and front obstacles is greater than 10cm, clear the dot matrix display.

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 P5-7.png from the “Small_Turtle_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:P5-21.png.

First set up the dot matrix display, click “Small_Turtle_Robot”, drag out the block 0464-pro3图12.png into the setup block; here default SDA pin to A4, SCL pin to A5. And again drag out the block 0464-pro3图17.png into the do statement, click the drop-down triangle to select smile pattern. The dot matrix will display a smile pattern. And drag out the block 0464-pro3图15.png into the else statement.

0464-pro5图20.png

Now we have written the test code for ultrasonic sensor. Upload the code and move an obstacle in front of ultrasonic sensor to check the result.

0464-pro5-code.png


What you will see
Upload the code success, open the monitor and set the baud rate to 9600. Turn the Slide switch ON.
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.
464图片46.png
When the measured distance is less than 10cm, LED matrix shows a smile image; otherwise, no image display.
464图片47.png




  • Little Knowledge:

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

2.0464-pro5图22.png: print the distance value on the newline of monitor. The baud rate default by 9600.
If use the block 0464-pro5图23.png , it will not print the value on the newline; just print on the monitor. The difference between them is whether need to make line wrap.

3.What happens when you change the number in one or both of the delay(1000)
441图17.png
This delay period is in milliseconds, so if you want the LED to blink as low or fast, change the value, try 500 or 2000.

4.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.Change the distance value measured by ultrasonic sensor to make the LED panel show different patterns.
0464-pro5图24.png



Project 6: Infrared Receiver


  • IR Remote Control:
remote control

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


Wiring Diagram:
Note: stack the motor drive shield on the UNO board; connect the infrared receiver sensor to P4(G、V、A1) connector on the motor drive shield. 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.
Connect dot matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5). Connect the power to BAT connector.

464图片49.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“Small_Turtle_Robot”, drag out the blockP9-3.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.
P9-7.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 dot 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.

First set up the dot matrix display, click “Small_Turtle_Robot”, drag out the block0464-pro3图12.png into the setup block; here default SDA pin to A4, SCL pin to A5. And again drag out the block0464-pro6图3.png and 0464-pro3图17.png into the do statement, click the drop-down triangle to select front2.
0464-pro6图6.png

Next duplicate the block0464-pro6图5.png once and change “0xFF629D” to “0xFF02FD” and click the drop-down triangle to select stop2.


0464-pro6-code.png


What you will see:
Upload the code success, open the monitor and set the baud rate to 9600. Turn the Slide switch ON.
Aimed at the infrared receiver, press your remote control to send the signal, and you will see the encoding of each button on the remote control.
Note if press the control button too long, easily appear unreadable code. Shown as below figure.
464图片52.png

If receive the 464图片53.png up button value from IR remote control, LED dot matrix shows the front icon0428图片31.png ; if receive the 464图片55.pngOK key value, shows“STOP”.


464图片56.png



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



Little Knowledge:
1.In the code, we direct use the library441图78.png; the signal pin of IR receiver module is A1; the IR receiver receives an infrared signal and outputs 16-bit encoding, printing out on serial monitor (baud rate 9600).
thumb

2.We have tested 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.
In the code, we can change the different key encoding to control dot matrix display different icons.



Extension Practice:
1.Driving the 2 motors’ turning direction and speed by infrared remote control.
(refer to project 9/10 - motor driving)
Combine infrared receiver and motors driving knowledge to build an infrared remote control car.

thumb


Project 7: 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 8: 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:
Note: stack the motor drive shield onto UNO control board. Connect the servo motor to motor drive shield. Brown line is for GND, red one for 5V, orange one for analog pin A3.
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.
Connect the power supply to BAT connector.


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 analog pin A3 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 A3; 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 ON position. The servo motor will rotate to 90 degrees.
Upload the Code 2 success, turn the slide switch to ON 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.
464图片63.png this piece of block is to set the procedure; connect the servo signal pin to A3 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 A3.
thumb


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.
(refer to the project 2 Code 2 - LED breath)

thumb


Project 9: Motor Driving and Speed Control

Overview:

KS0435-3.png

There are many ways to drive the motor. Our 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 V2 based on the L298P circuit.
The stackable design can make it be plugged directly into the Arduino, reducing the technical difficulty of using and driving the motor.

Direct stack the motor driver shield onto UNO R3 board, after the BAT is powered on, turn the Slide button ON, to supply the power for both keyestudio motor driver shield V2 and UNO R3 board.
For simple wiring, the motor driver shield comes with anti-reverse interfaces. When connecting the motor, power supply and sensor modules, you just need to plug in directly.

The Bluetooth interface on the motor driver shield is fully compatible with keyestudio HM-10 Bluetooth module. When connecting, just plug HM-10 Bluetooth module into the corresponding interface.

At the same time, the motor drive shield has brought out extra digital and analog ports in 2.54mm pin headers, so that you can continue to add other sensors for experiments extension.
The motor drive shield can access to 4 DC motors, defaulted by jumper connection. The motor connector A and A1, connector B and B1 are separately in parallel.

The 8 jumpers can be applied to control the turning direction of 4 motors.
For instance, if change the 2 jumpers near the motor A connector from horizontal connection to vertical connection, the turning direction of motor A is opposite to the original rotation direction.

thumb


Specifications:

  • 1)Logic part input voltage: DC5V
  • 2)Driving part input voltage (limit): DC 6-18V
  • 3)Driving part input voltage (recommended): 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℃


PINOUT Instructions:

thumb


Wiring Diagram:
Connect two motors to keyestudio motor drive shield V2; stack the motor drive shield onto UNO control board.
441图57.png


Driving Motor
According to the wiring diagram, default the jumper connection method.
Follow the table below to drive the 2 motors rotate by Digital, PWM pins, so as to control the robot car run.
The PWM value is in the range of 0-255. The greater the value set, the faster the motors rotate.
0464-pro9图1.png


Coding:
Navigate the turtle robot to turn forward for 2 seconds, backward for 2 seconds, rotate to left for 2 seconds, rotate to right for 2 seconds, stop for 2 seconds then turn left for 2 seconds, turn 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 4 and pin 2; change the analog pin 3 to pin 5 and pin 9. Pin 4 and pin 2 set to LOW; assign both pin 5 and pin 9 value to 100.
Next go to drag out the block P6-3.png from “Control”, and set to 2000ms.
0464-pro9图5.png
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, right and stop.
Duplicate the finished code string above three times;
Set the pin 4 and pin 2 to HIGH, assign both pin 5 and pin 9 value to 100, so that both the left and the right motor will turn backward, thus the robot will turn back.
0464-pro9图6.png

Set the pin 4 to LOW and pin 2 to HIGH, assign both pin 5 and pin 9 to 100, so that the left motor turns back and the right motor turns front, thus the robot will rotate to left.

P6-6.png

Set the pin 4 to HIGH and pin 2 to LOW, assign both pin 5 and pin 9 to 100, so that the right motor turns front and the left motor turns back, thus the robot will rotate to right.
P6-7.png

Go to “In/Out” again, drag out the blockP6-2.png and duplicate once, change the pin3 to pin 5 and pin 9, assign the value 0; then add a delay block 2000ms.
0464-pro9图10.png

Finally move on to write the code for robot to turn left, right and stop.
Duplicate the code block of robot turning forward 0464-pro9图5.png twice. Just change the value of pin5 to 180, turning into:
0464-pro9图12.png

Both the left and the right motor turn forward, so turtle robot will turn left.
Just change the value of pin9 to 180, turning into:
0464-pro9图13.png

Both the left and the right motor turn forward, so turtle robot will turn right.
And duplicate the code block of robot stop once.

Upload the complete code to see the desktop robot move.
0464-pro9-code.png


Result:
Drag the test code to Mixly window, compile the code and then click on the 'Upload' button. You will see the message “Upload success” appear on the bottom bar. Turn the slide switch to ON position.
The 2 motors act like the smart car to turn forward for 2 seconds, backward for 2 seconds, rotate to left for 2 seconds, rotate to right 2 seconds then stop for 2 seconds, turn left for 2 seconds, turn right for 2 seconds, stop for 2 seconds, alternately and circularly.
441图61.png



  • Little Knowledge:

1.The code logic is completely based on the motor driving reference table. Check it out.
2.The PWM value is in the range of 0-255. The greater the value set, the faster the motors rotate. Base on that, you can set the speed as you like.


  • Extension Practice:

1.Based on the logic table, try to reset a new moving track for your smart car. (reference program)
0464-pro9图14.png


Project 10: Library Driving Motor

Overview:
There are many ways to drive the motor. We have learned how to control the 2 motors in the previous section, so as to drive the smart car run. It is troublesome to control the smart car via control port.
For this, we specially create the library to drive the robot car more simple and easier.
When setting, the PWM value is in the range of 0-255. The greater the value set, the faster the motors rotate.


Wiring Diagram:
441图57.png


Test Code:
Click the “Small_Turtle_Robot”, drag out the block0464-pro10图1.png and set to PWM100; so the robot will move front at a speed of PWM100.
This block0464-pro10图2.png has the same function as the string block 0464-pro10图3.png.

Next go to drag out the block P6-3.png from “Control”, and set to 2000ms.
Click the “Small_Turtle_Robot”, drag out the block0464-pro10图5.png, 0464-pro10图6.png,0464-pro10图7.pngand 0464-pro10图8.png, set to PWM100; respectively add a delay block in 2000ms.
Continue to write the program for robot, turn left for 2 seconds, turn right for 2 seconds, stop for 2 seconds.
Drag out the block0464-pro10图9.png, 0464-pro10图10.png and 0464-pro10图8.png; set to PWM100 and respectively add a delay block, set to delay 2000ms.


464图片66.png


Result:
Done wiring, connect the UNO control board to computer’s USB port with USB cable to upload the code. Upload success, turn the Slide switch ON.
The 2 motors act like the smart car to turn forward for 2 seconds, backward for 2 seconds, rotate to left for 2 seconds, rotate to right 2 seconds then stop for 2 seconds, turn left for 2 seconds, turn right for 2 seconds, stop for 2 seconds, alternately and circularly.



  • Little Knowledge:

1.The code using library to set the car’s motion state, easy and simple, shortening the code length.
2.The control logic is the same as project 9-motor driving. We can click to check out the corresponding language C of motor mixly code.
464图片67.png


  • Extension Practice:

1.Based on the logic table, try to reset a new moving track for your smart car.(reference program)
0464-pro10图12.png


Getting Started with Robot Projects

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

0464图片1.png

Project 11: Turtle Assembly Guide


Follow the assembly steps to build your own turtle robot.

Step 1: Bottom motor wheel

(1)Firstly, you should prepare the components as follows:

  • M3*6MM round-head screw *2
  • Nut M3 nickle plating *2
  • Bottom PCB*1
  • Tracking sensor *1
  • Universal caster *1

Insert two M3*6MM round-head screw into the tracking sensor, then tighten two M3 Nuts to the screws with screwdriver and self-prepared wrench.
464图片68.png

464图片69.png

Back view:
464图片70.png

Then fix 2 universal caster wheels to the bottom PCB board.Tighten the screws with screwdriver and self-prepared wrench.
0464-install1.png

0464-install2.png

Back view:

0464-install3.png

0464-install4.png

Back view:

0464-install5.png


(2)Next, mount the motors on the bottom board. You should first get some parts below:

  • U-type holder* 2
  • M2*12MM round-head screws *4
  • M2 Nut *4
  • Motor *2


464图片73.png

Note: the Acrylic plate is marked with A, B for the two motors. Mount the motor A to label A on the Acrylic plate; motor B to Acrylic position B.

464图片74.png

Firstly place four M2 Nuts inside the holes of white N20 motor holders. You should get it as below.
464图片75.png

Then place the white holders onto the motors.
464图片76.png

After that, fix these two motor connectors on the bottom PCB with four M2*12MM round-head screws.
464图片77.png

464图片78.png


(3)Completed the above assembly, let's install the 2 wheels for this small car.
464图片79.png
Plug the two yellow wheels into the motor shaft directly.
464图片80.png


Completed the above steps, you should get prepared for wire connection of motors and tracking sensor below.

  • JST-PH2.0MM-2P 24AWG black-red wire 160mm*2
  • JST-PH2.0MM-5P 24AWG blue-green-yellow-red-black wire 15CM *1


0464-install6.png

Separately connect the 2P black-red wire 160mm to the motor A and motor B.
0464-install7.png

Connect the 5P blue-green-yellow-red-black wire 15CM to the tracking sensor.
0464-install8.png

0464-install9.png


Step 2: Battery case

(1)Completed the above assembly, let's install the battery case.

  • M3*6MM round-head screws *2
  • M3 Nut *2
  • Battery case *1


0464-install10.png

We have provided you with two kinds of battery case. The 18650 2-cell battery case or 4-cell AA battery case for the robot.
You can install the 2-cell 18650 battery case to the bottom PCB with two M3*6MM round-head screws and M3 nuts.Tighten the screws with screwdriver and self-prepared wrench.
Then insert the batteries. The batteries are Not Included in shipping.


0464-install11.png

Or install 4-cell AA battery case with 2 M3*6MM round-head screws and 2 M3 nuts:
0464-install12.png

0464-install13.png

0464-install14.png

Here we install the 4-cell battery case for the robot car.


Step 3: Top PCB

(1)Above parts are installed well, start to install the top parts for the robot:

  • Top PCB *1
  • M3 Nut *1
  • M3*6MM round-head screws *9
  • M3*10MM dual-pass copper pillar *8
  • IR receiver sensor *1


464图片88.png

According to the silk mark of bottom PCB, install the IR receiver to the PCB using a M3 nut and a M3*6MM round-head screw.
Tighten the screws with screwdriver and self-prepared wrench. Then screw 8 M3*10MM dual-pass copper pillars to the PCB with 8 M3*6MM round-head screws.
464图片89.png464图片90.png


Followed by assembling the control board on bottom PCB. Prepare well the components below:

  • Motor drive shield V2*1
  • UNO R3 board*1
  • M3*6MM round-head screws *4
  • JST-PH2.0MM-3P connector wire *1

First, tighten the UNO board to the PCB using four 3*6MM round-head screws. Tighten the screws with screwdriver.
464图片91.png

Then simply stack the motor drive shield V2 onto the UNO R3, and connect the IR receiver to P4 connector using JST-PH2.0MM-3P connector wire.
464图片92.png


Step 4: Servo plastic platform

(1)Time to assemble the motor and plastic platform:

  • black plastic platform *1
  • Servo *1

mount the servo to the black plastic platform with four M1.2*5 tapping screws (included in plastic platform bag), a cross white mount and a M2*5 screw (included in servo bag)
0464-install15.png

First should upload the code to UNO R3 to make the servo rotate to 90 degrees.


Test code:
Connect the servo to pin 3 (S, 5V, G)
464图片94.png

Detailed method please refer to the project - adjusting servo angle
464图片95.png

Then fix the cross white mount to the black plastic platform with four M1.2*5 tapping screws.
464图片96.png

464图片97.png

Then adjust the servo towards front in 90 degrees to install it.
0464-install16.png

After that, fix the servo to the plastic platform using a M2*5 screw.
0464-install17.png

0464-install18.png

Finally, mount well another two plastic platform holders using two M2*8 screws.
464图片101.png

464图片102.png


(2) Until now, let’s install the ultrasonic sensor to Servo platform part.

  • ultrasonic sensor *1
  • JST-PH2.0MM-4P wire 8CM *1
  • Nylon cable ties*2

Simply connect the wire to ultrasonic sensor, and then tighten the ultrasonic sensor to the black plastic platform using two cable ties through the holes of sensor.
464图片103.png
464图片104.png464图片105.png


(3)After that, mount the ultrasonic platform part onto the top PCB with four M3*6MM round-head screws.
Then connect ultrasonic sensor and servo motor to the motor drive shield.

  • Top PCB part
  • Ultrasonic platform part
  • M3*6MM round-head screw*4


464图片106.png

464图片107.png



Step 5: Matrix and Complete Robot

(3)Completed the above assembly, let's install the dot matrix display for this small turtle.

  • Dot matrix display *1
  • Jumper wire *4
  • M3*6MM round-head screws *4
  • M3*40MM dual-pass copper pillar* 4

Connect the jumper wires to the four pins of matrix display.
464图片108.png

464图片109.png

Then screw the four M3*40MM copper pillars to the bottom PCB with four M3*6MM round-head screws.
464图片110.png

464图片111.png

After that, assemble the bottom PCB parts, 8*8 dot matrix display and top PCB parts together using four M3*6MM round-head screws. Plug the matrix display into the bottom PCB.
464图片112.png

464图片113.png

0464-install19.png


Hookup Guide


KS0464-8.png

Plug in the HM-10 Bluetooth module and 8 jumpers.
464图片115.png


Congrats! complete the turtle 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.

0464图片3.png

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


Project 12: Line Tracking Robot

464图片116.png


Circuit Design:
In the above sections we already introduced the motor drive shield, tracking sensor, matrix module, motors and other hardware.
According to the hardware knowledge -- motor drive shield, motor driving, line tracking sensor, we’re now ready to give the robot capability - Line Tracking!
In the project, we make the robot detect black line at the car bottom with line tracking sensor. Then control the 2 motors rotation by measured result, so as to drive the robot track black line.

Below is a specific logic table of line tracking robot for your reference:
Line track-1.png


Build Line Tracking Robot:
Based on the designed circuit, we are going to build a line tracking robot car.
Check the circuit diagram and test code below.


Hookup Guide:
KS0464-3.png

Note: stack the motor drive shield onto UNO control board. connect the line tracking sensor to motor drive shield’s P1 connector (G, V, D6, D7, D8);
Respectively connect the motor A and B to connector A and B on the motor drive shield; connect the power supply to BAT connector.



Coding:

Now write the program to build a line tracking robot.

The line tracking sensor detects white, output LOW 0; detecting black, output HIGH 1.

To judge whether the left, the center and the right tracking sensor detect black line, if the center tracking sensor detects black line, judge whether the left and the right tracking sensor detect black line.
Here we can use the condition statement P3-13.pngorP3-14.png .
But the block P3-14.pngis more efficient thanP3-13.png .
Go to “Control”, drag out the block P3-13.png, then click the blue gear icon, appear the edit box, drag the P3-17.png block into Pro8-图片15.pngblock. So you can get the block P3-14.png.

Next, go to the “Logic”, drag out the block P3-20.pnginto the if statement, and drag out the block P8-5.pngfrom the “Small_Turtle_Robot”into the first input box at the left side of “=” and click drop-down triangle to select “center tracking”; drag the Pro8-图片20.pngfrom the “Math” into the second input box at the right side of “=” and change the value to 1; like this:
Ks0464-8.png

When the center tracking sensor detects black line, judge whether the left and the right tracking sensor detect black line.

Next should call the “if...do...else if...do...else...” statement.

Go to “Control”, drag out the block P3-13.png, then click the blue gear icon, appear the edit box, drag the Ks0464-10.pngblock into the Pro8-图片15.pngblock then drag the block Ks0464-12.pngbeneath the Ks0464-10.pngblock.

So you can get the block Ks0464-14.png; continue to drag this block into the do block Ks0464-8.png

If the left tracking sensor detects black line and the right tracking sensor detects white line, the robot will rotate to left at a speed of PWM200.

Next, go to the “Logic”, drag out the block P3-20.png into the if statement, and drag out the block P8-5.pngfrom the “Small_Turtle_Robot”into the first input box at the left side of “=” and click drop-down triangle to select “center tracking”; drag thePro8-图片20.png from the “Math” into the second input box at the right side of “=” and change the value to 1; like this:P12-16.png

We duplicate the block P12-16.pngonce, and respectively click the drop-down triangle icon to select “right_tracking” and change the value to 0.P8-28.png
And again go to the “Logic”, drag out the block P3-25.pnginto the if statement; respectively drag the block P12-16.pngand P8-28.png into the input box of block P3-25.png.

Drag out the block Ks0464-26.pngfrom “Small_Turtle_Robot”into the do statement, and set the value to PWM200.
Ks0464-27.png

Followed by the left tracking sensor detects white line and the right tracking sensor detects black line, the robot will rotate to right at a speed of PWM200.

Duplicate the block P12-22.png once and drag it into else if statement; change to “left_tracking=0 and right_tracking=1”

Drag out the blockKs0464-29.png from “Small_Turtle_Robot”into the do statement, and set the value to PWM200.

Next both the left and the right tracking sensor detects white line or black line, the robot will go front at a speed of PWM200.
Drag out the block Ks0464-30.pngfrom“Small_Turtle_Robot”into the else statement, and set the value to PWM200.
Ks0464-31.png

Or else, in the case that the center tracking sensor detects white line, if the left tracking sensor detects black line and the right tracking sensor detects white line, the robot will rotate to left at a speed of PWM200;
If the left tracking sensor detects white line and the right tracking sensor detects black line, the robot will rotate to right at a speed of PWM200;
Both the left and the right tracking sensor detects white line or black line, the robot will stop.


Duplicate the complete code of “if...do...else if...do...else...” block once and drag it into the else statement.

Drag out the block Ks0464-32.png from“Small_Turtle_Robot”to replace the block Ks0464-33.png.
The code for line tracking function is complete! Upload the program to see the effect.

Ks0464-34.png

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


What you will see:
Upload success and turn the slide switch to ON position.
The robot can automatically track black line.
464图片121.png



Little Knowledge:
1.The specific logic of tracking robot car please refer to the logic table mentioned above.
2.The PWM value is in the range of 0-255. The greater the value set, the faster the motors rotate. We can change the PWM value to randomly drive the robot car’s motion speed.



Project 13: Ultrasonic Follow Robot

464图片122.png


Circuit Design:
We combine the hardware knowledge -- LED matrix, 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 robot motion and show the running state by dot matrix.

The specific logic of ultrasonic follow robot is as shown below:
Follow-1.png


Build Line Tracking Robot:
Based on the circuit design, we can start building our own ultrasonic following robot.
Check the circuit diagram and test code below.


Hookup Guide:
Connect the servo pin to pin header A3 (S, 5V, G); 8*8 dot matrix to pin header A5, A4, 5V, G; Ultrasonic sensor to P2 connector.
464图片124.png

Note: stack the motor drive shield onto UNO control board. connect the ultrasonic sensor to motor drive shield’s P2 connector with 4P jumper wire, VCC pin to V, Trig pin to digital 13 (S), Echo pin to digital 12 (S), G pin to GND(G);
connect dot matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5).
Connect the servo motor to motor drive shield. Brown line is for GND, red line (VCC) for 5V, orange line for analog pin A3.
Connect the motor A and motor B to connector A and B separately. Connect the power supply to BAT connector.


Coding:
Now write the program to build an ultrasonic following robot.
First set up and initialize the servo angle to 90°,dot matrix displays a smile pattern.
Go to “Control”, drag out block 0464-pro3图13.png; then go to“Small_Turtle_Robot”, drag and drop the block Ks0464-36.pnginto setup block and set the servo angle to 90° .

And again drag the block Ks0464-37.pngand Ks0464-38.pngbeneath the servo block just made. Here default SDA pin to A4, SCL pin to A5; click the drop-down triangle to select a pattern smile.

Next move on to measure the distance by ultrasonic sensor.

Click “Variables”, drag out the block P10-1.png; and drag the block P10-2.pngfrom “Math” into the block P10-1.png; change“item”into“distance”and set the value 0.

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 “distance”. 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 distance digit. With this box called “distance”, we can store the measured distance digit between ultrasonic sensor and front obstacle. So every time I mention distance, it refers to the distance value measured by the ultrasonic sensor at that time.

Click “Variables”, drag out the block P10-6.png; and drag the block P10-8.pngfrom “Small_Turtle_Robot”into the distance block to make as Ks0464-44.png

To see the distance value measured by ultrasonic sensor on the serial monitor, we drag out the Ks0464-45.pngblock from “SerialPort” ; drag out the block Pro8-图片13.pnginto the Serial printIn block.

And again drag the block Ks0464-47.png into the P9-1.pngblock.
Now we can get a part of code like below:
Ks0464-49.png

Next judge the distance of front obstacle measured by ultrasonic sensor.

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

First when the front obstacle distance detected by ultrasonic sensor is smaller than 10cm, the robot will turn back at a speed of PWM200.

Go to “Control”, drag out the blockPro8-图片14.png, then click the blue gear icon, appear the edit box, drag the P10-14.png block into Pro8-图片15.pngblock twice and then drag the Ks0464-53.pngbeneath the P10-14.png block. So you can get the block:
Pro8-图片17.png

Go to “Logic”, drag the block P3-20.png into the if statement and select“<”; go to “Variables”, drag out the block Pro8-图片13.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-59.png (note you can type the value flexibly.)

Followed by drag out the blockKs0464-60.png from“Small_Turtle_Robot” into the do statement; change the PWM0 into PWM200.
Ks0464-61.png

Next we move on to write the program. When the front obstacle distance detected by ultrasonic sensor is greater than or equal to 10cm, and smaller than 20cm, the robot will stop running.

We duplicate the block Ks0464-59.png twice, and respectively change to “distance≥10” and “distance<20” .

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 10 to 20cm.

So we drag the block “distance≥10” and “distance<20” into the block P10-24.png and drag the block Ks0464-65.pnginto the else if statement.

Followed by drag out the block Ks0464-66.pngfrom “Small_Turtle_Robot” into the do statement.

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

We just duplicate the block Ks0464-65.pngonce and drag it into the second else if statement. And set to “distance≥20” and “distance<50” .

Followed by drag out the block Ks0464-68.pngfrom“Small_Turtle_Robot”into the do statement and set to PWM200.
And duplicate the stop block Ks0464-66.pngand drag it into the else statement.
Ks0464-70.png

Now the code for ultrasonic following robot is finished. Upload the complete code to operate your turtle robot!

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

464图片125.png



What you will see:
464图片126.png

Upload the code success to UNO R3 board; turn the slide switch to ON position.
The servo motor rotates to 90°and 8*8 dot matrix shows a smile face icon.
The turtle robot will walk along the front obstacle.



Little Knowledge:
1.The specific logic of following robot car please refer to the logic table mentioned above.
2.You can change the logic to make the robot follow an object.
For instance, in the source code, we’ve set the robot back when distance is less than 10cm (<10cm). Or you can change the distance value; reset the robot back when distance is less than 15cm (<15cm).



Project 14: Ultrasonic Avoiding Robot

464图片128.png


Circuit Design:
We combine the hardware knowledge -- LED matrix, 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 robot motion and show the running state by dot matrix.
The ultrasonic avoiding capability is almost the same as the ultrasonic following function. We only need to change the source code.

The specific logic of ultrasonic avoiding robot is as shown below:
464图片129.png


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


Hookup Guide:
Connect the servo pin to pin header A3 (S, 5V, G); 8*8 dot matrix to pin header A5, A4, 5V, G; Ultrasonic sensor to P2 connector.
464图片130.png


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

First set up and initialize the servo angle to 90°,dot matrix displays a smile pattern.

Go to “Control”, drag out block 0464-pro3图13.png; then go to“Small_Turtle_Robot”, drag and drop the block Ks0464-36.pnginto setup block and set the servo angle to 90° .


And again drag the block Ks0464-37.pngand Ks0464-38.pngbeneath the servo block just made. Here default SDA pin to A4, SCL pin to A5; click the drop-down triangle to select a pattern smile.

Next move on to measure the distance by ultrasonic sensor.

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 180°;
The variable Ks0464-89.pngstores the right obstacle distance measured by ultrasonic sensor when the servo is at 0°.
Need to initialize the variable“a”“a1”“a2”value to 0 and drag into setup block.
Ks0464-90.png

Click “Variables”, drag out the block Ks0464-104.png; and drag the block P10-8.png from“Small_Turtle_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 15cm, or else greater than or equal to 15cm.

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-99.png

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

Go to “Small_Turtle_Robot”, drag out the block Ks0464-100.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 180.

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-106.png
Next duplicate this piece of code block Ks0464-107.pngonce; set the servo angle 180 to 0; change the variable“j”into“k”; change the Ks0464-105.pnginto Ks0464-109.png.
Ks0464-110.png

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

If the distance a1 is greater than that of a2, set the servo angle to 90°, turtle robot will rotate to left for 400ms at a speed of PWM200 then go front at a speed of PWM200; otherwise, set the servo angle to 90°, turtle robot will rotate to right for 400ms at a speed of PWM200 then go front at a speed of PWM200.

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 the block P3-20.png into the if statement and select“>”; go to “Variables”, drag out the block Ks0464-88.pnginto the first input box at the left side of “>”; drag the Ks0464-89.pnginto the second input box at the right side of “>” .
Ks0464-112.png

Go to “Small_Turtle_Robot”, drag out the blockKs0464-101.png and Ks0464-116.png; set to servo angle 90 and PWM200. Add a delay block 400ms.
Then drag out the Ks0464-117.pngand set to PWM200.
Ks0464-118.png

We duplicate this piece of do block code once and drag into else statement; drag out the block Ks0464-119.pngto replace the block Ks0464-120.pngand set to PWM 200.
Ks0464-121.png

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

Go to“Small_Turtle_Robot”, drag out the block Ks0464-323.pnginto the last else statement and set to PWM 200.

The program for ultrasonic avoiding function has been written well. Upload the complete code to your turtle robot!

Code:
464图片131.png

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



What you will see:
464图片132.png

Upload the code success to UNO R3 board; turn the slide switch to ON position.
The servo motor rotates to 90°and 8*8 dot matrix shows a smile face icon.
The turtle robot will drive forward until it senses an object. When it senses an object in its path, it will reverse and then turn to avoid the obstacle.
464图片133.png



Little Knowledge:
1.The specific logic of following robot car please refer to the logic table mentioned above.
2.When setting the robot car, we’ve set the servo angle separately to 0°and 180°to test the distance between the left and the right direction.




Project 15: IR Remote Control Robot

remote control


Circuit Design:
We combine the hardware knowledge -- LED matrix, 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 robot movement.

The specific logic of infrared remote control robot is as shown below:
464图片134.png


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


Hookup Guide:
Connect the 8*8 dot matrix to pin header A5, A4, 5V, G; IR receiver sensor to P4 connector.
464图片135.png

Note: stack the motor drive shield on the UNO board; connect the infrared receiver sensor to P4(G、V、A1) connector on the motor drive shield.
Connect dot matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5). Respectively connect the motor A and B to connector A and B on the motor drive shield. Connect the power to BAT connector.


Coding:
Now write the program to build an infrared remote control robot.
Go to “Control”, drag out block 0464-pro3图13.png; then go to “Small_Turtle_Robot”, drag and drop the block Ks0464-37.pngand 0464-pro3图17.pnginto setup block. Here default SDA pin to A4, SCL pin to A5; click the drop-down triangle to select a pattern smile.

And then drag the P9-2.pngblock from “SerialPort” into the “setup” block.
Next, navigate the turtle robot move with an IR remote control, and the dot matrix will display the corresponding pattern.

We first click the imported library “Small_Turtle_Robot”, drag out the block P9-3.png; drag the block P9-4.pngfrom “SerialPort” into the infrared receiver block just made. Then go to “Variables”, drag out the block P9-5.pnginto the blockP9-4.png.
Ks0464-133.png

Press the keys to navigate the robot how to run and the dot matrix will display the corresponding pattern.

Here we use the condition statementP13-8.png .

Go to “Control”, drag out the P13-8.pngblock. According to the project 6, we have listed out the string value of each key on infrared remote control.
The front key P13-10.pngis FF629D; back key P13-11.png is FFA857; left keyP13-12.png is FF22DD; right key P13-13.pngis FFC23D;P13-14.png is FF02FD; P13-15.pngis FF30CF;P13-16.png is FF7A85.

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

If ir_rec=0xFF629D, press the key P13-10.png on the IR remote control, the robot will go front at a speed of PWM200 and 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:P9-18.png.

Click the imported library “Small_Turtle_Robot”, drag out the blockKs0464-147.png into do statement and change to PWM200.
And drag out the block Ks0464-148.pngand Ks0464-149.png; select the display pattern front2.
Ks0464-150.png

If ir_rec=0xFFA857, press the key P13-11.pngon the IR remote control, the robot will go back at a speed of PWM200 and dot matrix displays a back pattern.
Duplicate the code block above, just change “0xFF629D” to “0xFFA857” .

Click the imported library“Small_Turtle_Robot”, drag out the block Ks0464-152.pngto replace the blockKs0464-153.png ; set to PWM200 and select the display pattern back2.

Ks0464-154.png

At the same way, if ir_rec=0xFF22DD, press the key P13-12.pngon the IR remote control, the robot will rotate to left at a speed of PWM200 and dot matrix displays a leftward pattern.

If ir_rec=0xFFC23D, press the key P13-13.pngon the IR remote control, the robot will rotate to right at a speed of PWM200 and dot matrix displays a rightward pattern.

If ir_rec=0xFF02FD, press the key P13-14.pngon the IR remote control, the robot will stop.
Duplicate the code string of robot going front mentioned above three times and respectively change to “0xFF22DD”, “0xFFC23D”, “0xFF02FD”.

Click the “Desktop_Car_V3”, respectively drag out the blockKs0464-158.png,Ks0464-159.png ,Ks0464-160.png into the do statement; set to PWM200; click the drop-down triangle to select the display pattern left2, right2, stop2.
Ks0464-161.png

If ir_rec=0xFF30CF, press the key P13-15.pngon the IR remote control, the robot will turn left and dot matrix displays a leftward pattern.
Duplicate the code block of robot going front at a speed of PWM200 and dot matrix displaying a front pattern. And change the “0xFF629D” into “0xFF30CF”. Drag out the blockKs0464-163.png ,replacing the blockKs0464-153.png ; and again drag out the blockKs0464-165.png, replacing the blockKs0464-166.png.
Tick the LedArray1 to draw a leftward pattern.
Ks0464-167.png

If ir_rec=0xFF7A85, press the key P13-16.png on the IR remote control, the robot will turn right and dot matrix displays a rightward pattern.

Duplicate the code block above and change the “0xFF30CF” into “0xFF7A85”.
Drag out the block Ks0464-170.png, replacing the block Ks0464-163.png; set to LedArray2 ; cancel a leftward pattern and tick a rightward pattern.
Ks0464-172.png

Now the code for infrared remote control robot is finished. Upload the complete code to navigate your turtle robot!

Code:
Ks0464-173.png

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



Result:
464图片138.png
Upload the code success to UNO R3 board; turn the slide switch to ON position.
We can navigate the tank robot by IR remote control, at the same time, the LED matrix will display the motion states.
464图片139.png



Little Knowledge:
1.The specific logic of remote control robot please refer to the logic table mentioned above;
2.When setting the smart car, we can combine multiple keys to navigate the multi-function motions of robot car.



Project 16: Bluetooth Controlled Robot

We are now ready to give the turtle 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 robot.

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 LED matrix 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 Turtle_Car compression package to direct install the Turtle_Car APP; installed well, appear the icon below on your mobile phone:
thumb

Download the Turtle_Car package from the link below:
https://drive.google.com/open?id=16JD3LuLzFQBBXSVdquNSAcypa0HFz1Xs


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


2.Tap the Turtle_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. Click the up button 464图片146.pngon the APP, 8*8 dot matrix will display the front icon. Release the button, display the “STOP” icon.


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 Turtle_Car icon464图片147.png to enter the control interface.
thumb



Hookup Guide:
Note: Stack the motor drive shield onto UNO control board. Connect LED matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5). Plug firmly the Bluetooth module (RXD、TXD、GND、VCC) into the motor drive shield (TX、RX、-(GND)、+(VCC)). Connect the power supply to BAT connector.
thumb


Coding:
Write the program to know what signal the Bluetooth module sends.
Go to “Control”, drag out the thumbblock; and drag the thumbblock from “SerialPort” into the “setup” block.

We first click the imported library “Desktop_Car_V3”, drag out the block thumb; drag the block thumbfrom “SerialPort” into the BLE receiver block just made.
Then go to “Variables”, drag out the block thumbinto the blockthumb.
thumb

Upload the code success, connect Bluetooth module, open serial monitor and set the baud rate to 9600. Aimed at Bluetooth module, press the key on the mobile APP, and you can see the corresponding control character of key.
thumb


Below is Turtle Car Bluetooth APP interface and we have listed out what function of each key does:

thumb

thumb


We have read the character of each key on mobile APP via serial port and know the key function.
Click the button thumbon the APP, 8*8 dot matrix will display the front icon; release the button, display the “STOP” icon.

First initialize the dot matrix to display a smile pattern.
Go to “Control”, drag out the setup blockthumb.

Go to“Small_Turtle_Robot”, drag and drop the block thumb and thumbinto setup block. Here default SDA pin to A4, SCL pin to A5; click the drop-down triangle to select a pattern smile.

Here we call the condition statement block thumb.
Go to “Control”, drag out the block thumb, and then go to the “Logic”, drag out the block thumbinto the if statement, and drag out the block thumbfrom the “Variables” into the first input box at the left side of “=” ; drag thethumb from the “Text” into the second input box at the right side of “=”.

When press the buttonthumb , mobile Bluetooth will send a character “F” to Bluetooth module, Bluetooth module will receive the character “F”, so we replace the “a” with “F”. thumb

Click the “Small_Turtle_Robot”, drag the block thumbinto the do statement,click the drop-down triangle icon to select the pattern front2.
thumb
Duplicate this piece of code string once; type “S” and select the pattern stop2.
thumb


Code:
Now we have completed the program. Upload the code success, press and release the key thumb on the Bluetooth APP, check what phenomenon you will see.
Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.

thumb



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 button 464图片146.png on the Bluetooth APP, dot matrix will display the front icon0428图片31.png ; release the button, display the “STOP” icon.
thumb



Bluetooth Remote Control Robot


Circuit Design:
We have introduced how to use Bluetooth APP to control the dot matrix display.
Based on the above section, we now extend to control the motor drive shield, ultrasonic sensor, dot matrix module using several keys on the Bluetooth APP.
Based on the circuit design, we can start building our own Bluetooth remote control robot. Follow the wiring diagram and test code below.


Hookup Guide:

thumb

Note: Stack the motor drive shield onto UNO control board. Connect LED matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5). Plug firmly the Bluetooth module (RXD、TXD、GND、VCC) into the motor drive shield (TX、RX、-(GND)、+(VCC)).
Connect the motor A and motor B to connector A and B separately. Connect the power supply to BAT connector.


Coding:
Write the program to realize the functions we want. Use the buttonKs0464-184.pngthumbthumbthumb and thumbon the Bluetooth APP to navigate the robot go front, back, turn left, turn right, stop and dot matrix will display patterns.

Go to “Control”, drag out block Ks0464-185.png; then go to “Small_Turtle_Robot”, drag and drop the block Ks0464-37.pngand Ks0464-206.pnginto setup block. Here default SDA pin to A4, SCL pin to A5; click the drop-down triangle to select a pattern smile.
And then drag the thumb block from “SerialPort” into the “setup” block.

Next the Bluetooth module will read corresponding Bluetooth signal.

We first click the imported library “Small_Turtle_Robot”, drag out the block thumb; drag the block thumbfrom “SerialPort” into the BLE receiver block just made. Then go to “Variables”, drag out the block thumbinto the blockthumb.

thumb

Press any direction button and stop button, the Bluetooth module will receive corresponding signal, turtle robot will move and stop in the corresponding direction, and dot matrix will show patterns.

So here require to make “option” judgement; we will use the blockthumb from “Control”.
Drag out the block thumb, then click the blue gear icon, appear the edit boxthumb, drag the thumbblock into thumbblock, turning intothumb.

When the value of the "expression" behind the switch block is equal to the value of the "constant expression" behind a case block, the statement following this case is executed.
After executing the statement following a case, the process control is transferred to the next case to continue execution.


Since the Bluetooth APP has several direction buttons, press the different direction buttons to both make the robot move in the corresponding direction and dot matrix shows pattern; press stop button, robot car will stop and dot matrix shows a STOP pattern.
So here we set 5 case statements; click the blue gear icon, appear the edit boxthumb ,drag the thumbblock into thumbblock four times again.

Press the arrow buttons on the APP, robot car will move in the corresponding direction.
Go to the “Variables”, drag out the block thumbinto the switch statement.
Press the button thumb, robot car will go front at a speed of PWM200 and dot matrix shows a front pattern. Go to “Text” , drag the block thumbinto case statement.
Because press the button thumband mobile Bluetooth will send a character “F” to Bluetooth module, Bluetooth module will receive the character “F”, so we replace the “a” with “F”.

Drag the block thumbfrom the “Small_Turtle_Robot”beneath the case ‘F’ statement; change the PWM0 to PWM200.
And drag out the block thumband thumb into the case ‘F’ statement; select the display pattern front2.
thumb

Press the buttonthumb , mobile Bluetooth will send a character “B” to Bluetooth module, Bluetooth module receives the character “B”, robot car will go back at a speed of PWM200 and dot matrix shows a back pattern.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “B”.

Drag the block thumbfrom the“Small_Turtle_Robot” beneath the case statement; change the PWM0 to PWM200.
And drag out the block thumband thumb into the case ‘B’ statement; select the display pattern back2.

Press the button thumb , mobile Bluetooth will send a character “L” to Bluetooth module, Bluetooth module receives the character “L”, robot car will rotate to left at a speed of PWM200 and dot matrix shows a leftward pattern.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “L”.

Drag the block thumbfrom the“Small_Turtle_Robot” beneath the case statement; change the PWM0 to PWM200.
And drag out the block thumband thumb into the case ‘L’ statement; select the display pattern left2.
thumb

Press the button thumb, mobile Bluetooth will send a character “R” to Bluetooth module, Bluetooth module receives the character “R”, robot car will rotate to right at a speed of PWM200 and dot matrix shows a rightward pattern.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “R”.

Drag the block thumbfrom the“Small_Turtle_Robot” beneath the case statement; change the PWM0 to PWM200.
And drag out the block Ks0464-148.pngand Ks0464-149.png into the case ‘R’ statement; select the display pattern right2.

Press the button 464图片159.png, mobile Bluetooth will send a character “S” to Bluetooth module, Bluetooth module receives the character “S”, robot car will stop moving and dot matrix shows a STOP pattern.
Go to “Text” , drag the block Pro9-图片12.pnginto case statement, replacing the “a” with “S”.

Drag the block Ks0464-247.pngfrom the“Small_Turtle_Robot” beneath the case statement.
And drag out the block thumband thumb into the case ‘S’ statement; select the display pattern stop2.


Code:
We have completed the program to realize the functions we want. Use the button button thumbthumbthumbthumb and thumbon the Bluetooth APP to navigate the robot go front, back, turn left, turn right, stop and dot matrix will display patterns.

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


Result:
thumb
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 robot.

Tag the key464图片146.png, go front; tap464图片156.png, go back; press464图片156.png, rotate to left; press464图片157.png, rotate to right; press464图片158.pngand release all the keys, turtle robot stops; press464图片159.png, start mobile direction sensing control, and tap the key again to exit. At the same time, LED matrix will show the robot motion states.
thumb



Little Knowledge:
1.We’ve listed out the control character and function of each key on the Bluetooth APP. So you can change the source code according to the control character. Press different keys to realize different functions.



Project 17: Bluetooth Multi-function Robot


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:

thumb


Test Code:
Write the Bluetooth multiple-function program for controlling the turtle robot.

First initialize the dot matrix to display a smile pattern.

Go to “Control”, drag out block 0464-pro3图13.png; then go to “Small_Turtle_Robot”, drag and drop the block Ks0464-37.pngand 0464-pro3图17.pnginto setup block. Here default SDA pin to A4, SCL pin to A5; click the drop-down triangle to select a pattern smile.

And then drag the P9-2.pngblock from “SerialPort” into the “setup” block.

Next the Bluetooth module will read corresponding Bluetooth signal.

We first click the imported library “Small_Turtle_Robot”, drag out the block Ks0464-208.png; drag the block P9-4.pngfrom “SerialPort” into the BLE receiver block just made.
Then go to “Variables”, drag out the block Pro9-图片3.pnginto the blockP9-4.png.
Ks0464-212.png

Press any direction button and stop button, the Bluetooth module will receive corresponding signal, turtle robot will move and stop in the corresponding direction, and dot matrix will show patterns.

So here require to make “option” judgement; we will use the blockthumb from “Control”.
Drag out the block thumb, then click the blue gear icon, appear the edit box, drag the thumbblock into thumbblock, turning intothumb.

When the value of the "expression" behind the switch block is equal to the value of the "constant expression" behind a case block, the statement following this case is executed.
After executing the statement following a case, the process control is transferred to the next case to continue execution.

Since the Bluetooth APP has several direction buttons, stop button, and button for obstacle avoiding, line tracking, ultrasonic follow function, press the different direction buttons to make the robot move in the corresponding direction and dot matrix shows pattern.

So here we set 8case statements; click the blue gear icon, appear the edit boxthumb ,drag the thumbblock into thumbblock seven times again.

Go to the “Variables”, drag out the block thumbinto the switch statement.
Press the button thumb, robot car will go front at a speed of PWM200 and dot matrix shows a front pattern. Go to “Text” , drag the block thumbinto case statement.
Because press the button thumband mobile Bluetooth will send a character “F” to Bluetooth module, Bluetooth module will receive the character “F”, so we replace the “a” with “F”.

Drag the block thumbfrom the“Small_Turtle_Robot”beneath the case ‘F’ statement; change the PWM0 to PWM200.
And drag out the block thumband thumb into the case ‘F’ statement; select the display pattern front2.
thumb

Press the buttonthumb , mobile Bluetooth will send a character “B” to Bluetooth module, Bluetooth module receives the character “B”, robot car will go back at a speed of PWM200 and dot matrix shows a back pattern.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “B”.
Drag the block thumbfrom the“Small_Turtle_Robot” beneath the case statement; change the PWM0 to PWM200.
And drag out the block thumband thumb into the case ‘B’ statement; select the display pattern back2.

Press the button 30px|frameless|thumb , mobile Bluetooth will send a character “L” to Bluetooth module, Bluetooth module receives the character “L”, robot car will rotate to left at a speed of PWM200 and dot matrix shows a leftward pattern.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “L”. Drag the block thumbfrom the“Small_Turtle_Robot” beneath the case statement; change the PWM0 to PWM200.
And drag out the block thumband thumb into the case ‘L’ statement; select the display pattern left2.

Press the button thumb, mobile Bluetooth will send a character “R” to Bluetooth module, Bluetooth module receives the character “R”, robot car will rotate to right at a speed of PWM200 and dot matrix shows a rightward pattern.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “R”.

Drag the block thumbfrom the“Small_Turtle_Robot” beneath the case statement; change the PWM0 to PWM200.

And drag out the block thumband thumb into the case ‘R’ statement; select the display pattern right2.
Press the button thumb, mobile Bluetooth will send a character “S” to Bluetooth module, Bluetooth module receives the character “S”, robot car will stop moving and dot matrix shows a STOP pattern.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “S”.

Drag the block thumbfrom the“Small_Turtle_Robot” beneath the case statement.
And drag out the block thumband thumb into the case ‘S’ statement; select the display pattern stop2.
thumb

Next write the program for obstacle avoiding, line tracking, ultrasonic following function.
Click the button thumb, mobile Bluetooth will send a character “U” to Bluetooth module, Bluetooth module receives the character “U”, the robot car will start ultrasonic avoiding function.
Go to “Text” , drag the blockthumb into case statement, replacing the “a” with “U”.
Move on to write the code string for ultrasonic avoiding.
Go to “Functions”, we drag out the block thumb and name it asthumb.
Here need to set up a variable.
First go to “Variables”, drag out the block thumb; then drag the block thumbfrom “Math” into value behind; replace “item” with “flag”, and default as an integer, assign the variable “flag” to 0.

Then drag this block thumbinto thumbblock, so that set up a variable block thumb.
Now go to “Variables”, drag out the block thumbinto the blockthumb and assign a value 0.

Go to “Control”, drag out the block into the block thumb. Go to “Logic”, drag the block thumb into the repeat while blockthumb.
And drag the variable block thumbinto the first input box of blockthumb; drag a block thumbinto the second input box of block thumband keep the digit 0.
thumb

Next move on to measure the distance by ultrasonic sensor.

Followed by set up three variables, “a”, “a1”and “a2”.
Click “Variables”, drag out the block thumb; and drag the block thumbfrom “Math” into the block thumb; duplicate thumbtwice and respectively change “item” into“a”, “a1”, “a2”.
So we can get the variables Ks0464-87.png,Ks0464-88.png andKs0464-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 180°;
The variable Ks0464-89.pngstores the right obstacle distance measured by ultrasonic sensor when the servo is at 0°.

Drag the block thumb,thumb and thumb into setup block.


Click “Variables”, drag out the block thumb; and drag the block thumbfrom “Small_Turtle_Robot”into the block thumb; then drag the block thumbinto the do statement of block thumb.
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 15cm, or else greater than or equal to 15cm. 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-99.png

If the distance is smaller than 15cm, turtle robot will stop moving for 500ms; then set the servo angle to 180°, read the a1, delay 300ms; set the servo angle to 0°, read the a2, delay 300ms;

Go to “Small_Turtle_Robot”, drag out the block Ks0464-100.pnginto the do statement. And add a delay block 500ms.

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 180.

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 300ms.
Duplicate this piece of code block once; set the servo angle 180 to 0; change the variable“j”into“k”; change the Ks0464-105.pnginto Ks0464-109.png.
Ks0464-316.png

Next in the case that the front obstacle distance measured by ultrasonic sensor is smaller than 15cm, judge whether the left obstacle distance a1 is greater than the right obstacle distance a2. If the distance a1 is greater than that of a2, set the servo angle to 90°, turtle robot will turn left for 400ms at a speed of PWM200 then go front at a speed of PWM200; otherwise, set the servo angle to 90°, turtle robot will turn right for 400ms at a speed of PWM200 then go front at a speed of PWM200.

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 thumb 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 “” .

Go to“Small_Turtle_Robot”, drag out the block thumbandthumb ; set to servo angle 90 and PWM 200.
Add a delay block 400ms. Then drag out thethumb and set to PWM200.
thumb

We duplicate this piece of do block code once and drag into else statement; drag out the block thumb, replacing the block thumb; and set to PWM 200.

Next judge whether the front obstacle distance measured by ultrasonic sensor is greater than 15cm, turtle robot will go front at a speed of PWM200.
Go to“Small_Turtle_Robot”, drag out the block thumbinto the last else statement and set to PWM 200.
thumb

Click the button thumb, the robot car will exit the ultrasonic avoiding function.

We first drag out the block thumbinto the do statement of the block thumb.
Then go to “Control”, drag out the block thumbinto the block thumb .
And drag out the block thumbfrom “Math” into the if statement.
Then drag the block thumbfrom the “Variables” into the first input box of thumb; drag the block thumbfrom the “Text” into the second input box of thumband change the “a” into “S”.
Go to “Variables”,drag out the block thumbinto the do block thumb; and drag out the block thumbfrom “Math” into the block thumband change value 0 into 1.
thumb

The line tracking function is completed:
thumb
Finally go to “Functions”, we drag out the block thumbinto the main program case ‘X’
Move on to write the code string for ultrasonic following function.

Press the button thumb, mobile Bluetooth will send a character “Y” to Bluetooth module, Bluetooth module receives the character “Y”, robot car will start ultrasonic following function.
Go to “Text” , drag the block thumbinto case statement, replacing the “a” with “Y”.
Then write the program for robot ultrasonic following.
Go to “Functions”, we drag out the block thumb and name it as thumb.
Go to “Variables”, drag out the blockthumb

into the blockthumb and assign a value 0. 

Go to “Control”, drag out the block thumb into the block thumb.
Go to “Logic”, drag the block thumbinto the repeat while block thumb.
And drag the variable block thumbinto the first input box of block thumb; drag a bloc thumbkinto the second input box of block thumb.
thumb

First we set up a variable, “distance”. The variable “distance” means save the distance value measured by ultrasonic sensor.
Click “Variables”, drag out the block thumb; and drag the block thumbfrom “Math” into the block thumb; change“item” into“distance” thumb.
So already build the variable “distance”.
Click “Variables”, drag out the block thumb; and drag the block thumbfrom “Small_Turtle_Robot”into the distance block to make as thumband then drag this block into the do statement of block thumb.

Next judge the distance of front obstacle measured by ultrasonic sensor.
Here we can use the judgement statement “if...do...else if...do...” .
First when the front obstacle distance detected by ultrasonic sensor is smaller than 10cm, the robot will turn back at a speed of PWM200.


Go to “Control”, drag out the block Pro8-图片14.png, then click the blue gear icon, appear the edit box, drag the P10-14.png block into Pro8-图片15.png block two time and then drag the beneath the block. So you can get the block:
P10-16.png





thumb


thumb

thumb

Ks0464-88.png Ks0464-89.png




















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

thumb


Result:
thumb
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 robot by Bluetooth remote control.
Tag the different keys to switch different functions; tap stop button to exit the function.
thumb



Resources

  • Get all the resources here:

https://1drv.ms/u/s!ArhgRvK6-RyJdbBmQ2kCzCJVKY8?e=RbrWBU

  • Video:

http://video.keyestudio.com/ks0464/



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