Android phone controls Arduino over wifi

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

Join the Conversation

35 Comments

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

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

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

  4. 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 :)

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

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

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

    (Android phone controls the micro controller through WIFI)

  8. 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..:)

  9. 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…

  10. Hey :)
    that is exactly what i am looking for.. I also try to program a project for my School education and i need 3 Buttons to control an LED Matrix to show the time. Please can you send me the arduino and android code please
    Email: huteralexander@gmail.com
    Thank you

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

  12. did anyone received Android source code “Android phone controls Arduino over wifi “? I hope so because I too am interested at how you code it so please, send it to me :s afy-dee@outlook.kr

  13. What do i win if i too copy and paste this sentence into my comment:
    Can you send me Android sourcecode “Android phone controls Arduino over wifi “.

    Do i get bonus points for paying attention to correctly copy&pasting the white-space between the word wifi and the quote mark?

Leave a comment

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

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