Ks0313 keyestudio Desktop Mini Bluetooth Smart Car V2.0 Kit: Difference between revisions

From Keyestudio Wiki
Jump to navigation Jump to search
Line 838: Line 838:
'''Connection Diagram'''
'''Connection Diagram'''


<br>[[File:Ks0313-7(22.png|800px|frameless|thumb]]<br>
<br>[[File:Ks0313-7(18.png|800px|frameless|thumb]]<br>





Revision as of 11:09, 29 May 2018

keyestudio keyestudio Desktop Mini Bluetooth Smart Car V2.0 Kit


thumb

Overview

keyestudio 4WD Desktop Mini Bluetooth Smart Car V2.0 Kit is based on microcontroller learning application development system. This smart car is controlled by UNO R3 microcontroller. It can achieve the functions of line tracking, obstacle avoidance, IR remote control, Bluetooth remote control and more. All electronic components of the smart car are soldered with anti-reverse interfaces, making it easy and convenient for you to connect the wires.
This kit also contains plenty of interesting programs, which can help you master the electronic sensor modules and running functions of car. The kit aims to disengage you from boring theories, and you can make further study of microcontroller system development when playing it.

Parameters

  • 1) Motor Voltage range: 1-6V; motor shaft length: 10mm; speed: 6.0V 100rpm/min.
  • 2) Motor control is driven by L298P.
  • 3) Three groups of line tracking modules, to detect black-white line, with higher accuracy and can also be used for anti-fall control.
  • 4) Two groups of obstacle detector modules, to detect whether there are obstacles on the left or right side of smart car; Ultrasonic module is used to detect the distance between ultrasonic and obstacles, forming the smart car’s obstacle avoidance system.
  • 5) Bluetooth wireless module can be paired with mobile phone’s Bluetooth to remotely control smart car.
  • 6) Infrared receiver module is matched with an infrared remote control to control smart car.
  • 7) Can access the external 7 ~ 12V voltage.

Component List

No. Component Quantity Picture
1 Keyestudio UNO R3 Main Board 1
thumb
2 Keyestudio quick connectors motor driver shield 1
thumb
3 Keyestudio quick connectors IR receiver module 1
thumb
4 Keyestudio quick connectors line tracking sensor 1
thumb
5 Keyestudio quick connectors 12FN20 motor 4
thumbthumbthumbthumb
6 Keyestudio quick connectors obstacle detector module 2
thumb
7 Keyestudio quick connectors ultrasonic module 1
thumb
8 keyestudio Bluetooth HC-06 1
thumb
9 Keyestudio JMFP-4 17-button 86*40*6.5MM yellow (eco-friendly) (no battery) 1
thumb
10 Double-Connector JST-PH2.0MM-5P 24AWG blue-green-yellow-red-black wire 15CM (reverse direction) 1
thumb
11 Double-Connector JST-PH2.0MM-4P 24AWG green-yellow-red-black wire 8CM (reverse direction) 1
thumb
12 Double-Connector JST-PH2.0MM-3P 24AWG yellow-red-black wire 8CM (reverse direction) 3
thumb

thumb

thumb
13 Double-Connector JST-PH2.0MM-2P 24AWG red-black wire 160mm 4
thumb

thumb

thumb

thumb
14 Battery holder with JST-PH2.0MM-2P socket lead, black-red lead length 150mm 1
thumb
15 Screw M2*10MM round head 10
thumbthumbthumbthumbthumbthumbthumbthumbthumbthumb
16 Nut M2 nickle plating 10
thumbthumbthumbthumbthumbthumbthumbthumbthumbthumb
17 Screw M3*10MM round head cross 9
thumbthumbthumbthumbthumbthumbthumbthumbthumb
18 Screw M3*6MM round head 18
thumbthumbthumbthumb thumb thumb thumb thumb thumb thumb thumb thumb thumb thumb thumb thumb thumb thumb
19 Screw M3*8MM flat head 4
thumb thumbthumb thumb
20 Nut M3 nickle plating 15
thumb thumb

thumbthumbthumb thumbthumbthumb thumbthumbthumb thumb thumbthumb thumb

21 Dual-pass M3*40MM Copper Pillar 4
thumb thumb thumb thumb
22 Single-pass M3*8+6MM 4
thumb thumb thumb thumb
23 M3*12MM Copper Pillar 2
thumb thumb
24 N20 motor-dedicated wheel 4
thumbthumb thumb thumb
25 N20 motor holder white U-type plastic 4
thumbthumb thumb thumb
26 Transparent acrylic panel (3PCS) thickness 3MM 1
thumb
27 Black-yellow Handle 3*40MM cross screwdriver 1
thumb
28 Lithium Ion Battery Charger 18650 double-cell with plug 1
thumb
29 18650 battery pack 3.7V blue 2PCS CS100% 1
thumb
30 USB cable AM/BM transparent blue OD:5.0 L=1m 1
thumb


Assembly Steps

Arduino IDE and Driver Installation

When getting the development board, first of all you have to install the Arduino IDE and the driver, and all relevant files can be found on the official website. The following link includes various systems, various versions of the Arduino IDE and drivers whatever you choose.
https://www.arduino.cc/en/Main/OldSoftwareReleases#1.5.x

