Mobile+Bluetooth+Arduino

My project is to control light switch using cellphone and the arduino. My problem is that:
I don't know much about programming in cellphone. So, I'm asking some help on this, and is it possible for the cellphone program to connect with the program of Arduino Uno? BTW, I'm testing it on Symbian OS phones.

Thanks in advance. :blush:

is it possible for the cellphone program to connect with the program of Arduino Uno?

Yes.

I don't know much about programming in cellphone.

That's going to make it hard, then.

Consider using an Arduino with an Ethernet shield and have the Arduino serve a web page for doing stuff to the lights. Then you can use your phone's browser.

A bit like this - here its Morse code on a bright LED, but you'll get the idea.

Here is some simpler example code for turning pins on and off from a Aruino web server, from my book 'Programming Arduino: Getting started with Sketches'. The code is for Arduino 1.0.

// sketch 10-02 Internet Pins

#include <SPI.h>
#include <Ethernet.h>

// MAC address just has to be unique. This should work
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address will be dependent on your local network:
byte ip[] = { 192, 168, 1, 30 };
EthernetServer server(80);

int numPins = 5;
int pins[] = {3, 4, 5, 6, 7};
int pinState[] = {0, 0, 0, 0, 0};
char line1[100];

void setup()
{
  for (int i = 0; i < numPins; i++)
  {
     pinMode(pins[i], OUTPUT);
  }
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  EthernetClient client = server.available();
  if (client) 
  {
    while (client.connected()) 
    {
      readHeader(client);
      if (! pageNameIs("/"))
      {
        client.stop();  
        return;
      }
      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/html");
      client.println();

      // send the body
      client.println("<html><body>");
      client.println("<h1>Output Pins</h1>");
      client.println("<form method='GET'>");  
      setValuesFromParams();
      setPinStates();
      for (int i = 0; i < numPins; i++)
      {
         writeHTMLforPin(client, i);
      }
      client.println("<input type='submit' value='Update'/>");
      client.println("</form>");
      client.println("</body></html>");

      client.stop();            
    }
  }
}

void writeHTMLforPin(EthernetClient client, int i)
{
  client.print("<p>Pin ");
  client.print(pins[i]);  
  client.print("<select name='");
  client.print(i);
  client.println("'>");
  client.print("<option value='0'");
  if (pinState[i] == 0)
  {
    client.print(" selected");
  }
  client.println(">Off</option>");
  client.print("<option value='1'");
  if (pinState[i] == 1)
  {
    client.print(" selected");
  }
  client.println(">On</option>");
  client.println("</select></p>");  
}

void setPinStates()
{
  for (int i = 0; i < numPins; i++)
  {
     digitalWrite(pins[i], pinState[i]);
  }
}

void setValuesFromParams()
{
  for (int i = 0; i < numPins; i++)
  {
    pinState[i] = valueOfParam(i + '0');
  }
}

void readHeader(EthernetClient client)
{
  // read first line of header
  char ch;
  int i = 0;
  while (ch != '\n')
  {
    if (client.available())
    {
      ch = client.read();
      line1[i] = ch;
      i ++;
    }
  }
  line1[i] = '\0'; 
  Serial.println(line1);
}

boolean pageNameIs(char* name)
{
   // page name starts at char pos 4
   // ends with space
   int i = 4;
   char ch = line1[i];
   while (ch != ' ' && ch != '\n' && ch != '?')
   {
     if (name[i-4] != line1[i])
     {
       return false;
     }
     i++;
     ch = line1[i];
   }
   return true;
}

int valueOfParam(char param)
{
  for (int i = 0; i < strlen(line1); i++)
  {
    if (line1[i] == param && line1[i+1] == '=')
    {
      return (line1[i+2] - '0');
    }
  }
  return 0;
}

I don't know much about programming in cellphone.

That's going to make it hard, then.
[/quote]

I'm now studying Java, is there any other choice to program for cellphone? Do I need to make GUI for cellphone?

Si:
Consider using an Arduino with an Ethernet shield and have the Arduino serve a web page for doing stuff to the lights. Then you can use your phone's browser.

A bit like this - here its Morse code on a bright LED, but you'll get the idea.

Dr. Monk's DIY Electronics Blog: Freetronics EtherTen Review

