Project tutorial
Wireless robot controlled by pointing with your smartphone o

Wireless robot controlled by pointing with your smartphone o © CC BY-NC-SA

This project is to control wireless robot by pointing with our smartphone at any direction we want the robot to go .

  • 2,017 views
  • 2 comments
  • 9 respects

Components and supplies

Necessary tools and machines

Arduino IDE
1sheeld Mobile application

About this project


This project is to control wireless robot by pointing with our smartphone at any direction we what the robot to go ( when the phone leans forward , backward , left or right ) Or by giving it Voice orders ( Forward , Backward , left or right ) .We can use the same idea for chair of disabled people ,so they can only move their phones or give the chair an order by their voice .So let's know how this is made step by step .

- Mount and adjust 1Sheeld as illustrated here 

- Mount the Motor shield over 1sheeld board

 - Connect the Arduino board to your PC to burn the code ( Illustrated code attached )

/* Hi, My Name is Mona 

Here is an illustrated code for controlling wirless robot using smartphone ( when your phone leans forward robot moves forward,

when your phone leans backwards the robot moves backward and the same for left and right directions ), or you can control it by saying 

"forward" it will move forward and the same thing for the other 3 directions .

if you said wrong word your smartphone will tell you " please say you order again " using text-to-speech shield */

/* for any questions feel free to contact me at monamohamed816@gmail.com */

#define CUSTOM_SETTINGS

#define INCLUDE_ORIENTATION_SENSOR_SHIELD

#define INCLUDE_VOICE_RECOGNIZER_SHIELD

#define INCLUDE_TEXT_TO_SPEECH_SHIELD 

#include <OneSheeld.h>

/* SeeedStudio Motor shield uses Arduino pins from 8 to 13 */ 

int M1=9 ; // to Enable and control speed of the first motor 

int M2=10 ; // to Enbale and control speed of the second motor 

int M11= 8; //this pin controls OUT1 in the motor shield ( connected with the first terminal of the first motor )

int M12 = 11; // this pin controls OUT2 in the motor shield ( connected with the second terminal of the first motor )

int M21 = 12; // this pin controls OUT3 in the motor shield (connected with the frist terminal of the second motor )

int M22 = 13 ; // this pin controls OUT4 in the motor shield ( connected with the second terminal of the second motor ) 

/* Defining the Voice Commands */ 

const char forwardCommand[]="forward";

const char backwardCommand [] ="backward";

const char rightCommand[]="right";

const char leftCommand[]="left";

void setup() 

{

  OneSheeld.begin();

  VoiceRecognition.start(); // Activates voice recognition shield 

  pinMode(M11 , OUTPUT ) ;

  pinMode(M12 , OUTPUT ) ;

  pinMode(M21 , OUTPUT ) ;

  pinMode(M22 , OUTPUT ) ;

  pinMode(M1 , OUTPUT ) ;

  pinMode (M2 , OUTPUT ) ;

}

void function() // function defined for Voice Recognition shield orders 

{ if ( VoiceRecognition.isNewCommandReceived()) // checks if there is a new command 

   { if (!strcmp(forwardCommand ,VoiceRecognition.getLastCommand())) // compares the word said by the user with Forward command

      { analogWrite (M1,255) ;

        analogWrite (M2,255);

        digitalWrite(M11 , HIGH );

      digitalWrite (M12 ,LOW);

      digitalWrite(M21 , HIGH ) ;

      digitalWrite(M22,LOW); 

      }

else if (!strcmp(backwardCommand , VoiceRecognition.getLastCommand())) // compares the word said by the user with backward command

      { analogWrite (M1,255) ;

        analogWrite (M2,255);

        digitalWrite(M11 , LOW);

      digitalWrite (M12 ,HIGH);

      digitalWrite(M21 , LOW ) ;

      digitalWrite(M22,HIGH ); 

      }

     else if(!strcmp(leftCommand, VoiceRecognition.getLastCommand())) // compares the word said by the user with left command

      { analogWrite (M1,255) ;

        analogWrite (M2,255);

       digitalWrite(M11 , LOW );

      digitalWrite (M12 ,LOW );

      digitalWrite(M21 , HIGH ) ;

      digitalWrite(M22,LOW );

      }

      else if(!strcmp(rightCommand , VoiceRecognition.getLastCommand()))// compares the word said by the user with right command

      { analogWrite (M1,255) ;

        analogWrite (M2,255);

        digitalWrite(M11 , HIGH);

      digitalWrite (M12 ,LOW);

      digitalWrite(M21 , LOW ) ;

      digitalWrite(M22, LOW );

      }

      // if all commands don't match the defined commands , your smartphone will say " please say your order again " 

      else { 

        TextToSpeech.say("please say your order again") ;

     digitalWrite(M11 , LOW);

     digitalWrite (M12 ,LOW);

     digitalWrite(M21 , LOW );

     digitalWrite(M22, LOW ); }  }

}