Next, we first introduce the installation method of Arduino IDE-1.5.6 version in the Windows system.

The file downloaded is an arduino-1.5.6-r2-windows.zip compression folder, please unzip it to the hard disk. Double-click Arduino-1.5.6 .exe file. Please refer to the following setup figures:
713.png

Click “I Agree”. Then, click “Next”
714.png

Next, click “Install”.
715.png

Finally, click “Close” after completing the installation.
716.png

The figure below shows the Arduino 1.5.6 version:
717.png


Next, we will introduce the driver installation of keyestudio UNO R3 development board. You can also follow it to install the driver for MEGA2560 R3 development board. The installation method is similar and you can use the same drive file.

Let’s move on to the driver installation in the WIN 7 system.

  • When you connect UNO board to your computer at the first time, right click “Computer” —>“Properties”—> “Device manager”, you can see “Unknown devices”. First, right click “Computer” —>select “Properties”—> click “Device manager”, you should see an icon for ‘unknown device’ with a little yellow warning triangle next to it. This is your Arduino.
    Driver 1.png


  • Right-click on the device and select the top menu option (Update Driver Software...).
    Driver 2.png


  • You will then be prompted to either ‘Search Automatically for updated driver software’ or ‘Browse my computer for driver software’. In this page, click “Browse my computer for driver software”.
    Driver 3.png


  • Select the option to browse and navigate to the drivers folder.
    Driver 4.png


  • Click 'Next' and you may get a security warning, if so, allow the software to be installed. Once the software has been installed, you will get a confirmation message.
    Driver 5.png


  • Installation completed, click “Close”.
    Driver 6.png


  • After installation, go to check the “Device manager” again. right click “Computer” —> “Properties”—> “Device manager”, you can see the device shown as below figure.
    Driver 7.png

Example for Using Arduino IDE

When successfully installing the USB driver for UNO R3 board, you can find the corresponding serial port in Windows Device Manager. Next, we will show you the program “Hello World!” displayed on the serial monitor of Arduino IDE. Here we use the Arduino 1.5.6 version.

Sample Code as below:
Copy and paste the following source code to Arduino IDE.

int val;
int ledpin=13; 
void setup()
{
Serial.begin(9600);
pinMode(ledpin,OUTPUT);
}
void loop()
{
val=Serial.read();
if(val=='R')
{
digitalWrite(ledpin,HIGH);
delay(500);
digitalWrite(ledpin,LOW);
delay(500);
Serial.println("Hello World!");
}
}

Then,set the Board and COM port, shown below.
Hello 1.png

Hello 2.png

If setting well the board and port, you can see it display on the bottom right corner, which is the same as the Device Manager display.
Hello 3.png

Then, click the verify to compile the sketch, if no mistake, click upload to upload the program.
Done uploading, open the serial monitor on the upper right corner and set the baud rate as 9600, enter an “R” and then click “Send”, finally you can see the D13 indicator on the UNO R3 board blinks once, and “Hello World!” is displayed on the serial monitor. Shown below.
Monitor2.png

Hello 4.png
Congrats. Your first programming is done well!


Projects Details

1) Keyestudio quick connectors Motor Drive Shield


thumb


Description
Keyestudio quick connectors motor driver shield is specially designed for this smart car. The driver chip used in this shield is L298P and it comes with a power switch. When stacking the driver shield onto UNO R3 board, after the BAT is powered on, press the POWER button lightly, so external power is supplied to both driver shield and UNO R3 board at the same time.
In order to facilitate wiring, this driver shield comes with an anti-reverse interface. You can use only several wire to connect the motor, power and sensor modules. The Bluetooth interface on this shield is fully compatible with HC-06 Bluetooth module. So you just need to connect HC-06 Bluetooth module to the connector directly.
At the same time, the 2.54 pin header on the shield is reserved for both digital and analog ports of UNO R3 board. This allows you to continue to add other sensors for experiment extension.


Specifications

  • 1.Input voltage for Logic part: DC 5V
  • 2.Input voltage for Drive part: DC 7-12V
  • 3.Operating current for Logic part: <36mA
  • 4.Operating current for Drive part: <2A
  • 5.Maximum Dissipation Power: 25W (T=75°C)
  • 6.Input level for signal control: high level 2.3V<Vin<5V, low level -0.3V<Vin<1.5V
  • 7.Working temperature: -25~+130°C


Connection Diagram

thumb


Test Code
You can copy and paste the code below on Arduino software.

#define E1  9  
#define E2  5 
#define M1  2          
#define M2  4 
        
void M_Control_IO_config(void)// initialization function of motor driver shield IO 
{
  pinMode(M1,OUTPUT); // 
  pinMode(M2,OUTPUT); // 
  pinMode(E1,OUTPUT); // 
  pinMode(E2,OUTPUT); //   
}

void advance(void)        // move forward
{
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}  
void back(void)        // move backward
{
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}  

void turnL(void)     // turn left 
{
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E1,150);   
    analogWrite(E2, 150);
}

void turnR(void)            // turn right
{
   digitalWrite(M1,HIGH);   // both left and right wheel move backward
   digitalWrite(M2, HIGH);  
   analogWrite(E1,150);   
   analogWrite(E2, 150);  
}