Here is some simpler example code for turning pins on and off from a Aruino web server, from my book 'Programming Arduino: Getting started with Sketches'. The code is for Arduino 1.0.

// sketch 10-02 Internet Pins

#include <SPI.h>
#include <Ethernet.h>

// MAC address just has to be unique. This should work
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address will be dependent on your local network:
byte ip[] = { 192, 168, 1, 30 };
EthernetServer server(80);

int numPins = 5;
int pins[] = {3, 4, 5, 6, 7};
int pinState[] = {0, 0, 0, 0, 0};
char line1[100];

void setup()
{
for (int i = 0; i < numPins; i++)
{
pinMode(pins[i], OUTPUT);
}
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
}

void loop()
{
EthernetClient client = server.available();
if (client)
{
while (client.connected())
{
readHeader(client);
if (! pageNameIs("/"))
{
client.stop();
return;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();

  // send the body
  client.println("<html><body>");
  client.println("<h1>Output Pins</h1>");
  client.println("<form method='GET'>");  
  setValuesFromParams();
  setPinStates();
  for (int i = 0; i < numPins; i++)
  {
     writeHTMLforPin(client, i);
  }
  client.println("<input type='submit' value='Update'/>");
  client.println("</form>");
  client.println("</body></html>");

  client.stop();            
}

}
}

void writeHTMLforPin(EthernetClient client, int i)
{
client.print("

Pin ");
client.print(pins[i]);
client.print("

");
}

void setPinStates()
{
for (int i = 0; i < numPins; i++)
{
digitalWrite(pins[i], pinState[i]);
}
}

void setValuesFromParams()
{
for (int i = 0; i < numPins; i++)
{
pinState[i] = valueOfParam(i + '0');
}
}

void readHeader(EthernetClient client)
{
// read first line of header
char ch;
int i = 0;
while (ch != '\n')
{
if (client.available())
{
ch = client.read();
line1[i] = ch;
i ++;
}
}
line1[i] = '\0';
Serial.println(line1);
}

boolean pageNameIs(char* name)
{
// page name starts at char pos 4
// ends with space
int i = 4;
char ch = line1[i];
while (ch != ' ' && ch != '\n' && ch != '?')
{
if (name[i-4] != line1[i])
{
return false;
}
i++;
ch = line1[i];
}
return true;
}

int valueOfParam(char param)
{
for (int i = 0; i < strlen(line1); i++)
{
if (line1[i] == param && line1[i+1] == '=')
{
return (line1[i+2] - '0');
}
}
return 0;
}

This give me some clues. Thanks for this.

Hi,
Simon, thanks for the example.

This compiles OK on 1.0 but fails on 0022-0023. What might I look for?

Need to stay with 0023 for many other libraries.... Sigh...

Thanks!

Any help?

If you have a an android phone you can get a bluetooth serial app, then connect to a bluetooth serial module (10$ on ebay), which can basically send serial commands to the arduino and vice versa
I've used it on a project, and I can basically set any pin to input or output, high or low, and read back
works real nice
if your interested ill post a library I made that does this for you, which works on the mega and uno, then you can just plug in the module and ittl work

winner10920:
If you have a an android phone you can get a bluetooth serial app, then connect to a bluetooth serial module (10$ on ebay), which can basically send serial commands to the arduino and vice versa
I've used it on a project, and I can basically set any pin to input or output, high or low, and read back
works real nice
if your interested ill post a library I made that does this for you, which works on the mega and uno, then you can just plug in the module and ittl work

If you don't mind sir. I'd like to see that library you made. It might help me a lot. Thanks.

i attached the library, it has a simple readme, if you dont get it let me know its easy to forget to explain something in a readme when you know how everything works an may not find it important

the app in using on the phone is SENA BTerm
the arduino program listens to the incoming serial and parses a 4-7 long char buffer to do simple commands

its designed to run in main loop with the command .listen();
after placing this in your libraries, just use the example to test it out
for some example sending
" 13O1" sets pin 13, output, high
" 13OR" reads status of output ,prints 0/1
"05ID" sets digital pin 5 to input, and prints the reading 0/1
"05IA" takes analog reading of A5 and prints results
"03OA125" sets pin 3, output and pwm(125)

SerialControl.zip (1.97 KB)