Smart Engineers
Published © GPL3+

Arduino all in one robot

Experience the Arduino All-in-One Robot, equipped with Bluetooth, IR remote, voice control, obstacle avoidance, and hand follower.

IntermediateShowcase (no instructions)2 hours628
Arduino all in one robot

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Arduino nano shield (Homemade on zero pcb)
×1
DC Motor, 12 V
DC Motor, 12 V
×4
Bo Motor wheels. diameter-65mm, width-25mm
×4
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
L298n Motor Driver
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Infrared Receiver, 38 kHz
Infrared Receiver, 38 kHz
×1
Proximity Sensor
Proximity Sensor
×2
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×4
Resistor 100 ohm
Resistor 100 ohm
×12
18650 Lithium ion battery 3.7 volt 2000mah
×2
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
On and off switch
×1
Homemade cardboard enclosure Chassis
×1

Software apps and online services

Arduino IDE
Arduino IDE
MIT App Inventor 2
MIT App Inventor 2

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Application to control this robot made by using MIT app inventor

This is the APK file through which you can control this robot after making it. You just need to download this apk file and install it on your smartphone. This app is made by using the MIT app inventor.

aia file for this application

This is a .aia file for this application that is made by using the MIT app inventor. If you want to change or edit something in this application like its name or something else you just need to visit the MIT app inventor site sign up and then import this aia file on MIT app inventor.

Schematics

Circuit Diagram

This is the circuit diagram that you should have to follow to make all the connections.

Code

Arduino all-in-one Robot code

Arduino
By using this Arduino code you can control your robot using Bluetooth, voice, IR remote. You can also switch between different modes like obstacle avoidance and hand-follower.
// Arduino all in one robot car features:-
// . Bluetooth controlled
// . Voice controlled
// . IR remote controlled
// . Speed controlled
// . Front and back RGB leds
// . Going forward obstacle detection
// . Obstacle avoiding mode
// . Hand follower mode
// . Extra functions like blink light, dance, servo movement etc.

#include <IRremote.h>
#include <Servo.h>

IRrecv irrecv (2);
decode_results results;

Servo servo;

const int echo_pin = 4;
const int trig_pin = 5;

const int enable = 6;

const int lmf = 7; // Left motor forward
const int lmb = 8; // Left motor backward
const int rmf = 9; // Right motor forward
const int rmb = 10; // Right motor backward

const int left_ir_sensor = 11; // Left IR sensor
const int right_ir_sensor = 12; // Right IR sensor

const int front_red_pin = A0; // Front RGB led red pin
const int front_green_pin = A1; // Front RGB led green pin
const int front_blue_pin = A2; // Front RGB led blue pin

const int back_red_pin = A3; // Back RGB led red pin
const int back_green_pin = A4; // Back RGB led green pin
const int back_blue_pin = A5; // Back RGB led blue pin

int left_ir_value, right_ir_value; // Variable for storing value from left ir sensor and right ir sensor
int obs, hand; // Variable for changing modes
int Speed = 255; // Variable for controling the spped of motor
int var_1, var_2; // Variable to control rgb lights using ir remote
int distance_left, distance_front, distance_right; // Variable for getting front, left and right distance using ultrasonic sensor
int set = 25; // Variable for obstacle avoidance to set the minimum distance
int check_obs; // Variable for going forward obstacle dectection
int gesture_1; // Variable for gesture control mode using ir sensor
int gesture_2; // Variable for moving forward and backward by hand movement using ultrasonic sensor

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();

  servo.attach(3);
  servo.write(80);

  pinMode(echo_pin, INPUT);
  pinMode(trig_pin, OUTPUT);

  pinMode(enable, OUTPUT);

  pinMode(lmf, OUTPUT);
  pinMode(lmb, OUTPUT);
  pinMode(rmf, OUTPUT);
  pinMode(rmb, OUTPUT);

  pinMode(left_ir_sensor, INPUT);
  pinMode(right_ir_sensor, INPUT);

  pinMode(front_red_pin, OUTPUT);
  pinMode(front_green_pin, OUTPUT);
  pinMode(front_blue_pin, OUTPUT);

  pinMode(back_red_pin, OUTPUT);
  pinMode(back_green_pin, OUTPUT);
  pinMode(back_blue_pin, OUTPUT);


  front_light_off();
  back_light_off();

  delay(500);
}