void stopp(void)              // stop
{
    digitalWrite(M1,LOW);    
    digitalWrite(M2, LOW);  
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both left and right wheel stop
}

void setup() 
{ 
   Serial.begin(9600);
   M_Control_IO_config();        // initialization of motor driver shield IO
   stopp();
} 

void loop() 
{ 
advance();
delay(1000);
back();
delay(1000);
turnL();
delay(1000);
turnR();
delay(1000);
stopp();
delay(1000);
}


Test Result
Stack the driver shield onto UNO R3 board, wire it up as the above diagram and upload well the code, then you will see the four motors control the four wheels of smart car. Press down the POWER button, smart car will go forward for one second, backward for one second, then turn left for one second and turn right for one second, finally stop for one second, alternately and circularly.

2) Keyestudio quick connectors Line Tracking Sensor


thumb


Description
Keyestudio quick connectors line tracking sensor is designed specifically for this smart car. The sensor should be used together with the driver shield. It is equipped with an anti-reverse interface, which can be connected to driver shield with only one simple wire. The working principle of this sensor is to use the infrared light with different color reflectivity, converting the strength of reflected signal into a current signal. The sensor is active high level at detecting black, but is active low level at detecting white. The detection height is 0-3 cm. In the circuit you can rotate the potentiometer on the sensor to adjust the tracking sensitivity for black and white.


Parameters
1.Operating voltage: 3.3-5V(DC)
2.Interface: 5PIN interface
3.Output signal: digital signal
4.Detection height: 0-3cm


Connection Diagram
thumb


Test Code
You can copy and paste the code below on Arduino software.

const int sensorPin1 = 6;     // the number of the sensor pin1
const int sensorPin2 = 7;     // the number of the sensor pin2
const int sensorPin3 = 8;     // the number of the sensor pin3
const int ledPin1 = 3;      // the number of the LED pin1
const int ledPin2 = 10;      // the number of the LED pin2
const int ledPin3 = 11;      // the number of the LED pin3
void setup() {
  pinMode(ledPin1, OUTPUT); 
  pinMode(ledPin2, OUTPUT);  
  pinMode(ledPin3, OUTPUT);  
  pinMode(sensorPin1, INPUT); 
  pinMode(sensorPin2, INPUT);
  pinMode(sensorPin3, INPUT); 
  }
void loop(){    
     digitalWrite(ledPin1,1-digitalRead(sensorPin1));  
     digitalWrite(ledPin2,1-digitalRead(sensorPin2));  
     digitalWrite(ledPin3,1-digitalRead(sensorPin3));  
}


Test Result
Stack driver shield onto UNO R3 board, wire it up as the above diagram and upload well the code, then press the button on the shield lightly, and you can rotate three potentiometers on the sensor to adjust its sensitivity. It is better to set three LEDs in the critical point between on and off state.
If pick up a black paper to cover the sensing area of sensor, both LED on the sensor and external LED module are not bright. While pick up a white paper to cover the sensing area of sensor, both LED on the sensor and external LED module are turned on.

3) Keyestudio quick connectors IR Receiver Sensor


thumb


Description
Keyestudio quick connectors IR receiver sensor is designed specifically for this smart car. The sensor should be used together with the driver shield. It is equipped with an anti-reverse interface, which can be connected to driver shield with only one simple wire.
Infrared receiver sensor is mainly composed of an infrared receiving head, and it is a device that integrates reception, amplification and demodulation. Its internal IC has been demodulated and the output is a digital signal.


Parameters
1.Operating voltage: 3.3-5V(DC)
2.Interface: 3PIN interface
3.Output signal: digital signal
4.Receiving angle: 90 degrees
5.Frequency: 38khz
6.Receiving distance: 18 meters


Connection Diagram
thumb


Test Code
You can copy and paste the code below on Arduino software.

#include <IRremote.h>
int RECV_PIN = 15; //define the digital port15
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);//set the baud rate
irrecv.enableIRIn(); // enable infrared receiving
}
void loop() {
if (irrecv.decode(&results)) 
{
Serial.println(results.value, HEX);//display the data
irrecv.resume(); // receive the next data
}
}


Note:do remember to add IRremote folder into installation directory \Arduino\compiler libraries, or else it will fail to compile the code.


Test Result
Stack driver shield onto UNO R3 board, wire it up as the above diagram and upload well the code, then open the serial monitor and set the baud rate as 9600.
When IR receiver sensor receives the signal sent from infrared remote control, you can see the decoding of button on the monitor. If press the button too long, it will display the unreadable code like FFFFFFFF. Shown below.
thumb

thumb

4) keyestudio quick connectors Obstacle Detector Sensor


thumb


Description
Keyestudio quick connectors obstacle detector sensor is designed specifically for this smart car. The sensor should be used together with the driver shield. It is equipped with an anti-reverse interface, which can be connected to driver shield with only one simple wire. Done wire connection and powered up, if detecting the objects, the signal terminal of this sensor will output 0. If no, the signal terminal will output 1. Besides, you can rotate the potentiometer on the sensor to adjust the detective sensitivity.


Parameters
1.Operating voltage: 3.3-5V(DC)
2.Interface: 3PIN interface
3.Output signal: digital signal
4.Sensing range: 2-40cm


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

