Harsh Dethe
Published © CC BY-NC-SA

Smartphone-Controlled Robot Using BLE 4.0

Learn how you can build a simple robot using an Arduino and a BLE module to control it.

IntermediateFull instructions provided2 hours7,260
Smartphone-Controlled Robot Using BLE 4.0

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Motor Shield
×1
Bluetooth Low Energy (4.0)
×1
DC motors
×2
Batteries
×4

Software apps and online services

Arduino IDE
BLE Controller Android App

Story

Read more

Code

BLE_robot.ino

Arduino
No preview (download only).

Code snippet #1

Plain text
#include<AFMotor.h>

AF_DCMotor motorR(1);
AF_DCMotor motorL(2);
char data = 0;

void setup()
{
    Serial.begin(9600);                               
    Serial.println("Motor test !");
    motorR.setSpeed(200);
    motorL.setSpeed(200);
}

void forward()
{
  Serial.println("Going Forward...");
  delay(500);
  motorR.run(FORWARD);
  motorL.run(FORWARD);
}

void backward()
{
  Serial.println("Going Backward...");
  delay(500);
  motorR.run(BACKWARD);
  motorL.run(BACKWARD);
}

void left()
{
  Serial.println("Turning Left...");
  delay(500);
  motorR.run(FORWARD);
  motorL.run(RELEASE);
}

void right()
{
  Serial.println("Turning Right...");
  delay(500);
  motorR.run(RELEASE);
  motorL.run(FORWARD);
}

void hold()
{
  Serial.println("Stop...");
  delay(500);
  motorR.run(RELEASE);
  motorL.run(RELEASE);
}

void spinRight()
{
  Serial.println("Spining Right...");
  delay(500);
  motorR.run(BACKWARD);
  motorL.run(FORWARD);
}

void spinLeft()
{
  Serial.println("Spining Left...");
  delay(500);
  motorR.run(FORWARD);
  motorL.run(BACKWARD);
}
void loop()
{
   if(Serial.available() > 0)  
   {
      data = Serial.read(); 
      Serial.println(data);
                
      if(data == 'a')
      {
        forward();
      }
      else if(data == 'c')
      {
        backward();
      }
      else if(data == 'b')
      {
        right();
      }
      else if(data == 'd')
      {
        left();
      }
      else if(data == 'g')
      {
        hold();
      }
   }
 }

Credits

Harsh Dethe
30 projects • 71 followers
Electronics hobbyist, AI Enthusiast. I like to play with technology.
Contact

Comments

Please log in or sign up to comment.