void loop() {
  if (Serial.available() > 0) {
    int val = Serial.read();
    Serial.println(val);

    // Robot movement commands
    if (val == 1) { // Go forward
      check_obs = 1;
      forward();
    }
    else if (val == 2) { // Go backward
      backward();
    }
    else if (val == 3) { // Rotate left
      rotate_left();
    }
    else if (val == 4) { // Rotate right
      rotate_right();
    }
    else if (val == 5) { // Stop
      stp();
    }
    // RGB led control commands
    else if (val == 6) { // Front light off
      front_light_off();
    }
    else if (val == 7) { // Front red light
      front_red_light();
    }
    else if (val == 8) { // Front green light
      front_green_light();
    }
    else if (val == 9) { // Front blue light
      front_blue_light();
    }
    else if (val == 10) { // Front white light
      front_white_light();
    }
    else if (val == 11) { // Front yellow light
      front_yellow_light();
    }
    else if (val == 12) { // Front cyan light
      front_cyan_light();
    }
    else if (val == 13) { // Front magenta light
      front_magenta_light();
    }
    else if (val == 14) { // Back light off
      back_light_off();
    }
    else if (val == 15) { // Back red light
      back_red_light();
    }
    else if (val == 16) { // Back green light
      back_green_light();
    }
    else if (val == 17) { // Back blue light
      back_blue_light();
    }
    else if (val == 18) { // Back white light
      back_white_light();
    }
    else if (val == 19) { // Back yellow light
      back_yellow_light();
    }
    else if (val == 20) { // Back cyan light
      back_cyan_light();
    }
    else if (val == 21) { // Back magenta light
      back_magenta_light();
    }
    else if (val == 22) { // Obstacle avoiding mode
      obs = obs + 1;
      if (obs == 2) {
        obs = 0;
        stp();
      }
    }
    else if (val == 23) { // Hand follower mode
      hand = hand + 1;
      if (hand == 2) {
        hand = 0;
        stp();
      }
    }
    else if (val == 24) { // Speed low
      Speed = 130;
      front_green_light();
      back_green_light();
      delay(250);
      front_light_off();
      back_light_off();
    }
    else if (val == 25) { // Speed medium
      Speed = 190;
      front_cyan_light();
      back_cyan_light();
      delay(250);
      front_light_off();
      back_light_off();
    }
    else if (val == 26) { // Speed high
      Speed = 255;
      front_magenta_light();
      back_magenta_light();
      delay(250);
      front_light_off();
      back_light_off();
    }

    // Voice controlled commands
    else if (val == 27) { // Voice command go forward
      front_cyan_light();
      forward();
      delay(500);
      stp();
      front_light_off();
    }
    else if (val == 28) { // Voice command go backward
      back_green_light();
      backward();
      delay(500);
      stp();
      back_light_off();
    }
    else if (val == 29) { // Voice command turn left
      servo.write(180);
      rotate_left();
      delay(400);
      stp();
      servo.write(80);
    }
    else if (val == 30) { // Voice command turn right
      servo.write(0);
      rotate_right();
      delay(400);
      stp();
      servo.write(80);
    }
    else if (val == 31) { // Voice command light on (yellow light)
      front_yellow_light();
      back_yellow_light();
    }
    else if (val == 32) { // Voice command light off
      front_light_off();
      back_light_off();
    }
    else if (val == 33) { // Voice command blink light
      blynk_light();
    }
    else if (val == 34) { // Voice command dance
      dance();
    }
  } // VOID LOOP STARTED HERE

  //===========================================================================================================================================================================================
  // ********************************************************************************** FUNCTION FOR IR REMOTE CONTROLLED *********************************************************************
  //===========================================================================================================================================================================================

  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC);

    if (results.value == 33448095) { // Go forward
      check_obs = 1;
      forward();
    }
    else if (results.value == 33464415) { // Go backward
      backward();
    }
    else if (results.value == 33427695) { // Turn left
      left();
    }
    else if (results.value == 33446055) { // Turn right
      right();
    }
    else if (results.value == 33439935) { // Rotate left
      rotate_left();
    }
    else if (results.value == 33472575) { // Rotate right
      rotate_right();
    }
    else if (results.value == 33456255) { // Stop
      stp();
    }
    else if (results.value == 33454215) { // Obstacle avoiding mode
      obs = obs + 1;
      if (obs == 2) {
        obs = 0;
        stp();
      }
    }
    else if (results.value == 33441975) { // Hand follwer mode
      hand = hand + 1;
      if (hand == 2) {
        hand = 0;
        stp();
      }
    }
    else if (results.value == 33444015) { // Speed low
      Speed = 130;
      front_green_light();
      back_green_light();
      delay(250);
      front_light_off();
      back_light_off();
    }
    else if (results.value == 33478695) { // Speed medium
      Speed = 190;
      front_cyan_light();
      back_cyan_light();
      delay(250);
      front_light_off();
      back_light_off();
    }
    else if (results.value == 33486855) { // Speed high
      Speed = 255;
      front_magenta_light();
      back_magenta_light();
      delay(250);
      front_light_off();
      back_light_off();
    }
    else if (results.value == 33460335) { // Front RGB led color change
      var_1 = var_1 + 1;
      if (var_1 == 8) {
        var_1 = 0;
        front_light_off();
      }
      if (var_1 == 1) {
        front_red_light();
      }
      else if (var_1 == 2) {
        front_green_light();
      }
      else if (var_1 == 3) {
        front_blue_light();
      }
      else if (var_1 == 4) {
        front_white_light();
      }
      else if (var_1 == 5) {
        front_yellow_light();
      }
      else if (var_1 == 6) {
        front_cyan_light();
      }
      else if (var_1 == 7) {
        front_magenta_light();
      }
    }
    else if (results.value == 33431775) { // Back RGB led color change
      var_2 = var_2 + 1;
      if (var_2 == 8) {
        var_2 = 0;
        back_light_off();
      }
      if (var_2 == 1) {
        back_red_light();
      }
      else if (var_2 == 2) {
        back_green_light();
      }
      else if (var_2 == 3) {
        back_blue_light();
      }
      else if (var_2 == 4) {
        back_white_light();
      }
      else if (var_2 == 5) {
        back_yellow_light();
      }
      else if (var_2 == 6) {
        back_cyan_light();
      }
      else if (var_2 == 7) {
        back_magenta_light();
      }
    }
    else if (results.value == 33480735) { // Blynk light
      blynk_light();
    }
    else if (results.value == 33435855) { // Gesture control mode using ir sensor
      gesture_1 = gesture_1 + 1;
      if (gesture_1 == 2) {
        gesture_1 = 0;
        stp();
      }
    }
    else if (results.value == 33452175) { // Gesture control mode using ultrasonic sensor
      gesture_2 = gesture_2 + 1;
      if (gesture_2 == 2) {
        gesture_2 = 0;
        stp();
      }
    }
    else if (results.value == 33423615) { // Look left
      servo.write(180);
    }
    else if (results.value == 33484815) { // Look front
      servo.write(80);
    }
    else if (results.value == 33462375) { // Look right
      servo.write(0);
    }
    else if (results.value == 33468495) { // Dance
      dance();
    }
    irrecv.resume();
    delay(250);
  }

  //==========================++===============================================================================================================================================================
  // ******************************************************************************************************************************************************************************************
  //===========================================================================================================================================================================================

  left_ir_value = digitalRead(left_ir_sensor); // Store data from 'left ir sensor' to 'left ir data' variable
  right_ir_value = digitalRead(right_ir_sensor); // Store data from 'right ir sensor' to 'right ir data' variable

  //===========================================================================================================================================================================================
  // ********************************************************************************* FUNCTION FOR GESTURE CONTROL MODE **********************************************************************
  //===========================================================================================================================================================================================

  // Gesture control left and right using ir sensor
  if (gesture_1 == 1) {
    if ((left_ir_value == 1) && (right_ir_value == 0)) {
      servo.write(30);
      rotate_right();
      delay(400);
      servo.write(80);
      stp();
    }
    else if ((left_ir_value == 0) && (right_ir_value == 1)) {
      servo.write(130);
      rotate_left();
      delay(400);
      servo.write(80);
      stp();
    }
    else {
      stp();
    }
  }

  // Gesture control forward and backward using ultrasonic sensor
  if (gesture_2 == 1) {
    distance_front = get_distance();
    if (distance_front >= 15 && distance_front <= 30) {
      forward();
      front_blue_light();
      back_light_off();
    }
    else if (distance_front >= 5 && distance_front <= 14) {
      backward();
      back_blue_light();
      front_light_off();
    }
    else {
      stp();
      front_light_off();
      back_light_off();
    }
    delay(250);
  }

  //===========================================================================================================================================================================================
  // ********************************************************************************* FUNCTION FOR OBSTACLE AVOIDING MODE ********************************************************************
  //===========================================================================================================================================================================================

  if (obs == 1) {
    distance_front = get_distance();
    if ((distance_front <= set) || (left_ir_value == 1) || (right_ir_value == 1))  {
      front_red_light();
      back_red_light();
      hc_sr4();
    }
    else {
      forward();
      front_light_off();
      back_light_off();
    }
  }


  //===========================================================================================================================================================================================
  // ********************************************************************************* FUNCTION FOR HAND FOLLWER MODE *************************************************************************
  //===========================================================================================================================================================================================

  if (hand == 1) {
    if ((left_ir_value == 0) && (right_ir_value == 0)) {
      stp();
    }
    else if ((left_ir_value == 1) && (right_ir_value == 1)) {
      forward();
    }
    else if ((left_ir_value == 1) && (right_ir_value == 0)) {
      rotate_left();
    }
    else if ((left_ir_value == 0) && (right_ir_value == 1)) {
      rotate_right();
    }
  }

  //===========================================================================================================================================================================================
  // **************************************************************************** FUNCTION FOR GOING FORWARD OBSTACLE DETECTION ***************************************************************
  //===========================================================================================================================================================================================

  if (check_obs == 1) {
    distance_front = get_distance();
    if (distance_front <= set) {
      stp();
      front_red_light();
      back_red_light();
      backward();
      servo.write(180);
      delay(250);
      servo.write(0);
      delay(250);
      servo.write(80);
      stp();
      front_light_off();
      back_light_off();
      check_obs = 0;
    }
  }

  //===========================================================================================================================================================================================
  // ******************************************************************************************************************************************************************************************
  //===========================================================================================================================================================================================

  delay(10);
} // VOID LOOP ENDED HERE