const int sensorPin1 = 14;     // the number of the sensor pin1
const int sensorPin2 = 16;     // the number of the sensor pin2
const int ledPin1 = 3;      // the number of the LED pin1
const int ledPin2 = 10;      // the number of the LED pin2
void setup() {
  pinMode(ledPin1, OUTPUT); 
  pinMode(ledPin2, OUTPUT);   
  pinMode(sensorPin1, INPUT); 
  pinMode(sensorPin2, INPUT);
  }
void loop(){    
     digitalWrite(ledPin1,1-digitalRead(sensorPin1));  
     digitalWrite(ledPin2,1-digitalRead(sensorPin2)); 
}


Test Result
Stack driver shield onto UNO R3 board, wire it up as the above diagram and upload well the code to the board, then press down the POWER button on the shield. Besides, you can rotate two potentiometers on the sensor to adjust the sensitivity. It is better to set the LED on the right sensor in the critical point between on and off state.
When detecting the obstacle in front of sensor, both LED on the right sensor and external LED module are bright. If no, LED on the sensor and external LED module are off.

5) keyestudio quick connectors Ultrasonic Module


thumb


Description
Keyestudio quick connectors ultrasonic module is designed specifically for this smart car. This module should be used together with the driver shield. It is equipped with an anti-reverse interface, which can be connected to driver shield with only one simple wire. It is mainly used for distance detection, with the features of high precision, super closeness in the blind area (3-4cm) and stable performance.


Parameters
1.Operating voltage: 5V (DC)
2.Operating current: 15mA
3.Working frequency: 40khz
4.Maximum detection distance: 3-5m
5.Minimum detection distance: 3-4cm
6.Sensing angle: no more than 15 degrees


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

#define ECHO 13
#define TRIG 12
unsigned char SM;        // middle sensor status 
unsigned long rxTime;
void setup() {
  // put your setup code here, to run once:
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  rxTime = pulseIn(ECHO, HIGH);
  SM = (float)rxTime * 34 / 2000.0;
  Serial.print(SM);
Serial.println("cm");
  delay(300);
}


Test Result
Stack driver shield onto UNO R3 board, wire it up as the above diagram and upload well the code to the board, then open the serial monitor and set the baud rate as 9600.
If you place an obstacle in front of the ultrasonic sensor, you will see the distance between obstacle and sensor is displayed on the monitor with an interval of 0.3 second. Shown below.

thumb

6) keyestudio Bluetooth HC-06 Module


thumb


Description
Keyestudio Bluetooth HC-06 is fully compatible with driver shield. So you just need to connect the Bluetooth module to driver shield using several wires. This Bluetooth module can easily achieve serial wireless data transmission. Its operating frequency is among the most popular 2.4GHz ISM frequency band (i.e. Industrial, scientific and medical).
It adopts Bluetooth 2.1+EDR standard. In Bluetooth 2.1, signal transmit time of different devices stands at an interval of 0.5 second, thus the workload of Bluetooth chip can be reduced substantially and more sleeping time can be saved for Bluetooth. This module is set with serial interface, which is easy-to-use and simplifying overall design/development cycle.


Specification Parameters

  • 1.Bluetooth Protocol: Bluetooth 2.1+ EDR Standard
  • 2.USB Protocol: USB v1.1/2.0
  • 3.Operating Frequency: 2.4GHz ISM Frequency Band
  • 4.Modulation Mode: Gauss Frequency Shift Keying
  • 5.Transmit Power: ≤ 4dBm, Second Stage
  • 6.Sensitivity: ≤-84dBm at 0.1% Bit Error Rate
  • 7.Transmission Speed: 2.1Mbps(Max)/160 kbps (Asynchronous);
  • 1Mbps/1Mbps (Synchronous)
  • 8.Safety Feature: Authentication and Encryption
  • 9.Supported Configuration: Bluetooth Serial Port (major and minor)
  • 10.Supply Voltage: DC 5V
  • 11.Operating Temperature: -20 to 55℃


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

int val;  
void setup() 
{ 
Serial.begin(9600);
}
 void loop()
{ val=Serial.read(); 
if(val=='a')
 { 
 Serial.println("keyestudio");
}
}


Test Result
Wire it up as the above diagram, and stack driver shield onto UNO R3 board, then upload well the code to the board, you will see the power indicator D1 light up, and LED on the Bluetooth module flash.
Open your phone Bluetooth, ready to pair the device, enter 1234, you will see the paired device. Shown as figure below.
Then open an APP- BTClient to connect the Bluetooth, if connected, LED on the Bluetooth module is normally on. Enter the letter “a”, the BTClient software will print out “keyestudio”. Shown as the figure below.
thumb thumb

7) Line Tracking Function for Smart Car


Overview
This project is a simple and automatic tracking car system based on Keyestudio Arduino UNO R3 main control board. The smart car with UNO R3 as the controlling core, makes use of the tracking sensor to detect the black track on the pavement, and detection signal will feed back to the main control board. The main control board then will analyze and judge the collected signals to control the driving motor in time, thus adjust the turning direction of smart car. That is why the smart car can automatically follow the black track, achieving the automatic line tracking function for smart car.


