Android to control light using Arduino

Description: the android device will serve as switch for the lights in the house. It will be using bluetooth connection. Can this be done?

This is just a draft diagram:

yes, you need an Arduino with a bluetooth interface. In essence that is a serial port, never tried butshould work.

Alternative is to make: Android --- webserver/Arduino ---- Light

Then it can be controlled by any device with internet access. The advantage of bluetooth is that only devices nearby can control the arduino. Be sure to have a manual override at the arduino.

robtillaart: yes, you need an Arduino with a bluetooth interface. In essence that is a serial port, never tried butshould work.

Alternative is to make: Android --- webserver/Arduino ---- Light

Then it can be controlled by any device with internet access. The advantage of bluetooth is that only devices nearby can control the arduino. Be sure to have a manual override at the arduino.

thanks for the reply. Yah, I picked bluetooth for security purpose. Is there a specific Arduino that I should use? I'm just really new with this stuff.

This one is often recommended on the forum - http://www.sparkfun.com/products/10269 - with some header pins it is quite reusable for multiple projects. It is on my wishlist ...

There is an Arduino BT but it is hardwired and therefor not flexible/modular. And the price of the sparkfun module is quite acceptable imho. Search bluetooth @ sparkfun and you will find some more modules. There are other resellers too.

my 2 cents.

robtillaart: This one is often recommended on the forum - http://www.sparkfun.com/products/10269 - with some header pins it is quite reusable for multiple projects. It is on my wishlist ...

There is an Arduino BT but it is hardwired and therefor not flexible/modular. And the price of the sparkfun module is quite acceptable imho. Search bluetooth @ sparkfun and you will find some more modules. There are other resellers too.

my 2 cents.

thank you for the link. :) Uhm, where will this be plugged? I'm curious, how does the bluetooth reads the data when the button is pressed at the android device?

I'm curious, how does the bluetooth reads the data when the button is pressed at the android device?

I think the android device enables its internal bluetooth first, it sets up some protocol to speak serial with the BT module (there are several protocols that can be spoken over bluetooth) After that it connects to the BT module and then sends a byte or two (maybe more :). The BT module converts that signal to a TTL level which can be read by Arduino.

robtillaart:

I'm curious, how does the bluetooth reads the data when the button is pressed at the android device?

I think the android device enables its internal bluetooth first, it sets up some protocol to speak serial with the BT module (there are several protocols that can be spoken over bluetooth) After that it connects to the BT module and then sends a byte or two (maybe more :). The BT module converts that signal to a TTL level which can be read by Arduino.

So android device -> BT module -> Arduino -> light ? ?

In this case, i have to code the Arduino to understand the data received from the BT module?

hello,

why don't you go with wifi instead (I have done it this way) using a router serial connected to an arduino,

this way you get authentication and php handled by the router (might be more cheap on ebay than a bluetooth)

regards

viknet

In this case, i have to code the Arduino to understand the data received from the BT module?

Yep 100% right, AND you need to have an app on your android system that sends the data.

And probably you need a return channel too to confirm that the command has been executed or is that too fancy ?

For the Arduino part you are on the right forum, there are some posts on android on this forum - search them with the textbox in the upper right.

Hi,
I am not an expert, just a senior with a hobby. It is quite easy when you don’t get stuck in details. You need to set the bluetooth on Arduino to 9600 baud. And you can use a finished free Bluetooth chat program like BT Chat.

Here is the example I started with, and then I went on from there to make it work with 4 relays.

And you can also use your computer with bluetooth to control the relays. In Windows you can use Hyper Terminal after you have checked which port to connect to in Windows: Start - Run - devmgmt.msc - ENTER - ports

PS! If you have to change the baud rate on the module anyway, remember to change the password as well when you already are there. 1234 or 0000 is a bit widely known. :slight_smile:

/*
  Switch statement  with serial input
 
 Demonstrates the use of a switch statement.  The switch
 statement allows you to choose from among a set of discrete values
 of a variable.  It's like a series of if statements.
 
 To see this sketch in action, open the Serial monitor and send any character.
 The characters a, b, c, d, and e, will turn on LEDs.  Any other character will turn
 the LEDs off.
 
 The circuit:
 * 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
 
 created 1 Jul 2009
 by Tom Igoe
 
This example code is in the public domain.
   
 http://www.arduino.cc/en/Tutorial/SwitchCase2
 */

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
   // initialize the LED pins:
      for (int thisPin = 2; thisPin < 5; thisPin++) {
        pinMode(thisPin, OUTPUT);
      }
}

void loop() {
  // read the sensor:
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    // do something different depending on the character received.  
    // The switch statement expects single number values for each case;
    // in this exmaple, though, you're using single quotes to tell
    // the controller to get the ASCII value for the character.  For
    // example 'a' = 97, 'b' = 98, and so forth:

    switch (inByte) {
    case 'a':    
      digitalWrite(2, HIGH);
      Serial.println("2 HIGH");
      break;
    case 'b':    
      digitalWrite(2, LOW);
      Serial.println("2 LOW");
      break;
    case 'c':    
      digitalWrite(3, HIGH);
      Serial.println("3 HIGH");
      break;
    case 'd':    
      digitalWrite(3, LOW);
      Serial.println("3 LOW");
      break;
    case 'e':    
      digitalWrite(4, HIGH);
      Serial.println("4 HIGH");
      break;
     case 'f':    
      digitalWrite(4, LOW);
      Serial.println("4 LOW");
      break;
     
    default:
      // turn all the LEDs off:
      for (int thisPin = 2; thisPin < 7; thisPin++) {
        digitalWrite(thisPin, LOW);
      }
    }
  }
}

No need to reinvent the wheel :) Just use ArduinoCommander app https://market.android.com/details?id=name.antonsmirnov.android.arduinocommander and StandardFirmata sketch