//=============================================================================================================================================================================================
// ******************************************************************************** FUNCTIONS FOR RGB LED COLOR CHANGE ************************************************************************
//=============================================================================================================================================================================================

void front_light_off() { // Front RGB led all color off
  digitalWrite(front_red_pin, HIGH);
  digitalWrite(front_green_pin, HIGH);
  digitalWrite(front_blue_pin, HIGH);
}
void front_red_light() { // Front RGB led red color
  digitalWrite(front_red_pin, LOW);
  digitalWrite(front_green_pin, HIGH);
  digitalWrite(front_blue_pin, HIGH);
}
void front_green_light() { // Front RGB led green color
  digitalWrite(front_red_pin, HIGH);
  digitalWrite(front_green_pin, LOW);
  digitalWrite(front_blue_pin, HIGH);
}
void front_blue_light() { // Front RGB led blue color
  digitalWrite(front_red_pin, HIGH);
  digitalWrite(front_green_pin, HIGH);
  digitalWrite(front_blue_pin, LOW);
}
void front_white_light() { // Front RGB led white color
  digitalWrite(front_red_pin, LOW);
  digitalWrite(front_green_pin, LOW);
  digitalWrite(front_blue_pin, LOW);
}
void front_yellow_light() { // Front RGB led yellow color
  digitalWrite(front_red_pin, LOW);
  digitalWrite(front_green_pin, LOW);
  digitalWrite(front_blue_pin, HIGH);
}
void front_cyan_light() { // Front RGB led cyan color
  digitalWrite(front_red_pin, HIGH);
  digitalWrite(front_green_pin, LOW);
  digitalWrite(front_blue_pin, LOW);
}
void front_magenta_light() { // Front RGB led magenta color
  digitalWrite(front_red_pin, LOW);
  digitalWrite(front_green_pin, HIGH);
  digitalWrite(front_blue_pin, LOW);
}