Principle

  • 1. Using the characteristic that black has low reflectivity to light. When flat surface is not black, the infrared light transmitted by the sensor will be reflected back mostly, so the sensor outputs low level 0.
  • 2. When the flat surface has a black line and the sensor is above the black line, the reflected infrared light is very less due to the weak reflectivity of black, so it does not reach the level of sensor action and sensor outputs high level 1.
  • 3. Use the main control board to determine whether the output of the sensor is 0 or 1, finally detect the black line.
  • 4. The main control board will control the motor-driver shield according to the received signal, so as to control the turning direction of four motors. Finally control the movement of smart car.


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

#define SensorLeft    6   // left sensor input pin
#define SensorMiddle    7   // left sensor input pin
#define SensorRight   8  // right sensor input pin
unsigned int SL;        // left sensor status
unsigned int SM;        // middle sensor status
unsigned int SR;        // right sensor status
#define E1  9    // speed control pin, ENA pin on motor driver shield
#define E2  5   // speed control pin, ENA pin on motor driver shield
#define M1  2            // motor direction control, IN1 pin on motor driver shield
#define M2  4          // motor direction control, IN2 pin on motor driver shield
void Sensor_IO_Config()
{
  pinMode(SensorLeft,INPUT);
  pinMode(SensorMiddle,INPUT);
  pinMode(SensorRight,INPUT); 
}
void Sensor_Scan(void)
{
  SL = digitalRead(SensorLeft);
  SM = digitalRead(SensorMiddle);
  SR = digitalRead(SensorRight);
}
void M_Control_IO_config(void)// initialization function of motor driver shield IO
{
  pinMode(M1,OUTPUT); 
  pinMode(M2,OUTPUT);
  pinMode(E1,OUTPUT);
  pinMode(E2,OUTPUT);  
}

void advance(void)     // move forward
{
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void back(void)            // move backwards
{
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void turnR(void)        // turn right
{
   digitalWrite(M1,HIGH);   // both left and right wheel move backward
   digitalWrite(M2, HIGH);  
   analogWrite(E1,150);   
   analogWrite(E2, 150);  
}
void turnL(void)        // turn left
{
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E1,150);   
    analogWrite(E2, 150);
}    
void stopp(void)              // stop
{
    digitalWrite(M1,LOW);    
    digitalWrite(M2, LOW);   
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both right &left wheel stop  
}

void setup() 
{ 
   Sensor_IO_Config();
   M_Control_IO_config(); //  initialization of motor controller module IO 
   stopp();
} 
void loop() 
{ 
Sensor_Scan(); 
if((SL==1&&SM==1&&SR==1)||(SL==1&&SM==1&&SR==0)||(SL==0&&SM==1&&SR==1)||(SL==0&&SM==1&&SR==0))
  {
  advance();
  }
if(/*(SL==0&&SM==0&&SR==0)||*/(SL==0&&SM==0&&SR==1))
  {
  //back();
  //delay(10);
  turnR();
  }
if(SL==1&&SM==0&&SR==0)
  {
  //back();
  //delay(10);
  turnL();
  }
} 


Test Result
Wire it up as the above diagram, stack the motor shield onto main control board, then upload the test code to the board, press down the POWER button on the motor shield. If draw a black line on the ground, you can see that the smart car will track the black line.


thumb


8) Edge Avoidance Function for Smart Car


Overview
The principle of this project is similar to the previous project 7. The smart car with UNO R3 as the controlling core, makes use of the tracking sensor to detect the black track on the pavement, and detection signal will feed back to the main control board.
The main control board then will analyze and judge the collected signals to control the driving motor in time, thus adjust the turning direction of smart car. Finally control the smart car run within the area circled by the black line, achieving the automatic edge avoidance function for smart car.


Principle

  • 1. Using the characteristic that black has low reflectivity to light. When flat surface is not black, the infrared light transmitted by the sensor will be reflected back mostly, so the sensor outputs low level 0.
  • 2. When the flat surface has a black line and the sensor is above the black line, the reflected infrared light is very less due to the weak reflectivity of black, so it does not reach the level of sensor action and sensor outputs high level 1.
  • 3. Use the main control board to determine whether the output of the sensor is 0 or 1, finally detect the black line.
  • 4. The main control board will control the motor-driver shield according to the received signal, so as to control the turning direction of four motors. Finally control the movement of smart car.


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

#define SensorLeft    6   // left sensor input pin
#define SensorMiddle    7   // left sensor input pin
#define SensorRight   8  // right sensor input pin
unsigned int SL;        // left sensor status
unsigned int SM;        // middle sensor status
unsigned int SR;        // right sensor status
#define E1  9    // speed control pin, ENA pin on motor driver shield
#define E2  5   // speed control pin, ENA pin on motor driver shield
#define M1  2            // motor direction control, IN1 pin on motor driver shield
#define M2  4          // motor direction control, IN2 pin on motor driver shield
void Sensor_IO_Config()
{
  pinMode(SensorLeft,INPUT);
  pinMode(SensorMiddle,INPUT);
  pinMode(SensorRight,INPUT); 
}
void Sensor_Scan(void)
{
  SL = digitalRead(SensorLeft);
  SM = digitalRead(SensorMiddle);
  SR = digitalRead(SensorRight);
}
void M_Control_IO_config(void)// initialization function of motor driver shield IO
{
  pinMode(M1,OUTPUT); 
  pinMode(M2,OUTPUT);
  pinMode(E1,OUTPUT);
  pinMode(E2,OUTPUT);  
}

