Ks0428 keyestudio Mini Tank Robot Upgraded V2

From Keyestudio Wiki
Jump to: navigation, search


Keyestudio Mini Tank Robot Upgrade V2



About the tutorial

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

You can find out those awesome improvements as follows:

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


Technical Parameters

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



Packing List


thumb

thumb

thumb

thumb
thumb

thumb


Get Started with Mixly and ARDUINO

1)Installing Arduino IDE

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


See more contents at:


Ks0436-9.png

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

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


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



2)Introduction for Mixly Blocks

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

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



3)Import Robot Library

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


0428图片11.png

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

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

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

0428图片14.png



Get Started with Hardware Projects


Project 1: Built-in LED

Keyestudio UNO R3

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

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

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

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

KS0001 5-2.png Power LED Indicator

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

KS0001 5-3.png Digital I/O

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

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

Used for circuit ground

KS0001 5-5.png AREF

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

KS0001 5-6.png SDA

IIC communication pin

KS0001 5-7.png SCL

IIC communication pin

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

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

KS0001 5-9.png RESET Button

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

KS0001 5-10.png D13 LED

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

KS0001 5-11.png USB Connection

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

KS0001 5-12.png ATMEGA 16U2-MU

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

KS0001 5-13.png TX LED

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

KS0001 5-14.png RX LED

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

KS0001 5-15.png Crystal Oscillator

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

KS0001 5-16.png Voltage Regulator

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

KS0001 5-17.png DC Power Jack

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

KS0001 5-18.png IOREF

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

KS0001 5-19.png RESET Header

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

KS0001 5-20.png Power Pin 3V3

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

KS0001 5-21.png Power Pin 5V

Provides 5V output voltage

KS0001 5-22.png Vin

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

KS0001 5-23.png Analog Pins

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

KS0001 5-24.png Microcontroller

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



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

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

0428图片15.png


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

0428图片16.png

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

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

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

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

0428图片18.png

0428图片19.png



Project 2: Displaying Images

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

keyestudio 8x16 LED matrix panel


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


Parameters:

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


0428图片21.png


Hookup Guide
Stack the V5 sensor shield onto motor drive shield, then stack them on UNO R3 board.
Connect the LED panel to the V5 sensor shield with 4pin wire. Connect the two 18650 batteries for power supply.
0428图片22.png


Test Code:
0428图片23.png


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

0428图片27.png

0428图片28.png



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


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



Extension Practice:
1.Make the LED panel display 7 patterns in a cycle, with a delay time of 500ms for each pattern.



Project 3: Photo Resistor

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

keyestudio photo-resistor module


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


Parameters:

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


Hookup Guide
Connect the LED panel and 2 photocell modules to sensor shield V5.
Connect the left photocell sensor to A1(S, V, G); the right photocell to A2(S, V, G).
Stack the V5 sensor shield onto motor drive shield, then stack them on UNO R3 board. Connect the two 18650 batteries for power supply.
0428图片33.png


Test Code:
0428图片34.png


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

0428图片36.png

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

0428图片37.png


Little Knowledge:

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

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

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

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



Extension Practice:
1.Change the control logic of 2 analog values read by 2 photocell sensors to make the LED panel show different patterns.



Project 4: Ultrasonic Detecting Obstacles

HC-SR04 ultrasonic module


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

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

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


Specifications:

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


Hookup Guide
Connect the ultrasonic sensor to sensor shield V5, VCC pin to 5V(V), Trig pin to digital 5 (S), Echo pin to digital 4 (S), GND pin to GND(G).
0428图片49.png


Test Code:
0428图片50.png


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

0428图片52.png

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

0428图片53.png


Little Knowledge:

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

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

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



Extension Practice:
1.You can reset the control logic. Change the distance value measured by ultrasonic sensor to make the LED panel show different patterns.



Project 5: Infrared Receiving


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

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

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

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

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


  • IR Receiver Module:

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

IR Receiver Module


Parameters of IR Receiver:

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


Hookup Guide:
Connect the IR receiver to Analog 0 (A0).
0428图片60.png


Test Code:
0428图片61.png


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

0428图片63.png

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

0428图片65.png


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



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

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


Extension Practice:
1.Making the LED panel show different patterns by infrared remote control.
2.Driving the 2 motors’ turning direction and speed by infrared remote control.
(refer to project 8- motor driving) Combine infrared receiver and motors driving knowledge to build an infrared remote control car.



Project 6: Bluetooth Module

keyestudio HM-10 Bluetooth-4.0 V3

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


Technical Details:

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


thumb


Pins Description:

thumb


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


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


thumb


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


  • For Android APP:

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

Click Scan Device to search the Bluetooth.
thumb

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

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


  • For mac/iOS APP

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


Click to install the APP, as shown below.
thumb


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

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

thumb

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



Project 7: Adjusting Servo Angle

Servo


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

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

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

thumb

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

thumb


Parameters:

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


Connection Diagram:
Connect the servo pin to digital pin 9

thumb


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


Code 1: without the library

thumb


Code 2: using the library

thumb


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



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

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

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



Extension Practice:
1.Refer to the servo regulation principle and code1 method. Try rotating the servo angle to 0°, 45°and 180°
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.



Project 8: Motor Driving and Speed Control

keyestudio L298P motor shield


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

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

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

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


Parameters:

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


thumb


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

thumb


Connection Diagram:

thumb


Sample Code:

Code 1: without the library

thumb


Code 2: using the library

thumb


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



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

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



Extension Practice:
1.Refer to the motor driving logic and code set; try to reset a new moving track for your smart car.




Get Started with Robot Projects

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

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


Project 9: Tank Robot Installation

0428图片4.png

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


Step 1:install the tank bottom motor