void back_light_off() { // Back RGB led all color off
  digitalWrite(back_red_pin, HIGH);
  digitalWrite(back_green_pin, HIGH);
  digitalWrite(back_blue_pin, HIGH);
}
void back_red_light() { // Back RGB led red color
  digitalWrite(back_red_pin, LOW);
  digitalWrite(back_green_pin, HIGH);
  digitalWrite(back_blue_pin, HIGH);
}
void back_green_light() { // Back RGB led green color
  digitalWrite(back_red_pin, HIGH);
  digitalWrite(back_green_pin, LOW);
  digitalWrite(back_blue_pin, HIGH);
}
void back_blue_light() { // Back RGB led blue color
  digitalWrite(back_red_pin, HIGH);
  digitalWrite(back_green_pin, HIGH);
  digitalWrite(back_blue_pin, LOW);
}
void back_white_light() { // Back RGB led white color
  digitalWrite(back_red_pin, LOW);
  digitalWrite(back_green_pin, LOW);
  digitalWrite(back_blue_pin, LOW);
}
void back_yellow_light() { // Back RGB led yellow color
  digitalWrite(back_red_pin, LOW);
  digitalWrite(back_green_pin, LOW);
  digitalWrite(back_blue_pin, HIGH);
}
void back_cyan_light() { // Back RGB led cyan color
  digitalWrite(back_red_pin, HIGH);
  digitalWrite(back_green_pin, LOW);
  digitalWrite(back_blue_pin, LOW);
}
void back_magenta_light() { // Back RGB led magenta color
  digitalWrite(back_red_pin, LOW);
  digitalWrite(back_green_pin, HIGH);
  digitalWrite(back_blue_pin, LOW);
}


