ELECFREAKS
Published © CC BY-NC

Bluetooth Controlled Mechanical Arm

Get you started with programming of the Arduino compatible mechanical arm.

BeginnerShowcase (no instructions)794

Things used in this project

Hardware components

ELECFREAKS Freaduino
×1
ELECFREAKS Bluetooth Module
×1

Software apps and online services

ELECFREAKS FreaksCar App Download

Story

Read more

Code

Here's how to use APP to turn on and turn off LED which is on the UNO board.

C/C++
#include "ElecfreaksCar.h"

ElecfreaksCar BluetoothModule;
int ledPin = 13;

void setup()
{
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  while(Serial.available())
{
    uint8_t c = Serial.read();
    BluetoothModule.recievedData(&c, 1);
  }
  if(BluetoothModule.getRoll() > 125)
{
    digitalWrite(ledPin, LOW);
  }
else
{   
    digitalWrite(ledPin, HIGH);
  }
}

You can change it to create program yourself of mechanical arm.

C/C++
#include "ElecfreaksCar.h"
#include "Servo.h"

ElecfreaksCar BluetoothModule;  //define a variable of class of ElecfreaksCar which is named BluetoothModule

Servo Servo_Roll;  //This is a servo which to turn direction
Servo Servo_Distance;  //This is a servo which is to control the distance between the machanical hand and object.
Servo Servo_Catch;  //THis is a servo which is to control the manchanical hand to catch or let go.

float P=125.00;  //This is value of pitch. This value is middle value when the rocker in the middle
float R=125.00;  //This is value of roll. This value is middle value when the rocker in the middle
unsigned char Flag_Catch = 0;  //This is a flag about if the machanical hand catch or not

void Button()  //This function is to be run when user touch the button of APP
{
    if(Flag_Catch == 1)
    {
        Servo_Catch.write(0);  //Catch
        Flag_Catch = 0;
    }
    else
    {
        Servo_Catch.write(90);  //let go
        Flag_Catch = 1;
    }
}

void setup()
{
    Serial.begin(115200);  //baud rate
    BluetoothModule.setFun(Button);  //The arduino will run the function which is in the parameter. In here, it will run the function of "Button"

    Servo_Catch.attach(2);  //the servo of catch is connected with pin D2
    Servo_Distance.attach(4);  //the servo of controlling distance between machanical hand and object is connected with pin D4
    Servo_Roll.attach(5);  //the servo of controlling direction is connected with pin D5
}

void loop()
{
    while(Serial.available())  //if there is any data come from bluetooth, it will into the function of while
    {
        uint8_t c = Serial.read();  //read the data of serial com
        BluetoothModule.recievedData(&c, 1);  //recieve the data
        P=(float)BluetoothModule.getPitch();  //get the data of pitch
        R=(float)BluetoothModule.getRoll();  //get the data of roll

        P = P * 0.72;  //This is important. the value of the rocker of APP is from 0 to 250, But the degree of servo is from 0 degree to 180 degrees. 
                       //So we must make the value of pitch to multiplicative (180/250).
        R = R * 0.72;  //the same as pitch
    }
    Servo_Distance.write((int)P);  //make the servo to run the degree
    Servo_Roll.write((int)R); 
}

Credits

ELECFREAKS

ELECFREAKS

11 projects • 0 followers
ELECFREAKS focuses on the micro:bit developed kits and accessories. We are one of the official partners of the BBC micro:bit Foundation.

Comments