Table of Contents

Advertisement

Quick Links

www.keyestudio.com
Thanks for your support on our products, we will continue to
provide you better quality and service!
*About keyestudio ............................................................................................ 7
*References and After-sales Service ........................................................... 8
*Warning ............................................................................................................. 8
*Copyright .......................................................................................................... 8
1. Introduction ................................................................................................... 9
2. Features ........................................................................................................ 10
3. Specification ................................................................................................ 11
4.Product List ................................................................................................... 11
5. Assembly Guide ......................................................................................... 18
Step 1: Install Bottom Motor .................................................................. 18
Step 2: Install Driver Wheel ..................................................................... 20
Step 3: Install the Battery Holder ........................................................... 22
Step 4: Mount Acrylic Board and Sensors ............................................ 25
Step 5: Install the Servo Platform ........................................................... 28
Step 6: Install Sensors and Boards ......................................................... 29
Step 7: Hook-up Guide ......................................................................... 32
Step 8: Wire Up LED Panel ................................................................... 35
Content
1

Advertisement

Table of Contents
loading

Summary of Contents for Keyestudio Ks0428

  • Page 1: Table Of Contents

    Thanks for your support on our products, we will continue to provide you better quality and service! Content *About keyestudio .................... 7 *References and After-sales Service ............8 *Warning ......................8 *Copyright ......................8 1. Introduction ....................9 2. Features ......................10 3.
  • Page 2 Step 10: Tank Robot ................43 6. Install Arduino IDE and Driver ............... 44 (1) Installing Arduino IDE ..............44 (2) Keyestudio V4.0 Development Board ........46 (3) Installing V4.0 board Driver ............49 (4) Install other visions of driver ............55 (5) Arduino IDE Setting ................
  • Page 3 (4) Connection Diagram .............. 78 (5) Test Code ..................79 (6) Test Result .................. 80 (7) Code Explanation ..............80 Project 3: Photoresistor Sensor ............85 (1) Description ................85 (2) Specification ................86 (3) Equipment ................. 86 (4) Test Code ..................87 (5) Test Result ..................
  • Page 4 (2) Specification ................100 (3) Equipment ................100 (4) The principle of ultrasonic sensor ........101 (5) Connection Diagram ............103 (6) Test Code ................. 104 (7) Test Result ................106 (8) Code Explanation ..............106 (9) Extension Practice: ..............107 Project 6: IR Reception ...............
  • Page 5 (6) Download APP ................ 123 (7) Code Explanation ..............128 (8) Extension Practice ..............128 Project 8: Motor Driving and Speed Control ....... 130 (1) Description ................130 (2) Specification ................131 (3) Drive Robot to Move ............133 (4) Equipment ................
  • Page 6 (1) Description ................161 (2) Connection Diagram ............163 (3) Test Code ................. 165 (4) Test Result ................168 Project 11: Ultrasonic Avoid Tank ........... 169 (1) Description ................169 (2) Flow chart ................172 (3) Connection Diagram: ............172 (4) Test Code: ................
  • Page 7: About Keyestudio

    9. Resources ....................247 *About keyestudio Keyestudio is a best-selling brand owned by KEYES Corporation, our product lines range from controller boards, shields and sensor modules to smart car and complete starter kits for Arduino, Raspberry Pi and BBC micro:bit, which designed for customers of any level to learn electronics and programming knowledge.
  • Page 8: References And After-Sales Service

    *Copyright The keyestudio trademark and logo are the copyright of KEYES DIY ROBOT co.,LTD. All products under keyestudio brand can’t be copied, sold and resold without authorization by anyone or company. If you ’ re interested in our items, please contact to our sales fennie@keyestudio.com...
  • Page 9: Introduction

    1. Introduction Nowadays, technological education such as VR, kids programming, and artificial intelligence, has become mainstream in educational industry. Thereby, people attach importance to STEM education. Arduino is pretty notable in Maker education. So what is Arduino? Arduino is an open-source electronics platform based on easy-to-use hardware and software.
  • Page 10: Features

    Keyestudio team has designed a mini tank robot. The tank robot has a processor which is programmable using the Arduino IDE, to mapped its pins to sensors and actuators by a shield that plug in the processor, it reads sensors and controls the actuators and decides how to operate.
  • Page 11: Specification

    5. Multiple controls: IR remote control, App control(IOS and Android system) 6. Basic programming:C language code of Arduino IDE. 3. Specification Working voltage: 5v Input voltage: 7-12V Maximum output current: 2A Maximum power dissipation: 25W (T=75℃) Motor speed: 5V 200 rpm/min Motor drive mode: dual H bridge drive (L298P) Ultrasonic induction angle: <15 degrees...
  • Page 12 Electronic Parts Name Picture KEYESTUDIO V4.0 Development Board L298P Shield V5 Sensor Shield HC-SR04 Ultrasonic Sensor HM-10 Bluetooth-4.0 Module Remote Control 8X16 LED Panel...
  • Page 13 HX-2.54 4P Female Dupont Line 9G Servo Motor IR Receiver Module Photocell Sensor Red LED Components Acrylic Board Tank Robot Acrylic Board...
  • Page 14 Metal Holder L-type Bracket Tank Driver Wheel Tank Load-bearing Wheel Caterpillar Band Metal Motor Plastic Platform (PC) USB Cable (1m) 2.54 3pin F-F Dupont Wire 20cm...
  • Page 15 F-F Dupont Wire (15CM) Supportive Parts (27*27*16MM, Blue) 18650 2-Slot Battery Holder (Not included)18650 Battery Tip:We recommend you to purchase it on Ebay or wish Nuts/Screws Copper Bush Flange Bearing Hexagon Copper Bush(M3*10MM) Hexagon Copper Bush (M3*45MM) Copper Coupler...
  • Page 16 Inner Hexagon Screws (M3*6MM) Inner Hexagon Screws (M3*8MM) Inner Hexagon Screws (M3*25MM) Inner Hexagon Screws (M4*12MM) Inner Hexagon Screws (M4*40MM) Inner Hexagon Screws (M4*50MM) M3 Nuts M4 Self-locking Nuts M2 Nuts...
  • Page 17 M4 Nuts M2*10MM Round Head Screws M3*12MM Round Head Screws Tools 2.0*40MM Blue and Black Slotted Screwdriver 2.0*40MM Purple and Black Phillips Screwdriver M1.5 Hex Key Nickel Plated Allen Wrench M2.5 Hex Key Nickel Plated Allen Wrench M3 Hex Key Nickel Plated...
  • Page 18: Assembly Guide

    Decorative Cardboard 5. Assembly Guide After making an inventory all the parts in this kit, then we need to mount the tank robot. Let’s install smart car in compliance with the following instructions. Note: Peel the plastic film off the board first when installing smart car.
  • Page 19  Blue Supportive Parts *2  M4*12MM Inner Hex Screw * 2  M1.5 Hex Key Nickel Plated Allen Wrench *1  M3 Hex Key Nickel Plated Allen Wrench *1  M2.5 Hex Key Nickel Plated Allen Wrench *1...
  • Page 20: Step 2: Install Driver Wheel

    Step 2: Install Driver Wheel Prepare the parts as follows:  M4*12MM Inner Hex Screw * 2  M4*50MM Inner Hex Screw * 2  Tank Load-bearing Wheel * 2  Flange Bearing * 4  Copper Bush *2 ...
  • Page 21 www.keyestudio.com...
  • Page 22: Step 3: Install The Battery Holder

    Step 3: Install the Battery Holder Prepare the parts as follows:  Battery Holder *1  M3 Nut * 2  Blue Metal holder *2  M4 Nut *8  M3*10MM Flat Head Screw * 2  M4*40MM Inner Hex Screw *4 ...
  • Page 23 Finish the mount process. Go to fix the metal holder on the motor wheel with four M4*40MM inner hex screws and four M4 nuts.
  • Page 24 www.keyestudio.com...
  • Page 25: Step 4: Mount Acrylic Board And Sensors

    Step 4: Mount Acrylic Board and Sensors  Acrylic Board * 2  L- type Black Bracket *1  Photocell Sensor *2  IR Receiver Module *1  8X16 LED Panel *1  M2 Nut *4  M3 Nut *10...
  • Page 26  M2.5 Hex Key Allen Wrench *1  M3*12MM Round Head Screw *7  M3*10MM Hexagon Copper Bush *8  M2*10MM Round Head Screw * 4...
  • Page 27 www.keyestudio.com...
  • Page 28: Step 5: Install The Servo Platform

    Step 5: Install the Servo Platform Prepare the parts as follows:  Servo *1  Black Gimbal *1  Cable Tie *2  M2x8 Round Head Cross Tapping Screw *2  Ultrasonic Sensor *1  M2*4 Screw *1  M1.2*5 Screw *4 Note: for convenient debugging, keep the ultrasonic module straight ahead and the angle of servo motor 90°.
  • Page 29: Step 6: Install Sensors And Boards

    Step 6: Install Sensors and Boards...
  • Page 30 Prepare the parts as follows:  M3*6MM Round Head Screw *12  L298P Shield *1  V4.0 Board *1  V5 Sensor Shield *1  Screwdriver *1  Bluetooth Module *1...
  • Page 31 www.keyestudio.com...
  • Page 32: Step 7: Hook-Up Guide

    Step 7: Hook-up Guide...
  • Page 33 www.keyestudio.com...
  • Page 34 www.keyestudio.com...
  • Page 35: Step 8: Wire Up Led Panel

    Step 8: Wire Up LED Panel...
  • Page 36 LED Panel V5 Sensor Shield -(GND) +(VCC) Step 9: install all parts of Acrylic plate...
  • Page 37 www.keyestudio.com...
  • Page 38 www.keyestudio.com...
  • Page 39 www.keyestudio.com...
  • Page 40 www.keyestudio.com...
  • Page 41 www.keyestudio.com...
  • Page 42 www.keyestudio.com...
  • Page 43: Step 10: Tank Robot

    Step 10: Tank Robot Note: Remove the Bluetooth module before uploading test code, otherwise, you will fail to upload test code.
  • Page 44: Install Arduino Ide And Driver

    6. Install Arduino IDE and Driver (1) Installing Arduino IDE When we get control board, we need to download Arduino IDE and driver firstly. You could download Arduino IDE from the official website: https://www.arduino.cc/, click the SOFTWARE on the browse bar,...
  • Page 45 There are various versions Of IDE for Arduino, just download a version that compatible with your system, here we will show you how to download and install the windows version Arduino IDE. There are two versions of IDE for WINDOWS system, you can choose between the installer (.exe) and the Zip packages.
  • Page 46: Keyestudio V4.0 Development Board

    You just need to click JUST DOWNLOAD. (2) Keyestudio V4.0 Development Board We need to know keyestudio V4.0 development board, as a core of this smart car. keyestudio V4.0 development board is an Arduino uno-compatible...
  • Page 47 ATmega328P MCU, and with a cp2102 C hip as a UART-to-USB converter. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connecti...
  • Page 48 It contains everything needed to support the microcontroller; simp ly connect it to a computer with a USB cable or power it via an ext ernal DC power jack (DC 7-12V) or via female headers Vin/ GND(D C 7-12V) to get started.
  • Page 49: Installing V4.0 Board Driver

    50 mA 32 KB (ATmega328P-PU) of Flash Memory which used bootloader SRAM 2 KB (ATmega328P-PU) EEPROM 1 KB (ATmega328P-PU) Clock Speed 16 MHz LED_BUILTIN (3) Installing V4.0 board Driver Let’s install the driver of keyestudio V4.0 board. The USB-TTL chip...
  • Page 50 V4.0 board adopts CP2102 serial chip. The driver program of this chip is included in Arduino 1.8 version and above, which is convenient. Plug on USB port of board, the computer can recognize the hardware and automatically install the driver of CP2102.
  • Page 51 Click “ OK” to enter the following page, click “ browse my computer for updated driver software”, find out the installed or downloaded ARDUINO software. As shown below:...
  • Page 52 There is a DRIVERS folder in Arduino software installed package ( ), open driver folder and you can see the driver of CP210X series chips. We click “Browse”, then find out the driver folder, or you could enter “driver” to search in rectangular box, then click “next” , the driver will be installed successfully.
  • Page 53 Open device manager, we will find the yellow exclamation mark disappear. The driver of CP2102 is installed successfully.
  • Page 54 www.keyestudio.com...
  • Page 55: Install Other Visions Of Driver

    (4) Install other visions of driver If your development board is Arduino UNO board, install the driver as follows: Step 1: Plug in the development board, click Computer----- Properties----- Device Manager, you could see the unknown device is shown.
  • Page 56 Step 3: click“browse my computer for updated driver software” Step 4: find out the folder where the ARDUINO software is installed, drivers click folder and tap“Next”...
  • Page 57 Step 5: the driver is installed successfully. The device manager shows the serial port of Arduino.
  • Page 58: Arduino Ide Setting

    (5) Arduino IDE Setting Click icon,open Arduino IDE.
  • Page 59 To avoid the errors when uploading the program to the board, you need to select the correct Arduino board that matches the board connected to your computer. Then come back to the Arduino software, you should click Tools→ Board, select the board. (as shown below)
  • Page 60 Before uploading the program to the board, let’s demonstrate the function of each symbol in the Arduino IDE toolbar.
  • Page 61: Start First Program

    A- Used to verify whether there is any compiling mistakes or not. B- Used to upload the sketch to your Arduino board. C- Used to create shortcut window of a new sketch. D- Used to directly open an example sketch.
  • Page 62 Set board and COM port, the corresponding board and COM port are shown on the lower right of IDE.
  • Page 63 Click to start compiling the program, check errors.
  • Page 64: How To Add Libraries

    Click to upload the program, upload successfully. Upload the program successfully, the onboard LED lights on for 1s, lights off for 1s. Congratulation, you finish the first program. 7. How to Add Libraries? What are Libraries ? Libraries are a collection of code that makes it easy for you to connect to a sensor,display, module, etc.
  • Page 65 There are hundreds of additional libraries available on the Internet for download. The built-in libraries and some of these additional libraries are listed in the reference. Here we will introduce the most simple way for you to add libraries .
  • Page 66 Step 3: Next to find out the “libraries” of tank robot(seen in the link: , you just need to replicate and paste into https://fs.keyestudio.com/KS0428) libraries folder of Arduino IDE.
  • Page 67 Download them from the link and unzip them. Then add them into libraries of Arduino 1.8.13, as shown below:...
  • Page 68: Projects

    Now, you import libraries successfully. 8.Projects The whole project begins with basic program. Starting from simple to complex, the lessons will guide you to assemble robot car and absorb the knowledge of electronic and machinery step by step. I reckon that you could hardly sit still and itch to have a go, let’s get...
  • Page 69: Project 1: Led Blink

    Note: (G), marked on each sensor and module, is negative pole and connected to “G” , ” -” or “GND” on the sensor shield and control board ; (V) is positive pole and linked with V , VCC, + or 5V on the sensor shield or control board.
  • Page 70: Description

    (1) Description For the starter and enthusiast, this is a fundamental program---LED Blink. LED, the abbreviation of light emitting diodes, consist of Ga, As, P, N chemical compound and so on. The LED can flash diverse color by altering the delay time in the test code. When in control, power on GND and VCC, the LED will be on if S end is high level;...
  • Page 71: Equipment

    LED display color: red (3) Equipment (4) V5 Sensor Shield There will be troublesome when we combine Arduino development boards with numerous sensors. However, the V5 sensor shield, compatible with Arduino development board, address this problem perfectly. Just stack V5 board on it.
  • Page 72 Connection Diagram: Seen from the above diagram, LED is linked with D2...
  • Page 73: Test Code

    (5) Test Code keyestudio Mini Tank Robot V2 lesson 1.1 Blink http://www.keyestudio.com void setup() pinMode(2, OUTPUT);// initialize digital pin 2 as an output. void loop() // the loop function runs over and over again forever digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000);...
  • Page 74: Test Result

    (6) Test Result (There will be contradict about serial communication between code Bluetooth when uploading code, therefore, don’t link with Bluetooth module before uploading code.) Upload the program on the development board, LED flickers with the interval of 1s.
  • Page 75: Extension Practice

    We succeed to blink LED. Next, let’s observe what LED will change if we modify pins and delay time. Connection Diagram We’ve altered pins and connected LED to D10. Test Code: keyestudio Mini Tank Robot V2 lesson 1.2 delay http://www.keyestudio.com...
  • Page 76: Project 2: Adjust Led Brightness

    { // initialize digital pin 10 as an output. pinMode(10, OUTPUT); // the loop function runs over and over again forever void loop() { digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for 0.1 second digitalWrite(10, LOW);...
  • Page 77 PWM is a means of controlling the analog output via digital means. Digital control is used to generate square waves with different duty cycles (a signal that constantly switches between high and low levels) to control the analog output.In general, the input voltage of port are 0V and 5V.
  • Page 78: Specification

    It actually outputs 25 pictures per second. In this case, the human can ’ t tell it, neither does PWM. If want different voltage, need to control the ratio of 0 and 1. The more 0,1 signals output per unit time, the more accurately control.
  • Page 79: Test Code

    (5) Test Code keyestudio Mini Tank Robot V2 lesson 2.1 http://www.keyestudio.com int ledPin = 10; // Define the LED pin at D10 int value; void setup () pinMode (ledPin, OUTPUT); // initialize ledpin as an output. void loop ()
  • Page 80: Test Result

    (value = 0; value <255; value = value + 1) analogWrite (ledPin, value); // LED lights gradually light up delay (5); // delay 5MS for (value = 255; value> 0; value = value-1) analogWrite (ledPin, value); // LED gradually goes out delay (5);...
  • Page 81 Round 2:2 → 3 → 4 … Until number 2 is not established, “for”loop is over, After knowing this order, go back to code: for (int value = 0; value < 255; value=value+1){ for (int value = 255; value >0; value=value-1){ The two“for”statements make value increase from 0 to 255, then...
  • Page 82 PWM is a technology to obtain analog quantity through digital method. Digital control forms a square wave, and the square wave signal only has two states of turning on and off (that is, high or low levels). By controlling the ratio of the duration of turning on and off, a voltage varying from 0 to 5V can be simulated.
  • Page 83 (8) Extension Practice: Let’s modify the value of delay and remain the pin unchanged, then observe how LED changes. keyestudio Mini Tank Robot V2 lesson 2.2 pwm-slow http://www.keyestudio.com int ledPin = 10; // Define the LED pin at D10 int value;...
  • Page 84 () for (value = 0; value <255; value = value + 1) analogWrite (ledPin, value); // LED lights gradually light up delay (30); // delay 30MS for (value = 255; value> 0; value = value-1) analogWrite (ledPin, value); // LED gradually goes out delay (30);...
  • Page 85: Project 3: Photoresistor Sensor

    Project 3: Photoresistor Sensor (1) Description The photoresistor is a special resistor made of semiconductor materials such as CdS or Selenide septum. The surface is also coated with moisture-proof resin, which has a photoconductive effect. It is sensitive to ambient light. Its resistance varies from different light intensities.
  • Page 86: Specification

    (2) Specification Resistance:5K ohm-0.5Mohm Interface Type: analog Working Voltage: 3.3V-5V Easy installation: with screw fixing holes Pin spacing: 2.54mm (3) Equipment Connection Diagram:...
  • Page 87: Test Code

    The two photoresistor sensors are linked with A1 and A2, then finish the experiment via photoresistor connected to A1. Let’s read its analog value. (4) Test Code keyestudio Mini Tank Robot V2 lesson 3.1 photocell http://www.keyestudio.com int sensorPin = A1;...
  • Page 88: Test Result

    Serial.begin(9600); void loop() { sensorValue = analogRead(sensorPin); // read the value from the sensor: Serial.println(sensorValue); //Serial port prints the resistance value delay(500); //****************************************************** (5) Test Result Upload code on development board, open serial monitor, check if its value diminishes when covering photoresistor. However, the value increases when uncovered.
  • Page 89: Extension Practice

    LED and view the status of LED. PWM restrains the brightness, so LED is linked with PWM pins, connect LED to pin 10, keep pin of photoresistor unchanged, then design the code: /*keyestudio Mini Tank Robot V2 lesson 3.2 photocell-analog output http://www.keyestudio.com...
  • Page 90 = A1; // Analog input pin that the photocell is attached to int analogOutPin = 10; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0;...
  • Page 91: Project 4: Servo Control

    //*************************************************************** Upload code, press it by hand to observe the the LED brightness. Project 4: Servo Control (1) Description Servo motor is a position control rotary actuator. It mainly consists of housing, circuit board, core-less motor, gear and position sensor.
  • Page 92 When the motor speed is constant, the potentiometer is driven to rotate through the cascade reduction gear, which leads that the voltage difference is 0, and the motor stops rotating. Generally, the angle range of servo rotation is 0° --180 °...
  • Page 93: Specification

    The corresponding servo angles are shown below: (2) Specification Working voltage: DC 4.8V ~ 6V Operating angle range: about 180 ° (at 500 → 2500 μsec) Pulse width 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 ±...
  • Page 94: Equipment

    Stop current: ≦ 850mA (DC 4.8V) ≦ 1000mA (DC 6V) Standby current: 3 ± 1mA (DC 4.8V) 4 ± 1mA (DC 6V) (3) Equipment (4) Connection Diagram: Wiring note: the brown line of servo is linked with Gnd(G), the red line is connected to 5v(V) and orange line is attached to digital 9.
  • Page 95: Test Code1

    (5) Test Code1 keyestudio Mini Tank Robot V2 lesson 4.1 Servo http://www.keyestudio.com #define servoPin 9 //servo Pin int pos; //angle variable of servo int pulsewidth; // pulse width variable of servo void setup() { pinMode(servoPin, OUTPUT); //set servo pin to OUTPUT procedure(0);...
  • Page 96 (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees procedure(pos); // tell servo to go to position in variable 'pos' delay(15); // function to control servo void procedure(int myangle) { pulsewidth = myangle * 11 + 500;...
  • Page 97: Test Code2

    There is another guide for restraining servo---- servo library file, the following link of official website is for your reference. https://www.arduino.cc/en/Reference/Servo The library file of servo is used in the following code (6) Test Code2 keyestudio Mini Tank Robot V2 lesson 4.2 servo http://www.keyestudio.com #include <Servo.h>...
  • Page 98: Test Result

    { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15);...
  • Page 99: Project 5: Ultrasonic Sensor

    #include <Servo.h> Arduino comes with (servo function and statement) The following are some common statements of the servo function: 1. attach ( interface ) — — Set servo interface, port 9 and 10 are available 3. write(angle)——The statement to set rotation angle of servo, the angle range is from 0°...
  • Page 100: Specification

    HC-SR04 ultrasonic sensor is being used in a wide range of electronics projects for creating obstacle detection distance measuring application as well as various other applications. Here we have brought the simple method to measure the distance with arduino and ultrasonic sensor and how to use ultrasonic sensor with arduino.
  • Page 101: The Principle Of Ultrasonic Sensor

    (4) The principle of ultrasonic sensor As the above picture shown, it is like two eyes. One is transmitting end, the other is receiving end. The ultrasonic module will emit the ultrasonic waves after trigger signal. When the ultrasonic waves encounter the object and are...
  • Page 102 Trigger signals 10us high level Send ultrasonic waves Send 8t 40KHz ultrasonic pulses Module gets the time gap of transmission and reception...
  • Page 103: Connection Diagram

    (5) Connection Diagram...
  • Page 104: Test Code

    Trig → 5(S) Echo → 4(S) → Gnd(G) (6) Test Code keyestudio Mini Tank Robot V2 lesson 5 Ultrasonic sensor http://www.keyestudio.com int trigPin = 5; // Trigger int echoPin = 4; // Echo long duration, cm, inches; void setup() { //Serial Port begin Serial.begin (9600);...
  • Page 105 OUTPUT); pinMode(echoPin, INPUT); void loop() { // The sensor is triggered by a HIGH pulse of 10 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH);...
  • Page 106: Test Result

    Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(250); //**************************************************************** (7) Test Result Upload test code on the development board, open serial monitor and set baud rate to 9600. The detected distance will be displayed, unit is cm and inch. Hinder the ultrasonic sensor by hand, the displayed distance value gets smaller.
  • Page 107: Extension Practice

    = 4; this is defined as the pin of reception, generally input cm = (duration/2) / 29.1; inches = (duration/2) / 74; 0.0135 We can calculate the distance by using the following formula: distance = (traveltime/2) x speed of sound The speed of sound is: 343m/s = 0.0343 cm/uS = 1/29.1 cm/uS...
  • Page 108 Mini Tank Robot V2 lesson 5 Ultrasonic LED http://www.keyestudio.com int trigPin = 5; // Trigger int echoPin = 4; // Echo long duration, cm, inches; void setup() { //Serial Port begin Serial.begin (9600); //Define inputs and outputs pinMode(trigPin, OUTPUT);...
  • Page 109 // The sensor is triggered by a HIGH pulse of 10 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the signal from the sensor: a HIGH pulse whose // duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object.
  • Page 110: Project 6: Ir Reception

    Serial.print("cm"); Serial.println(); delay(250); if (cm>=2 && cm<=10) digitalWrite(10, HIGH); delay(1000); digitalWrite(10, LOW); delay(1000); //**************************************************************** Upload test code to development board and block ultrasonic sensor by hand, then check if LED is on Project 6: IR Reception (1) Description There is no doubt that infrared remote control is ubiquitous in daily life.
  • Page 111 The 38K infrared carrier signal emitted by remote controller is encoded by the encoding chip in the remote controller. It is composed of a section of pilot code, user code, user inverse code, data code, and data inverse code. The time interval of the pulse is used to distinguish whether it is a 0 or 1 signal and the encoding is made up of these 0, 1 signals.
  • Page 112: Specification

    VCC and GND. It is very convenient to communicate with arduino and other microcontrollers. (2) Specification Operating Voltage: 3.3-5V(DC) Interface: 3PIN Output Signal: Digital signal Receiving Angle: 90 degrees Frequency: 38khz Receiving Distance: 10m (3) Equipment...
  • Page 113: Connection Diagram

    (4) Connection Diagram Respectively link“-” 、 “ +”and S of IR receiver module with G(GND) , V(VCC)and A0 of keyestudio development board. Attention: On the condition that digital ports are not available, analog ports can be regarded as digital ports. A0 equals to D14, A1 is equivalent to digital 15.
  • Page 114 6 IRremote http://www.keyestudio.com #include <RremoteTank.h> // IRremote library statement int RECV_PIN = A0; //define the pins of IR receiver as A0 IRrecv irrecv(RECV_PIN); decode_results results; // decode results exist in the“result”of “decode results” void setup() Serial.begin(9600); irrecv.enableIRIn(); //Enable receiver void loop() { if (irrecv.decode(&results))//decode successfully, receive a set...
  • Page 115: Test Result

    IR receiver and the corresponding value will be shown, if pressing so long, the error codes will appear Below we have listed out each button value of keyestudio remote control. So you can keep it for reference.
  • Page 116: Code Explanation

    (7) Code Explanation irrecv.enableIRIn(): after enabling IR decoding, the IR signals will be received, then function “ decode() ” will check continuously if decode successfully. irrecv.decode(&results): after decoding successfully, this function will come back to “ true ” , and keep result in “ results ” . After...
  • Page 117 /* keyestudio Mini Tank Robot V2 lesson 6.2 IRremote http://www.keyestudio.com #include <RremoteTank.h> int RECV_PIN = A0;//define the pin of IR receiver as A0 int LED_PIN=10;//define the pin of LED int a=0; IRrecv irrecv(RECV_PIN); decode_results results; void setup() Serial.begin(9600);...
  • Page 118 // Initialize the IR receiver pinMode(LED_PIN,OUTPUT);//set LED_pin to OUTPUT void loop() { if (irrecv.decode(&results)) { if(results.value==0xFF02FD &a==0) // according to the above key value, press“OK”on remote control , LED will be controlled digitalWrite(LED_PIN,HIGH);//LED will be on a=1; else if(results.value==0xFF02FD &a==1) //press again digitalWrite(LED_PIN,LOW);//LED will go off...
  • Page 119: Project 7: Bluetooth Remote Control

    Project 7: Bluetooth Remote Control (1) Description Bluetooth, a simple wireless communication module most popular since the last few decades and easy to use are being used in most of the battery-powered devices. Over the years, there have been many upgrades of Bluetooth standard to keep fulfil the demand of customers and technology according to the need of time and situation.
  • Page 120: Specification

    (2) Specification Bluetooth protocol: Bluetooth Specification V4.0 BLE No byte limit in serial port Transceiving In open environment, realize 100m ultra-distance communication with iphone4s 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.
  • Page 121: Connection Diagram

    3. TXD: serial interface, transmitting terminal. 4. GND: Ground. 5. VCC: positive pole of the power source. 6. EN/BRK: break connect, it means breaking the Bluetooth connection, generally, keep it unconnected. (5) Test Code keyestudio Mini Tank Robot v2.0 lesson 7.1 bluetooth http://www.keyestudio.com...
  • Page 122 //character variable: save the value of Bluetooth reception void setup() { Serial.begin(9600); void loop() { if(Serial.available() > 0) //make sure if there is data in serial buffer ble_val = Serial.read(); //Read data from serial buffer Serial.println(ble_val); //Print...
  • Page 123: Download App

    (6) Download APP The code is for reading the received signal, and we also need a stuff to send signal. In this project, we send signal to control robot car via cellphone. Then we need to download the APP.
  • Page 124 BLE Scanner, then download. Enter Google Play to find out And allow APP to access “location” , you could enable “location” in settings of your cellphone. 3. After installation, open App and enable “ Location and Bluetooth” permission. 4. We take iOS version as example. The operation method of Android version is almost same as it.
  • Page 125 6. After connecting to HMSoft, click it to get multiple options, such as device information, access permission, general and custom service. Choose “CUSTOM SERVICE” 7.Then pop up the following page...
  • Page 126 8. Click(Read,Notify,WriteWithoutResponse)to enter the following page...
  • Page 127 Write Value, appear the interface to enter HEX or Text. 9. Click 10. Open the serial monitor on Arduino,enter a 0 or other character at Text interface.
  • Page 128: Code Explanation

    Then click“Write”, open serial monitor to view if there is a “0” signal (7) Code Explanation Serial.available() : The current rest characters when return to buffer area. Generally, this function is used to judge if there is data in buffer. When Serial.available()>0, it means that serial receives the data and can be read Serial.read():Read a data of a Byte in buffer of serial port, for...
  • Page 129 Mini Tank Robot v2.0 lesson 7.2 Bluetooth http://www.keyestudio.com int ledpin=11; void setup() {Serial.begin(9600); pinMode(ledpin,OUTPUT); void loop() { int i; if (Serial.available()) {i=Serial.read();...
  • Page 130: Project 8: Motor Driving And Speed Control

    Serial.println("DATA RECEIVED:"); if(i=='1') { digitalWrite(ledpin,1); Serial.println("led on"); if(i=='0') { digitalWrite(ledpin,0); Serial.println("led off"); }}}//******************************************* Click“Write”on APP, when you enter 1, LED will be on, when you input 0, LED will be off. (Remember to remove the Bluetooth module after finishing experiment, otherwise, code-burning will be...
  • Page 131: Specification

    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.
  • Page 132 1) Logic part input voltage: DC5V 2) Driving part input voltage: DC 7-12V 3) Logic part working current: <36mA 4) Driving part working current: <2A 5) Maximum power dissipation: 25W (T=75℃) 6) Working temperature: -25℃~+130℃ 7) Control signal input level: high level 2.3V<Vin<5V, low level...
  • Page 133: Drive Robot To Move

    (3) Drive Robot to Move Through the above circuit diagram, the direction pin of A motor is D12, and speed pin is D3; D13 is the direction pin of B motor, D11 is speed pin. We know how to control digital ports according to the following chart.
  • Page 134: Equipment

    Tank Motor (A) Motor (B) Robot Forward Turn clockwise Backward Turn anticlockwise Rotate to Turn Turn clockwise left anticlockwise Rotate to Turn clockwise Turn anticlockwise right Stop Stop Stop (4) Equipment (5) Connection Diagram...
  • Page 135: Test Code

    1, black line is linked with end 2. The red line of left front motor is attached to terminal 3, black line is linked with port 4. (6) Test Code keyestudio Mini Tank Robot v2.0 lesson 8.1 motor driver http://www.keyestudio.com...
  • Page 136 #define ML_Ctrl 13 //define the direction control pin of left motor #define ML_PWM 11 //define the PWM control pin of left motor #define MR_Ctrl 12 //define direction control pin of right motor #define MR_PWM 3 // define the PWM control pin of right...
  • Page 137 200 digitalWrite(MR_Ctrl,LOW);//set the direction control pin of right motor to LOW analogWrite(MR_PWM,200);//set the PWM control speed of right motor to 200 //front delay(2000);//delay in 2s digitalWrite(ML_Ctrl,HIGH);//set the direction control pin of left motor to HIGH analogWrite(ML_PWM,200);//set the PWM control speed of left motor to 200 digitalWrite(MR_Ctrl,HIGH);//set the direction control pin of right...
  • Page 138 LOW analogWrite(MR_PWM,200);//set the PWM control speed of right motor to 200 //left delay(2000);//delay in 2s digitalWrite(ML_Ctrl,LOW);//set the direction control pin of left motor to LOW analogWrite(ML_PWM,200);//set the PWM control speed of left motor to 200 digitalWrite(MR_Ctrl,HIGH);//set the direction control pin of right...
  • Page 139: Test Result

    //stop delay(2000);//delay in 2s }//***************************************** (7) Test Result Hook up by connection diagram, upload code and power on, smart car goes forward and back for 2s, turns left and right for 2s, stops for 2s and alternately. (8) Code Explanation...
  • Page 140 Mini Tank Robot v2.0 lesson 8.2 motor driver pwm http://www.keyestudio.com #define ML_Ctrl 13 //define the direction control pin of left motor #define ML_PWM 11 //define the PWM control pin of left motor #define MR_Ctrl 12 //define the direction control pin of right...
  • Page 141 OUTPUT);//define the PWM control pin of left motor as OUTPUT pinMode(MR_Ctrl, OUTPUT);//define the direction control pin of right motor as OUTPUT pinMode(MR_PWM, OUTPUT);//define the PWM control pin of right motor as OUTPUT void loop() { digitalWrite(ML_Ctrl,LOW);//Set direction control pin of left motor to LOW analogWrite(ML_PWM,100);// Set the PWM control speed of left...
  • Page 142 HIGH level analogWrite(MR_PWM,250);//Set the PWM control speed of right motor to 100 //back delay(2000);//define 2s digitalWrite(ML_Ctrl,HIGH);//Set direction control pin of left motor to HIGH level analogWrite(ML_PWM,250);//Set the PWM control speed of left motor to 100 digitalWrite(MR_Ctrl,LOW);//Set direction control pin of right...
  • Page 143: Project 9: 8*16 Led Board

    8*16 LED board If we add a to the robot, it will be amazing. Keyestudio's 8*16 dot matrix can meet your requirements. You can create facial emoticons, patterns or other interesting displays yourself. 8*16 LED light board comes with 128 LEDs. The data of the...
  • Page 144: Specification

    HX-2.54 4Pin wiring. (2) Specification Working voltage: DC 3.3-5V Power loss: 400mW Oscillation frequency: 450KHz Drive current: 200mA Working temperature: -40~80℃ Communication method: two-wire bus (3) Equipment (4) 8*16 Dot Matrix Display Circuit Graph...
  • Page 145 How to control each led light of 8*16 dot matrix? We know that a byte has 8 bits, each bit is 0 or 1. When a bit is 0, turn off LED and when a bit is 0, turn on LED. Thereby, one byte can control the LED in a row of dot matrix, so 16 bytes can control 16 columns of led lights, that is, 8*16 dot matrix.
  • Page 146 Description address Irrelevant automatically Irrelevant Fixed address choice, choice, Universal mode fill in 0 fill in 0 Test mode ③ For address command setting, the address can be selected as shown below. The first 00H is selected in our sample program, and the binary...
  • Page 147 SCL is low level, the signal on SDA can be altered. The data input is low-order first, high-order is behind ⑤ The condition to end data transmission is that when SCL is low, SDA is low, and when SCL is high, the SDA level also becomes high.
  • Page 148 ①Open links to enter the following page. ②The dot matrix is 8*16 in this project, so set the height to 8, width to 16, as shown below.
  • Page 149: Connection Diagram

    ③ Generate hexadecimal data from the pattern As shown below, press the left mouse button to select, the right button to cancel, draw the pattern you want, click Generate, and the hexadecimal data we need will be produced. (5) Connection Diagram...
  • Page 150: Test Code

    (Note: This pin is connected to arduino IIC, but this module is not IIC communication, it can be linked with any two pins.) (6) Test Code The code that shows smile face keyestudio Mini Tank Robot v2.0 lesson 9.1 Matrix face http://www.keyestudio.com //the data of smiley from modulus tool unsigned char smile[] = {0x00, 0x00, 0x1c, 0x02, 0x02, 0x02, 0x5c, 0x40, 0x40, 0x5c, 0x02, 0x02, 0x02, 0x1c, 0x00, 0x00};...
  • Page 151 //clear the display //matrix_display(clear); void loop(){ matrix_display(smile); // display smile face // the function for dot matrix display void matrix_display(unsigned char matrix_value[]) IIC_start(); // use the function of the data transmission start condition IIC_send(0xc0); //select address for(int i = 0;i < 16;i++) //pattern data has 16 bits IIC_send(matrix_value[i]);...
  • Page 152 IIC_end(); //the condition to start conveying data void IIC_start() digitalWrite(SCL_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); //Convey data void IIC_send(unsigned char send_data) for(char i = 0;i < 8;i++) //Each byte has 8 bits 8bit for every character digitalWrite(SCL_Pin,LOW); // pull down clock pin SCL_Pin to change the signal of SDA delayMicroseconds(3);...
  • Page 153 1 or 0 of every bit digitalWrite(SDA_Pin,HIGH); else digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); digitalWrite(SCL_Pin,HIGH); //pull up the clock pin SCL_Pin to stop transmission delayMicroseconds(3); send_data = send_data >> 1; // detect bit by bit, shift the data to the right by one...
  • Page 154: Test Result

    //****************************************************** (7) Test Result Wire according to connection diagram. The DIP switch is dialed to right end and power on, the smile face appears on dot matrix. (8) Extension Practice...
  • Page 155 We use the modulo tool (http://dotmatrixtool.com/#)to make the dot matrix alternately display start, go front and stop patterns then clear the patterns, the time interval is 2000 milliseconds. Get the graphical code to be displayed via modulus tool Start:...
  • Page 156 : 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00 The code that the multiple patterns shift: /* keyestudio Mini Tank Robot v2.0 lesson 9.2 Matrix loop http://www.keyestudio.com //Array, used to store the data of the pattern, can be calculated by yourself or obtained from the modulus tool...
  • Page 157 00,0x00,0x00,0x00}; unsigned char back[] = {0x00,0x00,0x00,0x00,0x00,0x24,0x48,0x90,0x48,0x24,0x00,0x00,0x 00,0x00,0x00,0x00}; unsigned char left[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0x10,0x44,0x28,0x10,0x 44,0x28,0x10,0x00}; unsigned char right[] = {0x00,0x10,0x28,0x44,0x10,0x28,0x44,0x10,0x28,0x44,0x00,0x00,0x 00,0x00,0x00,0x00}; unsigned char STOP01[] = {0x2E,0x2A,0x3A,0x00,0x02,0x3E,0x02,0x00,0x3E,0x22,0x3E,0x00,0x 3E,0x0A,0x0E,0x00}; unsigned char clear[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,0x00}; #define SCL_Pin A5 //Set clock pin to A5...
  • Page 158 // Display start pattern delay(2000); matrix_display(front); //Front pattern delay(2000); matrix_display(STOP01); //Stop pattern delay(2000); matrix_display(clear); //Clear the display Clear the screen delay(2000); // This function is used to display of dot matrix void matrix_display(unsigned char matrix_value[]) IIC_start();...
  • Page 159 IIC_start(); IIC_send(0x8A); //display control, set pulse width to 4/16 IIC_end(); //The condition starting to transmit data void IIC_start() digitalWrite(SCL_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); //Convey data void IIC_send(unsigned char send_data) for(char i = 0;i < 8;i++) //Each byte has 8 bits digitalWrite(SCL_Pin,LOW);...
  • Page 160 1 or 0 of every bit digitalWrite(SDA_Pin,HIGH); else digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); digitalWrite(SCL_Pin,HIGH); //pull up clock pin SCL_Pin to stop transmitting data delayMicroseconds(3); send_data = send_data >> 1; //detect bit by bit, so shift the data right by one...
  • Page 161: Project 10: Light Follow Robot

    //***************************************************** Upload code on development board, 8*16 dot matrix displays front , back and stop patterns, alternately. Project 10: Light Follow Robot (1) Description We’ve introduce how to use various sensors, modules. In this lesson, we combine with hardware knowledge --...
  • Page 162 Just need to 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.
  • Page 163: Connection Diagram

    We make a flow chart based on the above logic table, as shown below: (2) Connection Diagram...
  • Page 164 Attention: The 4Pin terminal block is marked with silkscreen 1234. The red line of right rear motor is connected to terminal 1, black line is linked with end 2. The red line of left front motor is attached to terminal 3, black line is linked with port 4.
  • Page 165: Test Code

    → G(GND) → V(VCC) → (3) Test Code keyestudio Mini Tank Robot v2.0 lesson 10 Light-following tank http://www.keyestudio.com #define light_L_Pin A1 //define the pin of left photo resistor #define light_R_Pin A2 //define the pin of right photo resistor...
  • Page 166 Serial.begin(9600); pinMode(light_L_Pin, INPUT); pinMode(light_R_Pin, INPUT); pinMode(ML_Ctrl, OUTPUT); pinMode(ML_PWM, OUTPUT); pinMode(MR_Ctrl, OUTPUT); pinMode(MR_PWM, OUTPUT); void loop(){ left_light = analogRead(light_L_Pin); right_light = analogRead(light_R_Pin); Serial.print("left_light_value = "); Serial.println(left_light); Serial.print("right_light_value = "); Serial.println(right_light); if (left_light > 650 && right_light > 650) //the value detected photo resistor,go front...
  • Page 167 Car_left(); else if (left_light <= 650 && right_light > 650) //the value detected photo resistor,turn right Car_right(); else //other situations, stop Car_Stop(); void Car_front() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,200); void Car_left() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,200);...
  • Page 168: Test Result

    Car_right() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,200); void Car_Stop() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,0); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,0); //**************************************************************** (4) Test Result Upload code on keyestudio V4.0 development board, DIP switch is dialed to right end and power on, the smart robot follows light to...
  • Page 169: Project 11: Ultrasonic Avoid Tank

    Project 11: Ultrasonic Avoid Tank (1) Description In this program, the ultrasonic sensor detects the distance of obstacle to send signals that control the robot car. Next, let’s show you how to make an obstacle avoidance car. The specific logic of ultrasonic avoiding robot is as shown...
  • Page 170 (servo angle a2(unit:cm) 20°) measured distance of left obstacle (servo angle a1(unit:cm) 160°) Settings Servo initial angle 90° Condition State Stop 1 second; set the servo angle to 160°, reading a1, delay 500ms; set the servo angle to 20°, reading a2, delay 500ms;...
  • Page 171 Set the servo to 90 ° , rotate to right ( PWM a1<a2 set to 255)for 0.5s, go front ( PWM set to 200) Conditi State on 2 Set the servo to 90 ° , rotate to left (PWM set to 255 )...
  • Page 172: Flow Chart

    (2) Flow chart (3) Connection Diagram:...
  • Page 173: Test Code

    G (GND) , V (VCC) and D9 of expansion board. The VCC, Trig, Echo and Gnd of ultrasonic sensor are linked with 5v(V), 5(S), Echo and Gnd(G) of expansion board. (4) Test Code: keyestudio Mini Tank Robot v2.0 lesson 11 ultrasonic_avoid_tank http://www.keyestudio.com int random2;...
  • Page 174 #define Trig 5 //ultrasonic trig Pin #define Echo 4 //ultrasonic echo Pin int distance; #define servoPin 9 //servo Pin int pulsewidth; /************the function to run motor**************/ void Car_front() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,200); void Car_back() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,HIGH); analogWrite(ML_PWM,200); void Car_left()
  • Page 175 Car_right() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,255); void Car_Stop() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,0); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,0); //The function to control servo void procedure(int myangle) { for (int i = 0; i <= 50; i = i + (1)) { pulsewidth = myangle * 11 + 500;...
  • Page 176 - pulsewidth / 1000)); //The function to control ultrasonic sensor float checkdistance() { digitalWrite(Trig, LOW); delayMicroseconds(2); digitalWrite(Trig, HIGH); delayMicroseconds(10); digitalWrite(Trig, LOW); float distance = pulseIn(Echo, HIGH) / 58.00; //58.20, that is, 2*29.1=58.2 delay(10); return distance;...
  • Page 177 OUTPUT); pinMode(Echo, INPUT); pinMode(ML_Ctrl, OUTPUT); pinMode(ML_PWM, OUTPUT); pinMode(MR_Ctrl, OUTPUT); pinMode(MR_PWM, OUTPUT); void loop(){ random2 = random(1, 100); a = checkdistance(); //assign the front distance detected by ultrasonic sensor to variable a if (a < 20) //when the front distance detected is less than 20 Car_Stop();...
  • Page 178 //Ultrasonic platform turns right for (int k = 1; k <= 10; k = k + (1)) { a2 = checkdistance(); //assign the right distance detected by ultrasonic sensor to variable a2 if (a1 < 50 || a2 < 50) //robot will turn to the longer distance side when left or right distance is less than 50cm.
  • Page 179 //If both side is greater than or equal to 50cm, turn left or right randomly if ((long) (random2) % (long) (2) == 0) //When the random number is even procedure(90); Car_left(); //tank robot turns left delay(500); Car_front(); //go front else procedure(90);...
  • Page 180: Test Result

    Car_front(); //go front //**************************************************************** (5) Test Result Upload code successfully, DIP switch is dialed to right end and power on, tank robot goes forward and automatically avoids the obstacle. Project 12: Ultrasonic Follow Tank...
  • Page 181: Description

    (1) Description In project 11, we made an obstacle avoidance car. In fact, we only need to alter a test code to transform an obstacle avoidance car into following car. In this lesson, we will make an ultrasonic follow robot.
  • Page 182: Flow Chart

    (2) Flow chart (3) Connection Diagram...
  • Page 183: Test Code

    Wire-up note: 1.8x16 LED panel V5 Sensor Shield → -(GND) → +(VCC) → → (4) Test Code keyestudio Mini Tank Robot v2.0 lesson 12 ultrasonic follow tank...
  • Page 184 //Array, used to store the data of the pattern, can be calculated by yourself or obtained from the modulus tool unsigned char start01[] {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x80,0x40,0x20,0x10,0x 08,0x04,0x02,0x01}; unsigned char front[] {0x00,0x00,0x00,0x00,0x00,0x24,0x12,0x09,0x12,0x24,0x00,0x00,0x 00,0x00,0x00,0x00}; unsigned char back[] {0x00,0x00,0x00,0x00,0x00,0x24,0x48,0x90,0x48,0x24,0x00,0x00,0x 00,0x00,0x00,0x00}; unsigned char left[] {0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0x10,0x44,0x28,0x10,0x 44,0x28,0x10,0x00};...
  • Page 185 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,0x00}; #define SCL_Pin A5 //Set clock pin to A5 #define SDA_Pin A4 //Set data pin to A4 #define ML_Ctrl 13 //define the direction control pin of left motor #define ML_PWM 11 //define PWM control pin of left motor...
  • Page 186 //set servo to 90° pinMode(Trig, OUTPUT); pinMode(Echo, INPUT); pinMode(ML_Ctrl, OUTPUT); pinMode(ML_PWM, OUTPUT); pinMode(MR_Ctrl, OUTPUT); pinMode(MR_PWM, OUTPUT); void loop(){ distance = checkdistance(); //assign the distance detected by ultrasonic sensor to distance if (distance >= 20 && distance <= 60) //range to go front Car_front();...
  • Page 187 //other situations, stop Car_Stop(); /***********the function for motor running****************/ void Car_front() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,200); void Car_back() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,HIGH); analogWrite(ML_PWM,200); void Car_left() digitalWrite(MR_Ctrl,LOW);...
  • Page 188 Car_right() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,200); void Car_Stop() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,0); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,0); /******************dot matrix********************/ // the function for dot matrix display void matrix_display(unsigned char matrix_value[])
  • Page 189 IIC_start(); // call the function that data transmission start IIC_send(0xc0); //Choose address for(int i = 0;i < 16;i++) //pattern data has 16 bits IIC_send(matrix_value[i]); //data to convey patterns IIC_end(); //end to convey data pattern IIC_start(); IIC_send(0x8A); //select pulse width4/16, control display IIC_end();...
  • Page 190 // transmit data void IIC_send(unsigned char send_data) for(char i = 0;i < 8;i++) //Each byte has 8 bits digitalWrite(SCL_Pin,LOW); //pull down clock pin SCL Pin to change the signals of SDA delayMicroseconds(3); if(send_data & 0x01) //set high and low level of SDA_Pin according to 1 or 0 of every bit digitalWrite(SDA_Pin,HIGH);...
  • Page 191 = send_data >> 1; // detect bit by bit, so move the data right by one //The sign that data transmission ends void IIC_end() digitalWrite(SCL_Pin,LOW); delayMicroseconds(3); digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); digitalWrite(SCL_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,HIGH); delayMicroseconds(3); /***************end dot matrix display******************/ //The function to control servo void procedure(int myangle) { for (int i = 0;...
  • Page 192: Test Result

    - pulsewidth / 1000)); //The function to control ultrasonic sensor function controlling ultrasonic float checkdistance() { digitalWrite(Trig, LOW); delayMicroseconds(2); digitalWrite(Trig, HIGH); delayMicroseconds(10); digitalWrite(Trig, LOW); float distance = pulseIn(Echo, HIGH) / 58.20; //58.20, that is , 2*29.1=58.2 delay(10);...
  • Page 193: Project 13: Ir Remote Robot Tank

    Project 13: IR Remote Robot Tank (1) Description IR remote control is one of most ubiquitous control, applied in TV, electric fan and some household appliances. In this project, we will make an IR remote smart car. And we’ve known every key value on IR remote control.
  • Page 194: Flow Chart

    8X16 LED matrix panel shows an icon “V” Remote control Key value Key state Go front(PWM set to 200) FF629D 8X16 LED panel shows front icon Go back(PWM set to 200) FFA857 8X16 LED panel shows back icon Turn left...
  • Page 195: Connection Diagram

    (3) Connection Diagram Attention:GND,VCC, SDA, SCL of 8x16 LED panel are respectively linked with -(GND), +(VCC), SDA ,SCL. And “-”、“+” and S of IR receiver module are attached to G(GND), V(VCC) and A0 on sensor shield. On the condition of insufficient digital ports, the...
  • Page 196: Test Code

    15. (4) Test Code keyestudio Mini Tank Robot v2.0 lesson 13 IR remote tank http://www.keyestudio.com #include <IRremoteTank.h> IRrecv irrecv(A0); //set IRrecv irrecv to A0 decode_results results; long ir_rec; //save the IR value received //Array, used to store the data of the pattern, can be calculated by...
  • Page 197 {0x00,0x00,0x00,0x00,0x00,0x24,0x48,0x90,0x48,0x24,0x00,0x00,0x00, 0x00,0x00,0x00}; unsigned char left[] {0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0x10,0x44,0x28,0x10,0x44, 0x28,0x10,0x00}; unsigned char right[] {0x00,0x10,0x28,0x44,0x10,0x28,0x44,0x10,0x28,0x44,0x00,0x00,0x00, 0x00,0x00,0x00}; unsigned char STOP01[] {0x2E,0x2A,0x3A,0x00,0x02,0x3E,0x02,0x00,0x3E,0x22,0x3E,0x00,0x3E, 0x0A,0x0E,0x00}; unsigned char clear[] {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00}; #define SCL_Pin A5 //Set clock pin to A5 #define SDA_Pin A4 //Set data pin to A4...
  • Page 198 #define servoPin 9 //pin of servo int pulsewidth; //save the pulse width value of servo void setup(){ Serial.begin(9600); irrecv.enableIRIn(); //Initialize the IR reception library pinMode(ML_Ctrl, OUTPUT); pinMode(ML_PWM, OUTPUT); pinMode(MR_Ctrl, OUTPUT); pinMode(MR_PWM, OUTPUT); pinMode(SCL_Pin,OUTPUT); pinMode(SDA_Pin,OUTPUT); matrix_display(clear); //Clear Screen matrix_display(start01); //show start picture pinMode(servoPin, OUTPUT);...
  • Page 199 String type="UNKNOWN"; String typelist[14]={"UNKNOWN", "NEC", "SONY", "RC5", "RC6", "DISH", "SHARP", "PANASONIC", "JVC", "SANYO", "MITSUBISHI", "SAMSUNG", "LG", "WHYNTER"}; if(results.decode_type>=1&&results.decode_type<=13){ type=typelist[results.decode_type]; Serial.print("IR TYPE:"+type+" "); Serial.println(ir_rec,HEX); irrecv.resume(); if (ir_rec == 0xFF629D) //Go forward Car_front(); matrix_display(front); //Display front image if (ir_rec == 0xFFA857) //Robot car goes back Car_back();...
  • Page 200 (ir_rec == 0xFF22DD) //Robot car turns left Car_T_left(); matrix_display(left); //Display left-turning image if (ir_rec == 0xFFC23D) //Robot car turns right Car_T_right(); matrix_display(right); //Display right-turning image if (ir_rec == 0xFF02FD) //Robot car stops Car_Stop(); matrix_display(STOP01); //show stop image if (ir_rec == 0xFF30CF) //robot car rotates anticlockwise Car_left();...
  • Page 201 Car_right(); matrix_display(right); //show clockwise rotation picture /******************Control Servo*******************/ void procedure(int myangle) { for (int i = 0; i <= 50; i = i + (1)) { pulsewidth = myangle * 11 + 500; digitalWrite(servoPin,HIGH); delayMicroseconds(pulsewidth); digitalWrite(servoPin,LOW); delay((20 - pulsewidth / 1000));...
  • Page 202 IIC_send(matrix_value[i]); //data to convey patterns IIC_end(); //end to convey data pattern IIC_start(); IIC_send(0x8A); //display control, set pulse width to 4/16 IIC_end(); //The condition starting to transmit data void IIC_start() digitalWrite(SCL_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); //传输数据 void IIC_send(unsigned char send_data) for(char i = 0;i <...
  • Page 203 //pull down clock pin SCL Pin to change the signals of SDA delayMicroseconds(3); if(send_data & 0x01) //set high and low level of SDA_Pin according to 1 or 0 of every bit digitalWrite(SDA_Pin,HIGH); else digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); digitalWrite(SCL_Pin,HIGH); //pull up clock pin SCL_Pin to stop transmitting data delayMicroseconds(3);...
  • Page 204 IIC_end() digitalWrite(SCL_Pin,LOW); delayMicroseconds(3); digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); digitalWrite(SCL_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,HIGH); delayMicroseconds(3); /***************the function to run motor***************/ void Car_front() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,200); void Car_back() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,200);...
  • Page 205 Car_left() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,HIGH); analogWrite(ML_PWM,255); void Car_right() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,255); void Car_Stop() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,0); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,0);...
  • Page 206: Test Result

    Car_T_left() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,180); void Car_T_right() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,180); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,255); //********************************************************* ******* (5) Test Result Upload code successfully and power on, the smart robot can be controlled by IR remote, at same time, the corresponding pattern is...
  • Page 207: Project 14: Bluetooth Control Robot

    HM-10 Bluetooth module as a Slave and the cellphone as a Host. keyes BT car is an APP rolled out by keyestudio team. You could control the robot car by it readily. There is a guide to how to download and install APP in the...
  • Page 208: Test Code

    (2) Test Code keyestudio Mini Tank Robot v2.0 lesson 14.1 bluetooth test http://www.keyestudio.com char ble_val; //character variables, used to save the value of Bluetooth reception void setup() { Serial.begin(9600); void loop() { if(Serial.available() > 0) //judge if there is data in buffer area...
  • Page 209 { ble_val = Serial.read(); //read the data from serial buffer Serial.println(ble_val); //print out }}//************************************************************** Pull off the Bluetooth module, upload test code, reconnect Bluetooth module, open serial monitor and set baud rate to 9600. Point at Bluetooth module and press keys on APP, the corresponding character is shown below.
  • Page 210: Connection Diagram

    (3) Connection Diagram...
  • Page 211 Wiring Attention: 8x16 LED panel Expansion Board → -(GND) → +(VCC) → → Insert Bluetooth module vertically, you don’t need to attach to its STATE and BRK pins...
  • Page 212: Test Code

    (4) Test Code Note: Remove the Bluetooth module before uploading test code, otherwise, you will fail to upload test code. keyestudio Robot Car v2.0 lesson 14.2 bluetooth car http://www.keyestudio.com //Array, used to store the data of pattern, can be calculated by...
  • Page 213 {0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0x10,0x44,0x28,0x10,0x 44,0x28,0x10,0x00}; unsigned char right[] {0x00,0x10,0x28,0x44,0x10,0x28,0x44,0x10,0x28,0x44,0x00,0x00,0x 00,0x00,0x00,0x00}; unsigned char STOP01[] {0x2E,0x2A,0x3A,0x00,0x02,0x3E,0x02,0x00,0x3E,0x22,0x3E,0x00,0x 3E,0x0A,0x0E,0x00}; unsigned char clear[] {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,0x00}; #define SCL_Pin A5 //Set clock pin to A5 #define SDA_Pin A4 //Set data pin to A4 #define ML_Ctrl 13 //define direction control pin of left motor...
  • Page 214 Serial.begin(9600); pinMode(SCL_Pin,OUTPUT); pinMode(SDA_Pin,OUTPUT); matrix_display(clear); //Clear the display matrix_display(start01); //display start pattern pinMode(ML_Ctrl, OUTPUT); pinMode(ML_PWM, OUTPUT); pinMode(MR_Ctrl, OUTPUT); pinMode(MR_PWM, OUTPUT); void loop(){ if (Serial.available()) bluetooth_val = Serial.read(); Serial.println(bluetooth_val); switch (bluetooth_val) case 'F': //forward command Car_front();...
  • Page 215 // show forward design break; case 'B': //Back command Car_back(); matrix_display(back); //show back pattern break; case 'L': // left-turning instruction Car_left(); matrix_display(left); //show “left-turning” sign break; case 'R': //right-turning instruction Car_right(); matrix_display(right); //display right-turning sign break; case 'S': //stop command Car_Stop();...
  • Page 216 IIC_start(); IIC_send(0xc0); //Choose address for(int i = 0;i < 16;i++) //pattern data has 16 bits IIC_send(matrix_value[i]); //data to convey patterns IIC_end(); //end to convey data pattern IIC_start(); IIC_send(0x8A); //display control, set pulse width to 4/16 IIC_end();...
  • Page 217 //transmit data void IIC_send(unsigned char send_data) for(char i = 0;i < 8;i++) //Each byte has 8 bits digitalWrite(SCL_Pin,LOW); //pull down clock pin SCL Pin to change the signals of SDA delayMicroseconds(3); if(send_data & 0x01) //set high and low level of SDA_Pin according to 1 or 0 of every bit digitalWrite(SDA_Pin,HIGH);...
  • Page 218 = send_data >> 1; // Detect bit by bit, so move the data right by one //The sign that data transmission ends void IIC_end() digitalWrite(SCL_Pin,LOW); delayMicroseconds(3); digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); digitalWrite(SCL_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,HIGH); delayMicroseconds(3); /*************the function to run motor**************/ void Car_front() digitalWrite(MR_Ctrl,LOW);...
  • Page 219 Car_back() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,HIGH); analogWrite(ML_PWM,200); void Car_left() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,HIGH); analogWrite(ML_PWM,255); void Car_right() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,255); void Car_Stop()
  • Page 220: Test Result

    Car_T_left() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,180); void Car_T_right() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,180); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,255); //**************************************************************** (5) Test Result...
  • Page 221: Project 15: Multi-Purpose Robot Car

    Upload code successfully, DIP switch is dialed to right end and power on. After connecting Bluetooth, we could drive smart car to move by Bluetooth App. Press ,tank robot goes forward;click ,smart car goes back; press button, tank robot turns left; click ,...
  • Page 222: Description

    (1) Description In previous projects, the tank car only performs single function, however, in this lesson, we integrate all of function to control smart car via Bluetooth control. Here is a simple flow chart of multi-purpose robot car as for your reference.
  • Page 223 Attention:Confirm that every component is connected.
  • Page 224 Wire-up Guide: 8x16 LED panel Expansion Board → -(GND) → +(VCC) → → Ultrasonic Module → 5v(V) Trig → 5(S) Echo → 4(S) → Gnd(G)
  • Page 225 Servo Motor Brown Wire → Gnd(G) Red Wire → 5v(V) Orange Wire →...
  • Page 226 Bluetooth Module → → → -(GND) +(VCC) No need to attach to STATE and BRK pins...
  • Page 227 IR Receiver Module Sensor Shield → G(GND) → V(VCC) →...
  • Page 228: Test Code

    Left photo resistor Sensor Shield → G(GND) → V(VCC) → Right Photo Sensor Shield resistor → G(GND) → V(VCC) → (3) Test Code...
  • Page 229 Mini Tank Robot v2.0 lesson 15 multiple functions http://www.keyestudio.com //Array, used to store the data of the pattern, can be calculated by yourself or obtained from the modulus tool unsigned char start01[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x80,0x40,0x20,0x10,0x 08,0x04,0x02,0x01}; unsigned char front[] = {0x00,0x00,0x00,0x00,0x00,0x24,0x12,0x09,0x12,0x24,0x00,0x00,0x 00,0x00,0x00,0x00};...
  • Page 230 STOP01[] = {0x2E,0x2A,0x3A,0x00,0x02,0x3E,0x02,0x00,0x3E,0x22,0x3E,0x00,0x 3E,0x0A,0x0E,0x00}; unsigned char clear[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,0x00}; #define SCL_Pin A5 //Set clock pin to A5 #define SDA_Pin A4 //Set data pin to A4 #define ML_Ctrl 13 //define direction control pin of left motor #define ML_PWM 11...
  • Page 231 #define servoPin 9 //servo Pin int pulsewidth; #define light_L_Pin A1 //define the pin of left photo resistor sensor #define light_R_Pin A2 //define the pin of right photo resistor sensor int left_light; int right_light; char bluetooth_val; //save the value of Bluetooth reception int flag;...
  • Page 232 OUTPUT); procedure(90); //set servo to 90° pinMode(SCL_Pin,OUTPUT); pinMode(SDA_Pin,OUTPUT); matrix_display(clear); //Clear the display matrix_display(start01); //display start pattern pinMode(light_L_Pin, INPUT); pinMode(light_R_Pin, INPUT); void loop(){ if (Serial.available()) bluetooth_val = Serial.read(); Serial.println(bluetooth_val); switch (bluetooth_val) case 'F': //Forward instruction Car_front(); matrix_display(front); //display forward pattern...
  • Page 233 'B': //Back instruction Car_back(); matrix_display(back); // display back pattern break; case 'L': //left-turning instruction Car_left(); matrix_display(left); //show left-turning pattern break; case 'R': //right-turning instruction Car_right(); matrix_display(right); //show right-turning pattern break; case 'S': //stop instruction Car_Stop(); matrix_display(STOP01); //display stop pattern break;...
  • Page 234 'X': matrix_display(start01); //show start pattern light_track(); break; /*****************Obstacle Avoidance Function**************/ void avoid() flag = 0; //the design that enter obstacle avoidance function while (flag == 0) random2 = random(1, 100); a = checkdistance(); //assign the front distance detected by ultrasonic sensor to variable a if (a <...
  • Page 235 (int j = 1; j <= 10; j = j + (1)) { ///for statement, the data will be more accurate if ultrasonic sensor detect a few times. a1 = checkdistance(); //assign the left distance detected by ultrasonic sensor to variable a1 delay(200);...
  • Page 236 Car_right(); //robot turns right delay(500); Car_front(); //go forward else //both distance on two side is greater than or equal to 50cm, turn randomly if ((long) (random2) % (long) (2) == 0) //when the random number is even procedure(90);...
  • Page 237 Car_right(); //robot turns right delay(500); Car_front(); ///go forward } } } else //If the front distance is greater than or equal to 20cm, robot car will go front Car_front(); //go forward // receive the Bluetooth value to end the obstacle avoidance function if (Serial.available())
  • Page 238 = checkdistance(); //assign the distance detected by ultrasonic sensor to distance if (distance >= 20 && distance <= 60) //the range to go front Car_front(); else if (distance > 10 && distance < 20) //the range to stop Car_Stop();...
  • Page 239 = 1; //end loop }}}} //The function to control ultrasonic sensor the function controlling ultrasonic sensor float checkdistance() { digitalWrite(Trig, LOW); delayMicroseconds(2); digitalWrite(Trig, HIGH); delayMicroseconds(10); digitalWrite(Trig, LOW); float distance = pulseIn(Echo, HIGH) / 58.00; //58.20 means 2*29.1=58.2 delay(10);...
  • Page 240 /****************Light Follow******************/ void light_track() { flag = 0; while (flag == 0) { left_light = analogRead(light_L_Pin); right_light = analogRead(light_R_Pin); if (left_light > 650 && right_light > 650) //the value detected by photo resistor, go forward Car_front(); else if (left_light > 650 && right_light <= 650) //the value detected by photo resistor, turn left Car_left();...
  • Page 241 //other situations, stop Car_Stop(); if (Serial.available()) bluetooth_val = Serial.read(); if (bluetooth_val == 'S') { flag = 1; }}}} /***************Dot Matrix *****************/ // this function is used for dot matrix display void matrix_display(unsigned char matrix_value[]) IIC_start(); IIC_send(0xc0); //Choose address for(int i = 0;i <...
  • Page 242 IIC_send(0x8A); //display control, set pulse width to 4/16 IIC_end(); //The condition starting to transmit data void IIC_start() digitalWrite(SCL_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,HIGH); delayMicroseconds(3); digitalWrite(SDA_Pin,LOW); delayMicroseconds(3); //convey data void IIC_send(unsigned char send_data) for(char i = 0;i < 8;i++) //each byte has 8 bits digitalWrite(SCL_Pin,LOW);...
  • Page 243 //pull up clock pin SCL_Pin to stop transmitting data delayMicroseconds(3); send_data = send_data >> 1; // detect bit by bit, so move the data right by one //The sign that data transmission ends void IIC_end() digitalWrite(SCL_Pin,LOW);...
  • Page 244 /*************the function to run motor*************/ void Car_front() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,200); void Car_back() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,200); digitalWrite(ML_Ctrl,HIGH); analogWrite(ML_PWM,200); void Car_left() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,HIGH);...
  • Page 245 Car_right() digitalWrite(MR_Ctrl,HIGH); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,255); void Car_Stop() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,0); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,0); void Car_T_left() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,255); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,180);...
  • Page 246: Test Result

    Car_T_right() digitalWrite(MR_Ctrl,LOW); analogWrite(MR_PWM,180); digitalWrite(ML_Ctrl,LOW); analogWrite(ML_PWM,255); (4) Test Result Note:Remove the Bluetooth module before uploading test code, otherwise, you will fail to upload test code. Reconnect Bluetooth module after uploading test code Upload test code successfully, insert Bluetooth module, power on, and connect to Bluetooth.
  • Page 247: Resources

    9. Resources Wiki page: https://wiki.keyestudio.com/Main_Page Official website: https://keyestudio.com/ Assembly Video Link: http://video.keyestudio.com/ks0428/...

Table of Contents