Sunday, December 14, 2014

How to Make Android app using MIT app inventor to control a Servo Motor


If you are looking to make Android app to control a servo motor, this is a perfect blog post for you, here you can follow a step by step procedure video to know how to make an android app using MIT app inventor and to control a servo motor. This app sends the angle for the servo from your android phone to your bluetooth connected to the Arduino. where the Arduino receives the angle and executes the program and set the angle to the servo motor.


What components that you need to make this?
Arduino Uno or any other microcontroller.
servo Motor
Bluetooth Module (HC-05)
Android phone :)









After completing the Program in MIT app inventor, go to Build and select App( save .apk to my computer)




Transfer the file to your android mobile phone or tablet.

if your mobile not allowing to install the app from unknown sources.

go to setting in your android mobile select security and move to Device administration and give access to allow install app from unknown sources.



Arduino Program:
___________________________________________________________________________________

#include <SoftwareSerial.h>

#include <Servo.h> 
Servo myservo;

int bluetoothTx = 10;
int bluetoothRx = 11;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  myservo.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()> 0 )
  {
    int servopos = bluetooth.read();
    Serial.println(servopos); 
    myservo.write(servopos);
  }


}

___________________________________________________________________________________

16 comments:

  1. Hello...interesting project...I wonder how to control DC motor replacing the servo motor...to make the dc motor forward or backward or stop...using android phone..

    I hope you could help me about that...thanks
    my email..appyfire@gmail.com

    ReplyDelete
    Replies
    1. http://learnhowtomakerobot.blogspot.in/2014/11/arduino-and-android-control-bluetooth.html

      Delete
  2. plz tell me how to add a sequence

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hello Sir.
    You've used Soft Serial communication by defining Tx,Rx pins. Can I do this by simple serial communication?
    Please reply back. I'm waiting for your reply

    ReplyDelete
    Replies
    1. Hi, i wanna do this usin the HC-06 , how many changes i have to do?

      Delete
  6. I have produced the Android app and run the code exactly as shown on this page (plus some tweaks when I couldn't get it to work), but no matter how I have fooled with things, the servo won't budge. I have scoped the signal going to the servo, and there's nothing but trash that appears momentarily when I use the app. The servo checks fine, and the LED that indicates bluetooth communication flickers when I use the app-any tips?

    ReplyDelete
  7. Lke your detailed video of how to program MIT app inventor for this problem. I am new to this problem, but am interested in controlling a robot with about 5 or 6 degrees of freedom using DC and stepper motors.
    I need to use my own power supply for the motors, but haven't seen much discussion on how to do this. I will be using L298N driver boards to provide power to DC and stepper motors.
    Any thoughts on how to make a circuit for arduino to do this???
    Jim S.

    ReplyDelete
  8. I have built this project.But in seriel monitor it only shows 255.....
    how can I tackle this problem

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. i want to make an application android control servo motor by slider 1 and control DC motor by slider 2 (forward or stop speed) . help me pleas

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This comment has been removed by the author.

      Delete
  11. Seopoly is a main incorporated programming, Apps, site improvement and computerized advertising corporate. We have practical experience in SEO-accommodating site building, app inventor, spot Net framework outlines and open source arrangements. Our group is committed to giving you predominant quality items and benefit and our consumer loyalty record are our reward.

    ReplyDelete
  12. I have a Bluno Beetle V1.0.I copied your code to control a servo. I changed the pin numbers and left everything else the same.
    Should this code work?
    #include // TX RX software library for bluetooth

    #include // servo library
    Servo myservo; // servo name

    int bluetoothTx = 1; // bluetooth tx to 1 pin
    int bluetoothRx = 0; // bluetooth rx to 0 pin

    SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

    void setup()
    {
    myservo.attach(2); // attach servo signal wire to pin 2
    //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()> 0 ) // receive number from bluetooth
    {
    int servopos = bluetooth.read(); // save the received number to servopos
    Serial.println(servopos); // serial print servopos current number received from bluetooth
    myservo.write(servopos); // roate the servo the angle received from the android app
    }


    }

    ReplyDelete