Bluetooth Servo Control

by ImGokul in Circuits > Microcontrollers

1500 Views, 5 Favorites, 0 Comments

Bluetooth Servo Control

5673f47e4936d425f20009c4.jpeg
5673f6b545bcebbf06000617.jpeg

Servos are one of the best things I like in electronics, and in this instructable I'm going to show you how to control a servo motor with your Linkit one and control the angle of the servo on a android phone. The Linkit One will communicate to android phone via Bluetooth, if you want to control it via WiFi you can check out my previous instructables.

Components

IMG_20151218_151330.jpg

Here is a list of all the components required to get started, make sure you collect all the components first before proceeding to other steps-

Servo

HC05 Bluetooth Module

Breadbaord

Wires

Battery

Schematics

len.PNG

The schematics can be found in the picture above, I had to use an Arduino to represent the Linkit one as Fritzing doesn't have a library for the Linkit one yet.

Program

IMG_20151218_151317.jpg

To upload the program you need to install the Linkit one plugin along with the arduino IDE. You can find instructions on how to do that in the official website. You can also download the IDE with the Linkit One plugin pre-installed from GitHub.

#define bluetooth Serial
#include

Servo myServo;

char cmd[100]; int cmdIndex;

void exeCmd() { // "servo" is the servo motor id if(cmd[0]=='s' && cmd[1]=='e' && cmd[2]=='r' && cmd[3]=='v' && cmd[4]=='o' && cmd[5]==' ') { int val = 0; for(int i=6; cmd[i]!=0; i++) { val = val*10 + (cmd[i]-'0'); } // if cmd is "servo 1234", val will be 1234 myServo.writeMicroseconds(val); } }

void setup() { delay(500); // wait for bluetooth module to start

bluetooth.begin(115200); // Bluetooth default baud is 115200 myServo.attach(4, 1000, 2000); cmdIndex = 0; }

void loop() { if(bluetooth.available()) { char c = (char)bluetooth.read(); if(c=='\n') { cmd[cmdIndex] = 0; exeCmd(); // execute the command cmdIndex = 0; // reset the cmdIndex } else { cmd[cmdIndex] = c; if(cmdIndex<99) cmdIndex++; } } }

Android App

For the android phone you need the RoboRemo app from the android Playstore you need to pair the android phone with the bluetooth module and the default password for most of the modules is "1234". After pairing the board connect to the board using the app.