void loop () 

  { analogWrite (M1,255) ;

        analogWrite (M2,255); 

    digitalWrite(M11 , LOW);

     digitalWrite (M12 ,LOW);

     digitalWrite(M21 , LOW );

     digitalWrite(M22, LOW );      

void function() ;

/* Using orientation shield to control the robot my moving the phone , as when it leans forward or backward or left or right

the degree of X,Y and Z changes  */

  /* Forward */

  if ((OrientationSensor.getX() > 20 && OrientationSensor.getY() > 3 && OrientationSensor.getZ()>0 )) /* when the arduino gets these vales

  of X,Y and Z it recognizes the position of the phone */

     {analogWrite (M1,255) ;

        analogWrite (M2,255); 

      digitalWrite(M11 , HIGH );

      digitalWrite (M12 ,LOW);

      digitalWrite(M21 , HIGH ) ;

      digitalWrite(M22,LOW);

         }

   /*Backward*/   

    if ((OrientationSensor.getX()<160 && OrientationSensor.getY() < -20 && OrientationSensor.getZ()>2 ))

  { analogWrite (M1,255) ;

        analogWrite (M2,255);  

    digitalWrite(M11 , LOW);

      digitalWrite (M12 ,HIGH);

      digitalWrite(M21 , LOW ) ;

      digitalWrite(M22,HIGH );  

   }  

   /*left*/   

    if ( (OrientationSensor.getX() > 170 && OrientationSensor.getY() < 0 && OrientationSensor.getZ() > 30 ))

  { analogWrite (M1,255) ;

        analogWrite (M2,255); 

    digitalWrite(M11 , LOW );

      digitalWrite (M12 ,LOW );

      digitalWrite(M21 , HIGH ) ;

      digitalWrite(M22,LOW ); 

  }

 /*right*/ 

   if (( OrientationSensor.getX() > 140 && OrientationSensor.getY() < -17 && OrientationSensor.getZ() < -10 ))

  { analogWrite (M1,255) ;

        analogWrite (M2,255);

     digitalWrite(M11 , HIGH);

      digitalWrite (M12 ,LOW);

      digitalWrite(M21 , LOW ) ;

      digitalWrite(M22, LOW ); } 

      }


- Now connect two terminals of the left Motor to OUT1 and OUT2 , and the two terminals of the right Motor to OUT3 and OUT4 

- Then connect the batteries , red wire to Vcc and black wire toGND 

- Then scan for your shield and select Orientation shield , Voice recognition shield and Text to speech shield

- lean your Smartphone forward ( you can notices on the orientation shield the values of X, Y and Z change ) , the robot moves forward 

- Or you can put down your phone and use Voice Recognition shield to give voice orders ( press tap to speak )

 - And finally text to speech shield will warn you if you said wrong voice order and tells you " please say your order again "





Code

Motors_Orientation_shield.inoArduino
/* Hi, My Name is Mona 
Here is an illustrated code for controlling wirless robot using smartphone ( when your phone leans forward robot moves forward,
when your phone leans backwards the robot moves backward and the same for left and right directions ), or you can control it by saying 
"forward" it will move forward and the same thing for the other 3 directions .
if you said wrong word your smartphone will tell you " please say you order again " using text-to-speech shield */

/* for any questions feel free to contact me at monamohamed816@gmail.com */
#define CUSTOM_SETTINGS

#define INCLUDE_ORIENTATION_SENSOR_SHIELD
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
#define INCLUDE_TEXT_TO_SPEECH_SHIELD 

#include <OneSheeld.h>

/* SeeedStudio Motor shield uses Arduino pins from 8 to 13 */ 

int M1=9 ; // to Enable and control speed of the first motor 
int M2=10 ; // to Enbale and control speed of the second motor 
int M11= 8; //this pin controls OUT1 in the motor shield ( connected with the first terminal of the first motor )
int M12 = 11; // this pin controls OUT2 in the motor shield ( connected with the second terminal of the first motor )
int M21 = 12; // this pin controls OUT3 in the motor shield (connected with the frist terminal of the second motor )
int M22 = 13 ; // this pin controls OUT4 in the motor shield ( connected with the second terminal of the second motor ) 


/* Defining the Voice Commands */ 
const char forwardCommand[]="forward";
const char backwardCommand [] ="backward";
const char rightCommand[]="right";
const char leftCommand[]="left";


void setup() 
{
  OneSheeld.begin();
  VoiceRecognition.start(); // Activates voice recognition shield 
  pinMode(M11 , OUTPUT ) ;
  pinMode(M12 , OUTPUT ) ;
  pinMode(M21 , OUTPUT ) ;
  pinMode(M22 , OUTPUT ) ;
  pinMode(M1 , OUTPUT ) ;
  pinMode (M2 , OUTPUT ) ;
  
}

