Android phone controls Arduino over wifi

in Android, Arduino by 7 | 22 comments

We recently did a little demo to send data to an Arduino with a TCP/IP Shield (using ATC-1000M) from an Android device via Wifi.

The Android phone in this demo uses Android Scripting Environment (ASE). It is available on Android Market for free.

Videos and source code after the break.

Here is a short video demonstration of blinking the Arduino LED using Android.

// By 7
// Version 00.08.01
#include <SoftwareSerial.h>

#define rxPin 0
#define txPin 1
#define ledPin 13

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
mySerial.begin(9600);
}

void loop()
{
char c = mySerial.read();
if(c=='A')
  digitalWrite(ledPin, HIGH);
if(c=='B')
  digitalWrite(ledPin, LOW);
}

Arduino Simple Source Code

'''
This is used to send a
character to the Arduino
via Wifi

By 7
'''

import android, socket

droid = android.Android()

STR_SEND_A='positive'
STR_SEND_B='negative'
STR_EXIT='neutral'

def test_alert_dialog_with_buttons():
  title = 'Alert'
  message = ('What do yo want to Send?')
  droid.dialogCreateAlert(title, message)
  droid.dialogSetPositiveButtonText('A')
  droid.dialogSetNegativeButtonText('B')
  droid.dialogSetNeutralButtonText('Exit')
  droid.dialogShow()
  response = droid.dialogGetResponse().result
  return response['which']

#Change this depending on the IP and Port of the ATC-1000M
HOST='192.168.7.3'
PORT=23

boolExit=False
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
    s.connect((HOST,PORT))
    while(boolExit==False):
        res=test_alert_dialog_with_buttons()
        if(res==STR_SEND_A):
         s.send('A')
        if(res==STR_SEND_B):
         s.send('B')
        if(res==STR_EXIT):
         boolExit=True
finally:
  s.close()

print 'Done! Thank You!'

Python for Android Source Code

This entry was posted in Android, Arduino and tagged , .

Comments

  1. keystoneclimber says:

    Would have been impressive if the WIFI hardware was connected to and controlled by the microcontroller.

  2. 7 says:

    ^^ actually, that would be next (hopefully)

  3. glutnix_neo says:

    seven! seven! seven!

  4. glutnix_neo says:

    I have one question, why did you use a software serial instead of the hardware UART which is available for pin 0 and 1?

  5. Dai anh Tai says:

    Can you sell for me Android sourcecode “Android phone controls Arduino over wifi “.
    Thanks.

  6. Dai Anh Tai says:

    Link died.
    Can you upload again or sell for me android code wifi.
    Thanks a lots.

  7. thor says:

    the link is deleted but the code is still posted above.

  8. Dustyn says:

    Nice! Have you seen anything like this using the iPhone?

  9. Raju says:

    i like your idea much.. dear plz can you send me android code for this project. asaleemj@gmail.com is my id i will be so much thankfull you..:)

  10. Ufo says:

    Hi.

    Can you send me too your android code on e-mail: uso567@list.ru.

    Cheers,
    Ufo

  11. Mirza says:

    Can you please send me the source code. I would appreciate that. My email is mirza.ramicic@hotmail.com . Thank you in advance!

  12. Mrad says:

    this is what i was looking for..i want to do an application with 4 bottons that controls 2 dc motors connected to an arduino mega via wifi..can u send me the android source code please. Mrad.13@hotmail.com
    thank u in advance :)

  13. Pidozky says:

    Good day!
    Can you also share with the android source code. dude_jhun15@yahoo.com
    Thanks a lot…

  14. uzy says:

    how to transfer data from arduino to android?

  15. sharizal says:

    can u email to me the android source code.. im really appreciated your helps.. im developing arduino project now.. tq

  16. Alejandro says:

    Can you send me too your android code on e-mail:avionica1@yahoo.com.mx
    Thanks a lot.

  17. Jopas says:

    nice work ! can u send me the full android program coz this is what i’am looking for .. tenk you in advance :D e-mail: momo20.js@gmail.com

  18. marwa ben massoud says:

    it ‘s a nice job ,please could you send me your android code thank you
    my mail: marwabenmassoud123@gmail.com

  19. ipan says:

    Pl. share me the schematic diagram and source code to implement for my final year project

    (Android phone controls the micro controller through WIFI)

  20. Jhon says:

    Very nice your idea.. I am a student system engineering and I am interested in learning how to control android and arduino using wifi , plz can you send me android code for this project. my email is jhonmc120@gmail.com I will be so much thankfull you..:)

  21. mehul says:

    I am a student MCA and I am interested in learning how to control android and arduino using wifi , plz can you send me android code for this project. my email is mehul.vekariya001@gmail.com I will be so much thankful you..:)

  22. Unknown says:

    This is what i was looking for… :) can i control any UART wifi module by my android phone? i haven’t arduino… reply me soon plz…

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.