//=============================================================================================================================================================================================
// ********************************************************************************** FUNCTIONS FOR OBSTACLE AVOIDING MODE ********************************************************************
//=============================================================================================================================================================================================

int get_distance() {
  digitalWrite(trig_pin, LOW);
  delayMicroseconds(2);

  digitalWrite(trig_pin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig_pin, LOW);

  long duration = pulseIn(echo_pin, HIGH);
  int distance_cm = duration * 0.034 / 2;  // Calculate distance in centimeters

  return distance_cm;
}

void hc_sr4() {
  stp();
  servo.write(0);
  delay(500);
  distance_right = get_distance();
  delay(100);
  servo.write(170);
  delay(500);
  distance_left = get_distance();
  delay(100);
  servo.write(80);
  delay(300);
  compareDistance();
}

void compareDistance() {
  if (distance_left > distance_right) {
    rotate_left();
    delay(350);
  }
  else if (distance_right > distance_left) {
    rotate_right();
    delay(350);
  }
  else {
    backward();
    delay(500);
    rotate_left();
    delay(500);
  }
}

//=============================================================================================================================================================================================
// ********************************************************************************** FUNCTIONS FOR ROBOT MOVEMENT ****************************************************************************
//=============================================================================================================================================================================================

void forward() {
  digitalWrite(lmf, HIGH);
  digitalWrite(lmb, LOW);
  digitalWrite(rmf, HIGH);
  digitalWrite(rmb, LOW);
  analogWrite(enable, Speed);
}
void backward() {
  digitalWrite(lmf, LOW);
  digitalWrite(lmb, HIGH);
  digitalWrite(rmf, LOW);
  digitalWrite(rmb, HIGH);
  analogWrite(enable, Speed);
}
void stp() {
  digitalWrite(lmf, LOW);
  digitalWrite(lmb, LOW);
  digitalWrite(rmf, LOW);
  digitalWrite(rmb, LOW);
  check_obs = 0;
}
void left() {
  digitalWrite(lmf, HIGH);
  digitalWrite(lmb, LOW);
  digitalWrite(rmf, LOW);
  digitalWrite(rmb, LOW);
  analogWrite(enable, 255);
}
void right() {
  digitalWrite(lmf, LOW);
  digitalWrite(lmb, LOW);
  digitalWrite(rmf, HIGH);
  digitalWrite(rmb, LOW);
  analogWrite(enable, 255);
}
void rotate_left() {
  digitalWrite(lmf, HIGH);
  digitalWrite(lmb, LOW);
  digitalWrite(rmf, LOW);
  digitalWrite(rmb, HIGH);
  analogWrite(enable, 255);
}
void rotate_right() {
  digitalWrite(lmf, LOW);
  digitalWrite(lmb, HIGH);
  digitalWrite(rmf, HIGH);
  digitalWrite(rmb, LOW);
  analogWrite(enable, 255);
}