void advance(void)     // move forward
{
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void back(void)            // move backwards
{
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void turnR(void)        // turn right
{
   digitalWrite(M1,HIGH);   // both left and right wheel move backward
   digitalWrite(M2, HIGH);  
   analogWrite(E1,150);   
   analogWrite(E2, 150);  
}
void turnL(void)        // turn left
{
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E1,150);   
    analogWrite(E2, 150);
}    
void stopp(void)              // stop
{
    digitalWrite(M1,LOW);    
    digitalWrite(M2, LOW);   
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both right &left wheel stop  
}

void setup() 
{ 
   Sensor_IO_Config();
   M_Control_IO_config(); //  initialization of motor controller module IO 
   stopp();
} 
void loop() 
{ 
Sensor_Scan(); 
if(SL==0&&SM==0&&SR==0)
  {
  advance();
  }
if((SL==1&&SM==0&&SR==0)||(SL==1&&SM==1&&SR==0)||(SL==0&&SM==1&&SR==0)||(SL==1&&SM==0&&SR==1))
  {
  back();
  delay(500);
  turnR();
  delay(500);
  }
if((SL==0&&SM==0&&SR==1)||(SL==0&&SM==1&&SR==1))
  {
  back();
  delay(500);
  turnL();
  delay(500);
  }
  if(SL==1&&SM==1&&SR==1)
  {
  back();
  }
} 


Test Result
Wire it up as the above diagram, stack the motor shield onto main control board, then upload the test code to the board, press down the POWER button on the motor shield.
If you draw a circle with black line, then place the car inside the circle, finally the smart car will turn back or redirect to avoid the line edge, only run inside the circle.


thumb

9) Obstacle Avoidance Function for Smart Car


Overview
This project is a simple and automatic obstacle avoidance system based on Keyestudio Arduino UNO R3 main control board. The smart car with UNO R3 as the controlling core, uses both ultrasonic module and obstacle detector sensor to detect the obstacle in front of the car, and the detection signal will feed back to the main control board.
The main control board then will analyze and judge the collected signals to control the driving motor in time, thus adjust the direction of smart car. Finally control the smart car automatically avoid the obstacles ahead to run smoothly, achieving the obstacle avoidance function for smart car.


Principle

  • 1. Use the ultrasonic module to detect the distance between the smart car and obstacle.
  • 2. Use the obstacle detector sensor to detect the obstacle ahead or left and right side. The sensitivity can be adjusted through rotating the two small potentiometers on the sensor. If detecting the obstacle, the signal end of sensor will output 0; if no, the signal end of sensor will output 1.
  • 3. The main control board will control the motor drive shield according to both the output signal from obstacle detector sensor and distance value from ultrasonic module, thus control the turning direction of four motors. If so, it can control the movement of smart car.


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

#define ECHO 13
#define TRIG 12
#define IRSensorLeft    A0   // left sensor input pin
#define IRSensorRight   A2  // right sensor input pin
unsigned char IRSL;        // left sensor status
unsigned char SM;        // middle sensor status 
unsigned char IRSR;        // right sensor status
unsigned long rxTime;
#define E1  9    
#define E2  5   
#define M1  2            
#define M2  4         
void Sensor_IO_Config()
{
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  pinMode(IRSensorLeft,INPUT);
  pinMode(IRSensorRight,INPUT);
}
void Sensor_Scan(void)
{
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  rxTime = pulseIn(ECHO, HIGH);
  SM = (float)rxTime * 34 / 2000.0;
  Serial.println(SM);
  IRSL = digitalRead(IRSensorLeft);
  IRSR = digitalRead(IRSensorRight);
}
void M_Control_IO_config(void)// initialization function of motor driver shield IO
{
  pinMode(M1,OUTPUT); 
  pinMode(M2,OUTPUT); 
  pinMode(E1,OUTPUT); 
  pinMode(E2,OUTPUT);   
}
void advance(void)        // turn left 
{
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}  
void back(void)        // turn right 
{
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void turnR(void)            // move backward
{
   digitalWrite(M1,HIGH);   // both left and right wheels move forward
   digitalWrite(M2, HIGH);  
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void turnL(void)     // move forward
{
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E1,150);   
    analogWrite(E2, 150);
}
void stopp(void)              // stop 
{
    digitalWrite(M1,LOW);    
    digitalWrite(M2, LOW);  
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both left and right wheels stop
}
void setup() 
{ 
   Serial.begin(115200);
   Sensor_IO_Config();
   M_Control_IO_config();        // initialization of motor driver shield IO
   stopp();
} 
unsigned char old_IRSL,old_IRSM,old_IRSR;
void loop() 
{
Sensor_Scan();
if(IRSL==1&&SM>8&&IRSR==1)
  advance(); 
if((IRSL==0&&SM<8&&IRSR==1)||(IRSL==0&&SM>8&&IRSR==1)||(IRSL==1&&SM<8&&IRSR==1))
  {
  turnR();
  }
if((IRSL==1&&SM<8&&IRSR==0)||(IRSL==1&&SM>8&&IRSR==0))
  {
  turnL();
  }
  if((IRSL==0&&SM<8&&IRSR==0)||(IRSL==0&&SM>8&&IRSR==0))
  {
  back();
  delay(200);
  turnL();
  delay(200);
  }
} 


Test Result
Wire it up as the above diagram, stack the motor shield onto main control board, then upload the test code to the board, press down the POWER button on the motor shield.
When detects the obstacle ahead, the smart car can automatically avoid it to run freely.
thumb

10) Object Following Function for Smart Car


