Sunday, 7 April 2019

CONTROLLING SERVO FROM ANDROID
(MIT APP INVENTOR & ARDUINO)


Related to my previous MIT App Inventor tutorial video, someone ask me to making video tutorial video to controlling multiple servo from android. But i don't have enough time to make preparation for "vlogging". So, today i just make post on my blog with some screenshot!







Open your browser, and log in your MIT App Inventor account and create new project.
Drag in Label for displaying accelerometer X, Y value. Don't forget to drag in Bluetooth Client, Clock and Accelerometer Sensor. Rename all variable.








Drag all block needed. Here is screenshot may help you!






And here is Arduino Code. You can copy and paste this code on your Arduino IDE or can directly download from link provided below.

/////////////////////////////////////////////////COPY AND PASTE THIS CODE///////////////////////////////////////////////
#include <Servo.h>
Servo x_servo;
Servo y_servo;

String x_angle; String y_angle;
int x_value; int y_value;

void setup() {
  Serial.begin(9600);
  Serial.setTimeout(30);
  x_servo.attach(4);
  y_servo.attach(5);
  x_servo.write(45); y_servo.write(45); //default position
}

void loop() {
  if (Serial.available() > 0){
    x_angle = Serial.readStringUntil('x'); 
    y_angle = Serial.readStringUntil('y');
    x_value = x_angle.toInt();
    y_value = y_angle.toInt();

    x_servo.write(x_value);
    y_servo.write(y_value);

    //uncomment to reverse servo movement
    //x_servo.write(((x_value)*-1)+180);
    //y_servo.write(((y_value)*-1)+180);
    
  }
}

///////////////////////////////////////////////////////////////END OF CODE////////////////////////////////////////////////////////////







Hardware Setup

Wiring as follow:

I highly recommend to use external power source for servo & bluetooth. They draw lot of current,your project may not running as you expected.

Servo 1 Pulse - Pin 4 Arduino
Servo 2 Pulse - Pin 5 Arduino

Bluetooth TX - RX Arduino
Bluetooth RX - TX Arduino
Bluetooth VCC - 5V Arduino
Bluetooth GND - Arduino GND


Breadboard Layout





Schematic Diagram




This is how i setup. im using Arduino Nano Expension Shield.







Then try to connect your bluetooth from your android to bluetooth module.




DOWNLOAD LINK
1. Android File .AIA


3. Arduino File .INO