Bluetooth-based Android Controller for Arduino

I was looking for a quick way to connect my arduino with android via Bluetooth to control stuffs easily. The reason for selecting Bluetooth over wi-fi is, Bluetooth pairing done once and multiple Bluetooth devices you can connect simultaneously.

ArduDroid: a Simple 2-Way Bluetooth-based Android Controller for Arduino

INTRODUCTION

After doing little google search came across ARDUDROID (formerly Andruino) is a simple Android app to help you control the pins of your Arduino Uno (or clone) from your Android phone wirelessly. It’s both an Android app and an Arduino program. ArduDroid employs a simple Android user interface to 1) control Arduino Uno’s digital and PWM pins 2) send text commands to Arduino 3) and receive data from Arduino over Bluetooth serial using the ever popular and really cheap (less than $10 from ebay) HC-05 Bluetooth over serial module. This app has been tested and designed for the HC-05 Serial Bluetooth module.
 How to use ArduDroid :
You can use ArduDroid to send commands to Arduino to control a relay to turn electric gadgets on/off, control a robot servo, increase/decrease speed of a motor and reverse direction, dim a light, speed up a fan, and so on. Furthermore, you can read Arduino pins and sensors then transmit the data back to your android phone.

Below code snippet must be in Arduino before starting the ArduDroid app.

/*
 PROJECT: ArduDroid
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: Oct 31, 2013
 FILE: ardudroid.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking.
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(38400);
  Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() return; // if serial empty, return to loop().

  // parse incoming command start flag
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command

  // parse incoming pin# and value
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value

  // 1) GET TEXT COMMAND FROM ARDUDROID
  if (ard_command == CMD_TEXT){
    inText =""; //clears variable for new input
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c;
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ARDUDROID
  if (ard_command == CMD_DIGITALWRITE){
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return.
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ARDUDROID
  if (ard_command == CMD_ANALOGWRITE) {
    analogWrite(  pin_num, pin_value );
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ARDUDROID
  if (ard_command == CMD_READ_ARDUDROID) {
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    Serial.print(" Analog 0 = ");
    Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);
    // add your code here
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);
    // add your code here
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);
    // add your code here
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);
    // add your code here
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);
    // add your code here
    break;
  case 8:
    pinMode(8, OUTPUT);
    digitalWrite(8, pin_value);
    // add your code here
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);
    // add your code here
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);
    // add your code here
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value);
    // add your code here
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);
    // add your code here
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);
    // add your code here
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value);
    // add your code here
    break;
    // default:
    // if nothing else matches, do the default
    // default is optional
  }
}

Reference: http://www.techbitar.com/ardudroid-simple-bluetooth-control-for-arduino-and-android.html

WiFi Audio/Video Raspberry Pi and Android

Play Wireless Audio using Raspberry Pi
This is quite easy by using VLC player.

Step:1 Download and install VLC player in your raspberry pi( I am using Raspbian OS)

First ensure you have the latest Raspbian by using following command

 sudo apt-get update 

Then install VLC
sudo apt-get vlc install
Run VLC player, go to view and select web in interface

In Linux it is not easy to get access
VLC in the latest versions uses a file called ‘.hosts’ to define which computers can access the VLC remote player. You need to open this file and edit it:
you will need to edit the hosts file:
the file is in /usr/share/vlc/lua/http/.hosts
To edit this file from the command line (making sure I have permission to save changes), I use

 cd /usr/share/vlc/lua/http/ 
sudo nano .hosts

 # Access-list for VLC HTTP interface 
# $Id$
#
# localhost
::1
127.0.0.1
# link-local addresses
#fe80::/64
# private addresses
fc00::/7
fec0::/10
10.0.0.0/8
172.16.0.0/12
192.168.0.0/16
169.254.0.0/16
#End


Then save the file.

Now this is the time to test the VLC player web interface is working or not.

Open the browser in Raspberry and type:
http://localhost:8080


If you see the above screen you are ready from Pi side.

Install VLCdirectpro from Android market and connect to the same network.

Open VLC Direct in your device

Open menu

Go to “Settings”

Click “Automatic Connection Wizard”

Click “Start”. VLC Direct will start scanning the network, looking for VLC.

That’s it! VLC Direct is now configured and ready to use!

Click “Automatic Connection Wizard”

 

For better Audio Quality refer to the following links to install Pulse Audio MPD: