Skip to content

14. INTERFACE AND APPLICATION PROGRAMMING

INDIVIDUAL ASSIGNMENT:

Write an application that interfaces a user with an input &/or output device that you made

GROUP ASSIGNMENT:

Compare as many tool options as possible

Voice controlled robot

For the voice controlled robot , I used bluetooth module HC-05. Voice controlled robot is a kind of robot which can be controlled by bluetooth communication. User has the bluetooth app in his/her smartphone. I made this app using MIT app inventor.

Programming Logic or Robot schematic :

1] The voice controlled app sends the direction movements of the robot to the bluetooth module HC-05, through voice commands given .

2] The bluetooth module HC-05 will receive the data transmitted from the app.

3] The arduino Uno will read the data received and then take the necessary actions based on the received data.

4] Finally, the motor driver will receive the commands from the arduino and will provide necessary power for the motors to move the robot.

Bluetooth module

HC-05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup.

More information abut bluetooth HC-05 module

MIT app inventor

App Inventor is a free, cloud-based service that can be accessed using a web browser. The apps made using the app inventor could be tested on the android phone using the companion app.

More about MIT app inventor

APP code 1

Arduino code 1

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(3,4); // Rx of arduino=3 , Rx of arduino=4
char bt;



void setup() {
  // put your setup code here, to run once:
bluetooth.begin(9600); // Begins the communication between the bluetooth module and the arduino UNO with Baud rate 9600
Serial.begin(9600); // Begins the Serial Communication with the Baud rate 9600.
pinMode(10,OUTPUT); // Sets the Pins 10,11,12,13 as OUTPUT Pin.
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);

}

/* A function is a way for programmers to reuse code without having to rewrite the code.
 *  Syntax : returntype functionName ( arguments)
 *             // function body
 *             return eturntype;
 *             }
  */

  void moveRobot(String motion) {
    if( motion == "Forward")  {  // RW - FWD(10 - Pos, 11- Neg) ; LW-FWD( 12-Pos , 13-Neg)
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);       
    Serial.println("Forward");
    }


    if( motion == "Backward") {  //RW - Bck(10 - Neg, 11- Pos) ; LW-FWD( 12-Neg , 13-Pos)
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);       
    Serial.println("Backward");
    }

     if( motion == "Left") {  //RW - FWD(10 - Pos, 11- Neg) ; LW-FWD( 12-Neg , 13-Pos)
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);       
    Serial.println("Left");
    }

    if( motion == "Right") {  //RW - FWD(10 - Neg, 11- Pos) ; LW-FWD( 12-Pos , 13-Neg)
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);       
    Serial.println("Right");
    }

    if( motion == "Stop") {  //RW - FWD(10 - Neg, 11- Neg) ; LW-FWD( 12-Neg , 13-Neg)
    digitalWrite(10,LOW);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,LOW);       
    Serial.println("Stop");
    }

  }


    void loop() {
  // put your main code here, to run repeatedly:

  if(bluetooth.available() ) { // Checks if bluetooth is available or not.
  bt = bluetooth.read() ; // Read the data from Bluetooth and store it in "bt".


 }

   Serial.println("The character sent from voice controller app is:" +String(bt));


  if(bt =='f'){               // The character sent by the app for forward condition is 'f'. Characters are represented in single quotes and string in double quotes.
    moveRobot("Forward");
  }

  if(bt =='b')
  {
    moveRobot("Backward");

  }
    if(bt =='l')
    {
    moveRobot("Left");

  }

   if(bt =='r')
   {
    moveRobot("Right");

  }

if(bt =='s')  
    {
    moveRobot("Stop");

  }

    }

APP code 2

Arduino code 2

#include<SoftwareSerial.h> // includes the software library
SoftwareSerial bluetooth(3,4);
 char bt;  // bt is just the variable name. Any name can be given to a charcter.
void setup() {
  // put your setup code here, to run once:
  bluetooth.begin(9600);
  Serial.begin(9600);
  Serial.println("Pair with bluetooth");
  pinMode(13,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
}
void moveRobot(String motion)
{
  if(motion=="Forward")
  {
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    Serial.println("Forward");

  }



  if(motion=="Backward")
  {
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
        Serial.println("Backward");
  }


  if(motion=="Left")
  {
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
       Serial.println("Left");
  }



  if(motion=="Right")
  {
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
       Serial.println("Right");
  }



  if(motion=="Stop")
  {
    digitalWrite(10,LOW);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,LOW);
        Serial.println("Stop");
  }
}
void loop() {
  // put your main code here, to run repeatedly:
String data=""; // can just be String data. Need not write String data =" "
 while(bluetooth.available())
  {

 bt=bluetooth.read();
    data+=bt; // data = data+bt . The word data is also a variavle name. Any name can be given instaed of data like voice , response etc . This adds new charcters to existing chacters thus forming a STRING

    Serial.println(String(data));
    if(data=="forward") // IN the voice app when we call out the directions, the word will be displayed in this manner.
    {
      moveRobot("Forward");

    }
    else if(data=="backward")
    {
      moveRobot("Backward");

    }
    else if(data=="right")
    {
      moveRobot("Right");

    }
    else if(data=="left")
    {
      moveRobot("Left");

    }
    else if(data=="stop")
    {
      moveRobot("Stop");

    }


    }

  }

Serial monitor readings

App interface

Connecting with bluetooth module HC-05

Video of voice controlled Robot


Last update: May 12, 2021