Overview
The principle of this project is similar to the previous project 9. The smart car with UNO R3 as the controlling core, makes use of both ultrasonic module and obstacle detector sensor to detect the object in front of the car, and the detection signal will feed back to the main control board.
The main control board then will analyze and judge the collected signals to control the driving motor in time, thus adjust the turning direction of smart car. Finally control the smart car automatically follow the object ahead, achieving the object following function for smart car.


Principle
1. Use the ultrasonic module to detect the distance between the smart car and object ahead.
2. Use the obstacle detector sensor to detect the obstacle ahead or left and right side. The sensitivity can be adjusted through rotating the two small potentiometers on the sensor. If detecting the object, the signal end of sensor will output 0; if no, the signal end of sensor will output 1.
3. The main control board will control the motor drive shield according to both output signal from obstacle detector sensor and distance value from ultrasonic module, thus control the turning direction of four motors. If so, it can control the movement of smart car.


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

#define ECHO 13
#define TRIG 12
#define IRSensorLeft    A0   // left sensor input pin
#define IRSensorRight   A2  // right sensor input pin
unsigned char IRSL;        // left sensor status
unsigned char SM;        // middle sensor status 
unsigned char IRSR;        // right sensor status
unsigned long rxTime;
#define E1  9    
#define E2  5   
#define M1  2            
#define M2  4         
void Sensor_IO_Config()
{
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  pinMode(IRSensorLeft,INPUT);
  pinMode(IRSensorRight,INPUT);
}
void Sensor_Scan(void)
{
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  rxTime = pulseIn(ECHO, HIGH);
  SM = (float)rxTime * 34 / 2000.0;
  Serial.println(SM);
  IRSL = digitalRead(IRSensorLeft);
  IRSR = digitalRead(IRSensorRight);
}
void M_Control_IO_config(void)// initialization function of motor driver shield IO
{
  pinMode(M1,OUTPUT); 
  pinMode(M2,OUTPUT); 
  pinMode(E1,OUTPUT); 
  pinMode(E2,OUTPUT);   
}
void advance(void)        // turn left 
{
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}  
void back(void)        // turn right 
{
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void turnR(void)            // move backward
{
   digitalWrite(M1,HIGH);   // both left and right wheels move forward
   digitalWrite(M2, HIGH);  
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void turnL(void)     // move forward
{
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E1,150);   
    analogWrite(E2, 150);
}
void stopp(void)              // stop 
{
    digitalWrite(M1,LOW);    
    digitalWrite(M2, LOW);  
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both left and right wheels stop
}

void setup() 
{ 
   Serial.begin(115200);
   Sensor_IO_Config();
   M_Control_IO_config();        // initialization of motor driver shield IO
   stopp();
} 
void loop() 
{
Sensor_Scan();
if((SM>10)&&(SM<25))
{
 advance(); 
 }
if((SM>=25)||(SM<=10))
  {
  stopp();
  }
if(IRSR==0)
{
 turnR();
 }
 if(IRSL==0)
{
 turnL();
 }
} 


Test Result
Wire it up as the above diagram, stack the motor shield onto main control board, then upload the test code to the board, press down the POWER button on the motor shield.
If detects an object ahead, the smart car will follow the object to run normally.
thumb


11) Infrared Remote Control for Smart Car


Overview
This project is a simple infrared remote control system based on Keyestudio Arduino UNO R3 main control board.The smart car with UNO R3 as the controlling core, makes use of infrared receiver module to receive the infrared signal, and infrared signal will feed back to the main control board.
The main control board then will analyze and judge the collected signals to control the driving motor in time, thus adjust the turning direction of smart car. Finally achieve the function that the smart car can be randomly controlled by infrared remote control.


Principle

  • 1. Connect the IR receiver module to the motor drive shield, enable the IR receiver module communicate with the infrared remote control.
  • 2. Infrared remote control will send the information of those buttons like“”“”“”“”“” to the IR receiver module.
  • 3. When the control board receives the info from IR receiver module, it will control the motor drive shield so as to control the smart car run.
  • 4. When the main board receives the info of button“”, smart car will go forward; when receives the info of button“”, smart car will go backward. If receives the info of button“”, smart car will turn left; if receives the info of button“”, smart car will turn right. If receives the info of button“”, smart car will stop.


Connection Diagram


thumb


Test Code
You can copy and paste the code below on Arduino software.