//=============================================================================================================================================================================================
// ********************************************************************************** FUNCTION FOR BLYNKING LIGHT ****************************************************************************
//============================================================================================================================================================================================

void blynk_light() {
  front_red_light();
  delay(500);
  back_red_light();
  delay(500);
  front_green_light();
  delay(500);
  back_green_light();
  delay(500);
  front_blue_light();
  delay(500);
  back_blue_light();
  delay(500);
  front_white_light();
  delay(500);
  back_white_light();
  delay(500);
  front_yellow_light();
  delay(500);
  back_yellow_light();
  delay(500);
  front_cyan_light();
  delay(500);
  back_cyan_light();
  delay(500);
  front_magenta_light();
  delay(500);
  back_magenta_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
  front_red_light();
  back_red_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
  front_green_light();
  back_green_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
  front_blue_light();
  back_blue_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
  front_white_light();
  back_white_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
  front_yellow_light();
  back_yellow_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
  front_cyan_light();
  back_cyan_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
  front_magenta_light();
  back_magenta_light();
  delay(500);
  front_light_off();
  back_light_off();
  delay(500);
}

//=============================================================================================================================================================================================
// **************************************************************************************** FUNCTION FOR DANCE ********************************************************************************
//=============================================================================================================================================================================================

void dance() {
  front_green_light();
  forward();
  delay(500);
  stp();
  delay(100);
  back_green_light();
  servo.write(180);
  rotate_left();
  delay(1000);
  stp();
  delay(100);
  servo.write(0);
  rotate_right();
  delay(1000);
  stp();
  delay(100);

  front_light_off();
  back_blue_light();
  servo.write(80);
  backward();
  delay(500);
  stp();
  delay(100);
  servo.write(180);
  front_blue_light();
  rotate_left();
  delay(1000);
  stp();
  delay(100);
  servo.write(0);
  rotate_right();
  delay(1000);
  stp();
  delay(100);

  front_yellow_light();
  back_light_off();
  servo.write(80);
  forward();
  delay(500);
  stp();
  delay(100);
  back_yellow_light();
  servo.write(130);
  left();
  delay(1000);
  stp();
  delay(100);
  servo.write(30);
  right();
  delay(1000);
  stp();
  delay(100);

  front_magenta_light();
  back_magenta_light();
  servo.write(180);
  rotate_left();
  delay(1000);
  stp();
  delay(100);
  servo.write(0);
  rotate_right();
  delay(1000);
  stp();
  delay(100);

  front_light_off();
  back_red_light();
  backward();
  servo.write(180);
  delay(250);
  servo.write(0);
  delay(250);
  servo.write(80);
  stp();
  back_light_off();
}

Credits

Smart Engineers

Smart Engineers

1 project • 2 followers
I'm a student who loves playing with robots and gadgets! Started tinkering with electronics a few years ago and haven't stopped since!

Comments