Introduction: Control Servo Over Bluetooth
A servo motor is a lot useful in DIY projects The reason is that you can control the angle of your servo motor through various commands. Today I would be telling you how to control your servo motor wirelessly using bluetooth. We would be using a smartphone application to control the servo. Please note that here we eould be using a external bluetooth module not the linkit one internal module.
Step 1: Gather Parts
Here are parts required by you to make this project:
- Likit one
- servo motor
- HC05 or HC 06 bluetooth module
- Breadboard
- Jump cables
Step 2: Connect the Bluetooth Module
We are not using the inbuilt bluetooth module of linkit one as it takes a lot of time to connect with a device and it bluetooth module also don't work with all apps. Instead of that we would be using the bluetooth module that we use in arduino projects i.e HC-05 or HC-06. This module is comparatively easy to use and to program and pairing of this module is also not very though. Here are its connections:
- vcc of module-----vcc of the board
- gnd of module-----gnd of the board
- rx of the module-----tx of the board
- tx of the module-----rx of the board
Step 3: Connect the Servo Motor
I advise you to place the top of the servo so that you can easily see the movement of the servo. The servo motor is a very unique and important motor. Connect gnd of servo to linkit one gnd, vcc of servo to vcc of board and vout of servo to digital pin 9.
Step 4: Upload the Code
Here is the code for the project:
#include
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int motor = 0;
void setup()
{
Serial.begin(9600); // initialize serial:
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.print("Arduino control Servo Motor Connected OK");
Serial.print('\n');
}
void loop()
{
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
motor = Serial.parseInt();
// do it again:
pos = Serial.parseInt();
// look for the newline. That's the end of your sentence:
if (Serial.read() == '\n') {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
// print the three numbers in one string as hexadecimal:
Serial.print("Data Response : ");
Serial.print(motor, DEC);
Serial.print(pos, DEC);
}
}
}
//for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
//{ // in steps of 1 degree
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(15); // waits 15ms for the servo to reach the position
//}
//for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
//{
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(15); // waits 15ms for the servo to reach the position
//}
//val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
//val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
//myservo.write(val); // sets the servo position according to the scaled value
//delay(15);
Step 5: Download the App
To control the servo, we would be using a mobile app You can easily find the app on the app store. Go to app store and search for Arduino bluetooth servo motor. Install the app and open it. Pair your mobile device to you bluetooth module and connect to it using the app. now you would be able to control your motor.
Step 6: END
Enjoy using your servo motor with your mobile. This is the end of this instructable. Hope you like it. For any problem comment below. More projects coming soon. THANK you