Voice Controlled Robot (Bluetooth and Smar...


In this tutorial, we will make voice controlled robot with an Android application. We will control the robot via Smartphone.

Please don't forget to subscribe. Thank you for your support.

---

Suggested videos about this project:

- How to install the library:  https://youtu.be/Es8D1q_b-c4
- Voice controlled LED:  https://youtu.be/Hn9CG_vEQAE
- Error: No Such File or Directory:  https://youtu.be/Es8D1q_b-c4
- Project on using motor shield: https://youtu.be/C3GhJmmRY4Y

---

Hardware Required:

-Arduino Board - https://goo.gl/UyGYeF
-L293D Motor Shield - https://goo.gl/9Ph44b
-Bluetooth Module (HC06) - https://goo.gl/thjwVL
-DC Motor and Wheel x2 - https://goo.gl/rpxoMu
-Bovine wheel - https://goo.gl/sNu1u7
-Wires - https://goo.gl/TdGrkk - https://goo.gl/VRzUN4
-Breadboard - https://goo.gl/jZeZC2
-Chassis - https://goo.gl/v1moF2
-Battery and Battery buckle - https://goo.gl/iAEgPl

Recommended site to buy the required hardware:
https://www.banggood.com/?p=CS120478587752016125

---

Creating chassis:

-DC Motors attach to the chassis
-The Arduino board attach to the chassis
-Mini breadboard attach to the chassis
-Bovine wheel attach to the chassis
-Wheels attach to DC Motors
-Bluetooth module attach to mini breadboard

---

Connections:

-Bluetooth RX connect to the Arduino TX input
-Bluetooth TX connect to the Arduino RX input
-The Motor Shield attach to the Arduino board
-The Arduino GND connect to the Bluetooth module GND
-The Arduino +5V connect to the Bluetooth module VCC
-Left DC Motor connect to the Motor Shield M1 inputs
-Right DC Motor connect to the Motor Shield M2 inputs
-Battery buckle connect to the Motor Shield +V and GND

---

About the Code and App:

-The Arduino board connect to the PC
-Open the Arduino New Sketch
-Copy and Paste the Code
-First you should add the library
-Get the AFMotor.h library:
https://github.com/adafruit/Adafruit-Motor-Shield-library
-Servo.h library is standard library
-Don't Forget ! You should select your Port
-When you uploading, disconnect the Bluetooth connection
-Download and Install the Application:
https://play.google.com/store/apps
-If you get a connection error, reset the Arduino and restart the application

Get the Code:
/*
 -----------------------------------------
  Mert Arduino Tutorial and Projects
  Subscribe for more videos and projects
  Thanks all subscribers ;)
 ----------------------------------------
*/

#include <AFMotor.h> //Adafruit Motor Shield Library. First you must download and install AFMotor library
#include <Servo.h>   //Servo library. This is standard library. (Sketch -> Include Library -> Servo)
String voice;

AF_DCMotor motor1 (1, MOTOR12_1KHZ); //create motor #1 using M1 output on Motor Drive Shield, set to 1kHz PWM frequency
AF_DCMotor motor2 (2, MOTOR12_1KHZ); //create motor #2 using M2 output on Motor Drive Shield, set to 1kHz PWM frequency
Servo myServo; //define servo name
int LED1 = A0; //define LED 1 pin
int LED2 = A1; //define LED 2 pin
int buzzerPin = A2; //define buzzer pin


void setup()
{
  Serial.begin(9600); //start serial communication
  myServo.attach(10); //define our servo pin (the motor shield servo1 input = digital pin 10)
  myServo.write(90);  //servo position is 90 degrees
  pinMode(LED1, OUTPUT); //A0 is output pin
  pinMode(LED2, OUTPUT); //A1 is output pin
  pinMode(buzzerPin, OUTPUT); //A2 is output pin
}

void loop() 
{
  while (Serial.available()){ //Check if there is an available byte to read
     delay(10); //Delay added to make thing stable 
    char c = Serial.read(); //Conduct a serial read
    if (c == '#') {break;} //Exit the loop when the # is detected after the word
    voice += c; //Shorthand for voice = voice + c
  }
  if (voice.length() > 0){
    if(voice == "*go ahead"){
      forward_car();
      }
    else if(voice == "*go back"){
      back_car();
      }
    else if(voice == "*turn right") {
      right_car();
    }
    else if(voice == "*turn left") {
      left_car();
    }
    else if(voice == "*turn on light") {
      LED_on();
    }
    else if(voice == "*turn off light") {
      LED_off();
    }
    else if(voice == "*buzzer") {
      buzzer_on();
    }
    else if(voice == "*stop") {
      stop_car();
    }
    
  voice=""; //Reset the variable after initiating
  }
}

void forward_car()
{
  motor1.run(FORWARD);
  motor1.setSpeed(170);
  motor2.run(FORWARD);
  motor2.setSpeed(170);
  delay(2000);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}
  
void back_car()
{
  motor1.run(BACKWARD);
  motor1.setSpeed(170);
  motor2.run(BACKWARD);
  motor2.setSpeed(170);
  delay(2000);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}
  
void right_car()
{
  myServo.write(0);
  delay(1000);
  myServo.write(90);
  delay(1000);
  motor1.run(FORWARD);
  motor1.setSpeed(170);
  motor2.run(BACKWARD);
  motor2.setSpeed(170);
  delay(1000);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}
  
void left_car()
{
  myServo.write(180);
  delay(1000);
  myServo.write(90);
  delay(1000);
  motor1.run(BACKWARD);
  motor1.setSpeed(170);
  motor2.run(FORWARD);
  motor2.setSpeed(170);
  delay(1000);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}

void LED_on ()
{
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
}

void LED_off ()
{
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
}

void buzzer_on ()
{
  tone(buzzerPin, 100);
  delay(800);
  noTone(buzzerPin);
}

void stop_car ()
{
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}