Prepare the parts as follows:

  • M4*12MM inner hex screw * 2
  • M3*8MM inner hex screw * 4
  • M4 nut * 2
  • Blue supporting parts *2
  • Metal holder *2
  • Copper Coupler *2
  • Metal Motor *2


To begin with, separately fix a blue supporting part onto a metal holder using a M4*12MM screw and a M4 nut. Pay more attention to the punch hole.

thumb

thumb

Then screw the gold Copper Coupler to the metal DC motor with screwdriver.
thumb

After that, separately mount metal DC motor onto metal holder with four M3*8MM inner hex screws. See details below.
thumb

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


Step 2:install the tank driver wheel

Prepare the parts as follows:

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


Mount the Tank Load-bearing wheel into the metal DC motor using a M4*12MM inner hex screw. Shown below.
thumb

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

After that, you will get the parts below.
thumb

Fix the tank loading-bearing wheel, Caterpillar Band with the flange bearing and M4 self-locking nut.
thumb

More details is showed below:
thumb

Finally you should get the complete tank wheel below.
thumb

thumbthumb


Step 3: install the battery case

Prepare the parts as follows:

  • M3*10MM flat-head screw * 2
  • M3 nut * 2
  • Battery case *1
  • Blue Metal holder *2
  • M4*35MM inner hex screw *4
  • M4 nut *4
  • M3*25MM inner hex screw *4
  • M3*45MM dual-pass cooper pillar *4


Fix the battery case onto the metal holder with two M3*10MM flat-head screws and two M3 nuts.
thumb

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

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

Then should mount another metal holder on the back with four M4 nuts.
thumb

thumb

Finally screw four M3*25MM inner hex screws and M3*45MM dual-pass copper pillars onto the blue supporting parts.
thumb

thumb


Step 4: mount the sensor module

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

  • Acrylic plate * 1
  • M3*8MM inner hex screw * 4
  • M3*10MM dual-pass copper pillar *4
  • M2*11MM dual-pass copper pillar *4
  • M2*10MM round-head screw * 4


Screw the M3*8MM inner hex screw and M3*10MM dual-pass copper pillar to the acrylic plate.
And screw the M2*10MM inner hex screw and M2*11MM dual-pass copper pillar to the acrylic plate.
thumb

thumb


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

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

thumb

To begin with, connect the jumper wire to IR receiver module, and screw the IR receiver module on the Acrylic plate with a M3 nickel plating nut and a M3*8MM inner hex screw.
thumb
thumb


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


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

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

thumb

Fix the 2 photocell modules on the acrylic plate parts with 2 M3*12MM round-head screws and 2 M3 nickel plating nuts.
thumb

Mount a 8X16 LED panel on the acrylic plate using 4 M2*10MM round-head screw and 4 M2 nickel plating nuts. And connect the HX-2.54 4P jumper wire.
thumb

thumbthumb


Step 5: install the servo plastic platform

Prepare the parts as follows:

  • Servo motor *1
  • Plastic platform parts *1


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

thumb

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

thumb

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


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

Mount the white cross on the black base plate using four M1.2*5MM self-tapping screws.
thumb

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

Show details as below:

thumb

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

Show details as below:

thumb


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

thumb


Step 6: install all the Acrylic plate parts

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

  • M3*12MM round head screw *2
  • M3 nickel plating nut *2
  • M2*10MM round head screw *4

thumb


Mount the ultrasonic servo platform to the bottom Acrylic plate with 4 M2*10MM round head screws.
Pay close attention to servo angle; ensure that the servo angle is in 90° facing front.

thumb

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

thumb




Step 7: Complete tank parts and control board

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

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


Mount the Acrylic part onto tank bottom wheel part with 4 M3*6MM inner hex screws.
thumb

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

thumb

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

First connect the jumper wire to the 2 photocell modules
thumb

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



Hookup Guide

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


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

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

The 4Pin terminal block is marked with silkscreen 1234.

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

thumbthumb

thumb


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

thumb

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


Project 10: Light Follow Tank

0428图片113.png


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

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


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


Hookup Guide:
0428图片115.png


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

0428图片116.png


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



Project 11: Ultrasonic Follow Tank

0428图片118.png


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

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


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


Hookup Guide:
0428图片120.png


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

0428图片121.png


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


Project 12: Ultrasonic Avoiding Tank


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

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

0428图片123.png


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


Hookup Guide:
0428图片124.png


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

0428图片125.png


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


Project 13: Infrared Remote Control Tank


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

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


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


Hookup Guide:
0428图片128.png


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

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


Adding library:

0428图片129.png

0428图片130.png


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


0428图片131.png


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




Project 14: Bluetooth Control Tank

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

KS0193-图片88.png


Bluetooth Remote Control

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

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

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


Parameters of HM-10 Bluetooth Module:

thumb

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


Using Bluetooth APP

  • For Android system:
0428图片138.png

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

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


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


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

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

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

5.Tap the button0428图片144.png, 8x16 LED panel will display the front icon. Release the button, display the “STOP”.



For iOS system:
1.Open the APP store
thumb

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

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

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

thumb



Hookup Guide:
thumb


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


thumb


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



Bluetooth Control Robot


Based on the above section, we now extend to control the sensor modules by several buttons on the Bluetooth APP.
Before build a Bluetooth control robot, we should get the basic understanding of each button on the APP and figure out what function they have.
thumb

thumb


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


Hookup Guide:

thumb


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

thumb


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



Project 15: Bluetooth Multi-function Tank


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


Hookup Guide:
0428图片133.png


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

0428图片134.png


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



Resources

  • Get all the resources here:

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

  • Video:

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


About keyestudio

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

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

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

Logo图片1.png


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


Customer Service

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


Buy From