#include <IRremote.h> 
int RECV_PIN = 15;
#define E1  9  
#define E2  5 
#define M1  2          
#define M2  4  
//******IR control part********
long advance1 = 0x00FF629D;
long back1 = 0x00FFA857;
long stop = 0x00FF02FD;
long left = 0x00FF22DD;
long right = 0x00FFC23D;
IRrecv irrecv(RECV_PIN);
decode_results results;
void M_Control_IO_config(void)// initialization function of motor driver shield IO 
{
  pinMode(RECV_PIN, INPUT);
  pinMode(M1,OUTPUT); // 
  pinMode(M2,OUTPUT); // 
  pinMode(E1,OUTPUT); // 
  pinMode(E2,OUTPUT); //   
}
void advance(void)        // turn left 
{
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
} 
void back(void)        // turn right
{
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}  
void turnL(void)     // move forward
{
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E1,150);   
    analogWrite(E2, 150);
} 
void turnR(void)            // move backward
{
   digitalWrite(M1,HIGH);   // both left and right wheel move backward
   digitalWrite(M2, HIGH);  
   analogWrite(E1,150);   
   analogWrite(E2, 150);  
}
void stopp(void)              // stop
{
    digitalWrite(M1,LOW);    
    digitalWrite(M2, LOW);  
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both left and right wheel stop
}
void setup()
{
M_Control_IO_config(); 
irrecv.enableIRIn(); // Start the receiver
}
int on = 0;
unsigned long last = millis();
void loop()
{
// If it's been at least 1/4 second since the last
// IR received, toggle the relay if (millis() - last > 250)
{
on = !on;
digitalWrite(11, on ? HIGH : LOW);
}
if (irrecv.decode(&results))
{
if (results.value == advance1 )
advance();
if (results.value == back1 )
back();
if (results.value == left )
turnL();
if (results.value == right )
turnR();
if (results.value == stop )
stopp();
last = millis();
irrecv.resume(); // Receive the next value
}
} 


Note:do remember to add IRremote folder into installation directory \Arduino\compiler libraries, or else it will fail to compile the code.
For example: C:\Program Files\Arduino\libraries


Test Result
Wire it up as the above diagram, stack the motor shield onto main control board, then upload the test code to the board, press down the POWER button on the motor shield.
Aligned at IR receiver module, press down the button on the infrared remote control, it will control the smart car running randomly.
thumb


12) Bluetooth Control for Smart Car


Overview
This project is a simple infrared remote control system based on Keyestudio Arduino UNO R3 main control board.The smart car with UNO R3 as the controlling core, makes use of Bluetooth module to receive the mobile phone’s Bluetooth signal, and Bluetooth signal will feed back to the main control board.
The main control board then will analyze and judge the collected signals to control the driving motor in time, thus adjust the turning direction of smart car. Finally achieve the function that the smart car can be randomly controlled by mobile phone’s Bluetooth device.


Principle

  • 1.Connect the Bluetooth module to the motor drive shield, enable the Bluetooth module communicate with APP on the mobile phone.
  • 2.Send the characters info like“U”“D”“L”“R”“S”to the Bluetooth module using phone’s APP.
  • 3.When the main board receives the info from Bluetooth module, it will correspondingly control the motor drive shield so as to control the turning direction of four motors. This way can randomly control the moving state of smart car.
  • 4.If main board receives the info“U”, smart car will go forward; if receives“D”, smart car will go backward. If receives the info“L”, smart car will turn left; if receives the info“R”, smart car will turn right. The smart car will stop when the main board receives the info“S”.


Connection Diagram
thumb


Test Code
You can copy and paste the code below on Arduino software.

#define E1  9  
#define E2  5 
#define M1  2          
#define M2  4         
int val;
void M_Control_IO_config(void)// initialization function of motor driver shield IO 
{
  pinMode(M1,OUTPUT); // 
  pinMode(M2,OUTPUT); // 
  pinMode(E1,OUTPUT); // 
  pinMode(E2,OUTPUT); //   
}
void advance(void)        // turn left 
{
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}   
void back(void)        // turn right
{
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
   analogWrite(E1,150);   
   analogWrite(E2, 150);
}
void turnL(void)     // move forward
{
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E1,150);   
    analogWrite(E2, 150);
}
 void turnR(void)            // move backward
{
   digitalWrite(M1,HIGH);   // both left and right wheel move backward
   digitalWrite(M2, HIGH);  
   analogWrite(E1,150);   
   analogWrite(E2, 150);  
}
void stopp(void)              // stop
{
    digitalWrite(M1,LOW);    
    digitalWrite(M2, LOW);  
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both left and right wheel stop
}
void setup() 
{ 
   Serial.begin(9600);
   M_Control_IO_config();        // initialization of motor driver shield IO
   stopp();
} 
void loop() 
{ 
val=Serial.read(); 
if(val=='U')advance();
if(val=='D')back();
if(val=='L')turnL();
if(val=='R')turnR();
if(val=='S')stopp();
}


Test Result
Wire it up as the above diagram, stack the motor shield onto main control board, then upload the test code to the board, and press down the POWER button on the motor shield. Powered up, power indicator D1 will light up and led light on the Bluetooth module will flash.
Then open the Bluetooth on your phone, pair the device, enter 1234, you can see the paired device. Open your APP to connect the Bluetooth, if connected, the led on the Bluetooth module is normally on. Finally, aligned at the Bluetooth module of car, press the controlled button on your APP, it can freely control the smart car running.
thumb