void function() // function defined for Voice Recognition shield orders 
{ if ( VoiceRecognition.isNewCommandReceived()) // checks if there is a new command 
   { if (!strcmp(forwardCommand ,VoiceRecognition.getLastCommand())) // compares the word said by the user with Forward command
      { analogWrite (M1,255) ;
        analogWrite (M2,255);
        digitalWrite(M11 , HIGH );
      digitalWrite (M12 ,LOW);
      digitalWrite(M21 , HIGH ) ;
      digitalWrite(M22,LOW); 
      }
 
else if (!strcmp(backwardCommand , VoiceRecognition.getLastCommand())) // compares the word said by the user with backward command
      { analogWrite (M1,255) ;
        analogWrite (M2,255);
        digitalWrite(M11 , LOW);
      digitalWrite (M12 ,HIGH);
      digitalWrite(M21 , LOW ) ;
      digitalWrite(M22,HIGH ); 
      }

     else if(!strcmp(leftCommand, VoiceRecognition.getLastCommand())) // compares the word said by the user with left command
      { analogWrite (M1,255) ;
        analogWrite (M2,255);
       digitalWrite(M11 , LOW );
      digitalWrite (M12 ,LOW );
      digitalWrite(M21 , HIGH ) ;
      digitalWrite(M22,LOW );
      }

      else if(!strcmp(rightCommand , VoiceRecognition.getLastCommand()))// compares the word said by the user with right command
      { analogWrite (M1,255) ;
        analogWrite (M2,255);
        digitalWrite(M11 , HIGH);
      digitalWrite (M12 ,LOW);
      digitalWrite(M21 , LOW ) ;
      digitalWrite(M22, LOW );
      }

      // if all commands don't match the defined commands , your smartphone will say " please say your order again " 
      else { 
        TextToSpeech.say("please say your order again") ;
     digitalWrite(M11 , LOW);
     digitalWrite (M12 ,LOW);
     digitalWrite(M21 , LOW );
     digitalWrite(M22, LOW ); }  }
}

void loop () 
     
  { analogWrite (M1,255) ;
        analogWrite (M2,255); 
    digitalWrite(M11 , LOW);
     digitalWrite (M12 ,LOW);
     digitalWrite(M21 , LOW );
     digitalWrite(M22, LOW );      
 

void function() ;
/* Using orientation shield to control the robot my moving the phone , as when it leans forward or backward or left or right
the degree of X,Y and Z changes  */
 
  /* Forward */
  if ((OrientationSensor.getX() > 20 && OrientationSensor.getY() > 3 && OrientationSensor.getZ()>0 )) /* when the arduino gets these vales
  of X,Y and Z it recognizes the position of the phone */
      
     {analogWrite (M1,255) ;
        analogWrite (M2,255); 
      digitalWrite(M11 , HIGH );
      digitalWrite (M12 ,LOW);
      digitalWrite(M21 , HIGH ) ;
      digitalWrite(M22,LOW);
         }
  

      
   /*Backward*/   
    if ((OrientationSensor.getX()<160 && OrientationSensor.getY() < -20 && OrientationSensor.getZ()>2 ))

  { analogWrite (M1,255) ;
        analogWrite (M2,255);  
    digitalWrite(M11 , LOW);
      digitalWrite (M12 ,HIGH);
      digitalWrite(M21 , LOW ) ;
      digitalWrite(M22,HIGH );  
   }  
   

   /*left*/   
    if ( (OrientationSensor.getX() > 170 && OrientationSensor.getY() < 0 && OrientationSensor.getZ() > 30 ))

  { analogWrite (M1,255) ;
        analogWrite (M2,255); 
    digitalWrite(M11 , LOW );
      digitalWrite (M12 ,LOW );
      digitalWrite(M21 , HIGH ) ;
      digitalWrite(M22,LOW ); 
  }
   
 
 
 /*right*/ 
   if (( OrientationSensor.getX() > 140 && OrientationSensor.getY() < -17 && OrientationSensor.getZ() < -10 ))

  { analogWrite (M1,255) ;
        analogWrite (M2,255);
     digitalWrite(M11 , HIGH);
      digitalWrite (M12 ,LOW);
      digitalWrite(M21 , LOW ) ;
      digitalWrite(M22, LOW ); } 

      }

Schematics

Wireless robot control
Untitled%20Sketch.fzz

Comments

Similar projects you might like

Voice Controlled Robot using your Smart Phone

Project tutorial by Ahmed Yassin

  • 3,057 views
  • 0 comments
  • 7 respects

Smartphone Controlled Arduino 4WD Robot Car

Project in progress by Andriy Baranov

  • 53,280 views
  • 43 comments
  • 98 respects

Two Mode Robot Controlling through Android and Windowsphone8

Project tutorial by Anas Siddiqui

  • 16,314 views
  • 9 comments
  • 48 respects

Line Follower Robot Using Arduino & 1Sheeld

Project tutorial by Ashraf Nabil

  • 2,157 views
  • 0 comments
  • 5 respects

2WD Voice Controlled Robot with Arduino and BitVoicer Server

Project tutorial by Marcio Tamagushi

  • 10,213 views
  • 11 comments
  • 32 respects
Add projectSign up / Login