Ks0313 keyestudio Desktop Mini Bluetooth Smart Car V2.0 Kit: Difference between revisions
Keyestudio (talk | contribs) |
Keyestudio (talk | contribs) |
||
Line 241: | Line 241: | ||
|- | |- | ||
| align="center" | '''①''' | | align="center" | '''①''' | ||
| align=" | | align="light" | '''USB Connection''' | ||
*Arduino board can be powered via USB connector. | *Arduino board can be powered via USB connector. | ||
*All you needed to do is connecting the USB port to PC using a USB cable. | *All you needed to do is connecting the USB port to PC using a USB cable. |
Revision as of 13:14, 5 July 2018
keyestudio keyestudio Desktop Mini Bluetooth Smart Car V2.0 Kit
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
Assembly Steps
Project Details for Smart Car
Project 1: Getting Started with ARDUINO
1)CorePart of Robot
When it comes to the core part, you may think of the sparkling energy block on the front of Iron Man's chest, or something in R2D2 Robot's head that can make him talk nonsense. The core is the part that really matters today. In fact, it is very easy to understand the core. In other word, the core is just like the human brain. It can receive various kinds of information every day and will send out various instructions every day. So actually the core of our robot is a development board compatible with ARDUINO.
Well, let's first look at this development board as the figure shown below:
File:KS0001.png
So why choose to use the UNO R3 development board as the core of robot? Well, because it is the most popular one in Arduino board series. In addition, it is also the best choice for beginners to learn to build electronic circuits and write the source code. Let's take a look at the details of this development board with the following chart:
① | USB Connection
|
② | DC Power Jack
Arduino board can be supplied with power from the DC power jack |
Installing Arduino IDE
When you get theUNO development board, first you should install the software and driver of Arduino. Here you can browse the ARDUINO website at this link, https://www.arduino.cc, pop up the following interface.
Then click the SOFTWARE on the browse bar, you will have two options ONLINE TOOLS and DOWNLOADS.
Click DOWNLOADS, it will appear the latest software version of ARDUINO 1.8.5 shown as below.
In this software page, on the right side you can see the version of development software for different operating systems. So ARDUINO has a rather powerful compatibility. You should download the software that is compatible with the operating system of your computer.
In our project, we will take WINDOWS system as an example here. There are also two options under Windows system, one is installed version, the other is non-installed version.
For simple installed version, first click Windows Installer, you will get the following page.
This way you just need to click JUST DOWNLOAD, then click the downloaded file to install it.
For non-installed version, first click Windows ZIP file, you will also get the pop-up interface as the above figure.
Click JUST DOWNLOAD, and when the ZIP file is downloaded well to your computer, you can directly unzip the file and then click the icon of ARDUINO program to start it.
Installing Arduino (Windows)
Install Arduino with the exe. Installation package
Click“I Agree”to see the following interface.
Click “Next”. Pop up the interface below.
You can press Browse… to choose an installation path or directly type in the directory you want.
Then click “Install” to initiate installation.
Wait for the installing process, if appear the interface of Window Security, just continue to click Install to finish the installation.
All right, up to now, you have completed the Arduino setup! The following icon will appear on your PC desktop.
Double-click the icon of Arduino to enter the desired development environment shown as below.
Installing Installing Driver
Next, we will introduce the driverinstallation of UNO R3 development board. Thedriver installation may have slight differences in different computer systems. So in the following let’s move on to the driver installation in the WIN 7 system.
The Arduino folder contains both the Arduino program itself and the drivers thatallow the Arduino to be connected to your computer by a USB cable. Before welaunch the Arduino software, you are going to install the USB drivers.
Plug one end of your USB cable into the Arduino and the other into a USB socket onyour computer.
When you connect UNO board to your computer at the first time, right click the icon of your “Computer” —>for “Properties”—> click the “Device manager”, under “Other Devices”, you should see an icon for“Unknown device” with a littleyellow warning triangle next to it. This is your Arduino.
Then right-click on the device and select the top menu option (Update Driver Software...) shown as the figure below..
It will then be prompted to either “Search Automatically for updated driversoftware” or “Browse my computer for driver software”. Shown as below. In this page, select “Browse my computer for driver software”.
After that, select the option to browseand navigate to the “drivers” folder of Arduino installation.
Click “Next” and you may get a security warning, if so, allow the software to be installed. Shown as below.
Once the software has been installed, you will get a confirmation message. Installation completed, click “Close”.
Up to now, the driver is installed well. Then you can right click “Computer” —>“Properties”—>“Device manager”, you should see the device as the figure shownbelow.
Example for Using Arduino IDE
STEP 1: Open Arduino
In the previous, we have introduced the driver installation of UNO R3 development board. So this time let’s first have basic understanding of the development environment of ARDUINO. After master that, we are about to upload the program to Arduino board.
First of all, open the unzipped folder of ARDUINO development software and click icon of ARDUINO to open the software, as the figure shown below.
STEP 2: Build Projects
When open the Arduino software, you will have two options as below:
- Build a new project
- Open an exiting project example
If you want to build a new project, please select “File”→then click “New”, you will see the software interface as follows.
→
If you want to open an example project, please select File→Example→Basics→Blink. Shown below.
→
STEP 3: Select Arduino Board
In order to avoid any mistakes during the process of uploading the code to the board, you must first select the correct Arduino board that matches the board connected to your computer.
Or you can directly open the Control Panel of your computer, then click to open Device Manager, you can check your board and port here. Shown as below.
Then come back to the Arduino software, you should click Tools→Board , select the correct board. Here in our tutorial we should select Arduino Uno. Shown as below.
STEP 4: Select Serial Port
Next, we should select the serial device of Arduino board. You can click Tools→Serial Port. It may be COM3 or higher (COM1 and COM2 are usually reserved as hardware serial port). If you want to find out your Arduino board, you could disconnect your Arduino board, then reopen the menu, you will see the Arduino board disappear. After that reconnect the board and select the serial port.
You should select the correct Serial port that matches the port showed on the Device Manager of your computer.
The figure shown below is only for your reference.
Attach your Arduino board to your computer with the USB cable and check that the “Board Type” and “Serial Port” are set correctly.
STEP 5: Upload the Code to Your Board
Before showing you how to upload the code to your board, first of all let me introduce the function of each icon on the Tool bar of Arduino IDE. Look at the picture showed below.
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.
E- Used to save the sketch.
F- Used to send the serial data received from board to the serial monitor.
Projects Details
1) Keyestudio quick connectors Motor Drive Shield
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
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
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
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
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
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.
4) keyestudio quick connectors Obstacle Detector Sensor
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
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
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
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.
6) keyestudio Bluetooth HC-06 Module
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
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.
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
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.
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
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.
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
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.
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
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.
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
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.
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”.
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.