Multi Servo Motor Control via Bluetooth Using the Android App



Arduino Tutorial 20: Multi Servo Motor Control via Bluetooth Using the Android App

Description:

In this tutorial, we will learn how to use multi-servo with an Android application. We will control 4 pcs servo motor with a Smartphone. You can implement your robotic arm projects with reference to this tutorial. Of course we will use external battery / power when doing this. 

Do not forget to subscribe. Thank you for your support.

--------------------

Hardware Required:

- Arduino Board
- HC-06 / 05 Bluetooth Module
- Servo Motor x4
- Wires and Breadboard
- Battery
- Android Device

Recommended site to buy the required hardware:

--------------------

Connections:

- The external battery VCC / GND connect to the breadboard
- The Arduino GND connect to the breadboard's GND input
- The servo connections we use in this project are as follows;

  Orange Input - Signal Input
  Red Input - Power Input (VCC)
  Brown Input - Ground Input(GND)

- The Servo1 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo1 Signal connect to the Arduino Digital PWM 3
- The Servo2 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo2 Signal connect to the Arduino Digital PWM 5
- The Servo3 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo3 Signal connect to the Arduino Digital PWM 6
- The Servo4 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo4 Signal connect to the Arduino Digital PWM 9
- The Bluetooth module attach to the Breadboard
- The Bluetooth VCC connect to the Arduino 3.3V
- The Bluetooth GND connect to the Arduino GND
- The Bluetooth TX connect to the Arduino Digital Pin 10
- The Bluetooth RX connect to the Arduino Digital Pin 11

--------------------

About the Code and Application:

- Get the Application


- You must download and install the SoftwareSerial library


- MIT App Inventor site to create an application.


--------------------

About Bluetooth Connection:

- After establishing a connection, the LED on the Bluetooth module must be active continuously.
- If you get any errors (Device not found, broken pipe, etc.), please check the module connections. If the connections are correct, try connecting to the module a several times. It will be connect.

--------------------

Get the Code :
#include <SoftwareSerial.h> // TX RX software library for bluetooth

#include <Servo.h> // servo library 
Servo myservo1, myservo2, myservo3, myservo4; // servo name

int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  myservo1.attach(3); // attach servo signal wire to pin 9
  myservo2.attach(5);
  myservo3.attach(6);
  myservo4.attach(9);
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int servopos = bluetooth.read();
    unsigned int servopos1 = bluetooth.read();
    unsigned int realservo = (servopos1 *256) + servopos;
    Serial.println(realservo);

    if (realservo >= 1000 && realservo <1180) {
      int servo1 = realservo;
      servo1 = map(servo1, 1000, 1180, 0, 180);
      myservo1.write(servo1);
      Serial.println("Servo 1 ON");
      delay(10);
    }
    if (realservo >= 2000 && realservo <2180) {
      int servo2 = realservo;
      servo2 = map(servo2, 2000, 2180, 0, 180);
      myservo2.write(servo2);
      Serial.println("Servo 2 ON");
      delay(10);
    }
    if (realservo >= 3000 && realservo <3180) {
      int servo3 = realservo;
      servo3 = map(servo3, 3000, 3180, 0, 180);
      myservo3.write(servo3);
      Serial.println("Servo 3 ON");
      delay(10);
    }
    if (realservo >= 4000 && realservo <4180) {
      int servo4 = realservo;
      servo4 = map(servo4, 4000, 4180, 0, 180);
      myservo4.write(servo4);
      Serial.println("Servo 4 ON");
      delay(10);
    }
  }
}