Internet of Things with Android and Arduino: Control remote Led

Nowadays a new emerging technology is Internet of Things (IoT): this post describes how to create Internet of things with Android and Arduino. In IoT project, all the physical objects (things) are connected together using internet infrastructure. Arduino borard is one of the most important object in this ecosystem. In this post, we will explore how to integrate Android with Arduino making the first step in IoT.Even Google at io15 presented its new IoT infrastructure called Brillo.
This tutorial describes how to create an Internet of things with Android and Arduino project: android app to control a remote Led.

Internet of Things with Android and Arduino : Overview

The picture below shows the main objects involved in the IoT project:

What we need is:

Arduino Uno

Ethernet shield

Smartphone with Android

All the objects are in the same network for simplicity. The idea is that the smartphone sends an HTTP request to the Arduino. A very small and simple Web server runs on Arduino, accepting HTTP request. For simplicity, the app sends JSON data that holds the led status.

Arduino: Web server and connections

In the Internet of things context (IoT), on the Arduino side, we simply need to connect the led to Arduino main board and control it using one of the Arduino output. The most complex part is creating a Web server that handles HTTP request. The image below shows how Arduino is connected to the led:

As you can see the connection is very simple. The Arduino sketch that implements the web server is shown below:

Almost all the arduino source code is used to handle HTTP connection. Notice that at line 4 we set the MAC Address of the ethernet shield while at line 5 we set the IP address.
In this way Arduino is ready to be integrated inside our internet of things world, it can exchange JSON request with external application including an app that runs on a smartphone. In this first part of Internet of things with Android and Arduino project, you gained the knowledge how to handle HTTP request in Arduino.

You can use other IoT protocols to exchange data between Arduino and Android app.

Android client: Send HTTP request

To complete our Internet of things with Android and Arduino scenario, it is necessary to implement an Android app that sends JSON request.
On Android code side, the things are much more simpler; the Android UI is shown below:

There is one simple button when the user clicks on it, the app sends an HTTP request to Arduino, that runs the web server.
If you want to know more about HTTP look at making HTTP request in Android.
The app layout is very simple and it is not covered here, the core of the app is where the button click is handled:

In this post you gained a basic understanding about how to create arduino webserver example and how to connect it to android app. This project can be extended and could be used as a base for arduino home automation. It is possible to make even more complex project that uses Android app and Arduino to control an RGB led.

This Internet of things project with Android and Arduino showed how to integrate two different ecosystems and make them working together.

About The Author

I'm an electronic engineer with over 15 years of
experience in computer programming. I'm the author of the book "Android things projects". I'm a MVB at DZone and DZone Guide Author. I have contributed to the IoT guide. I'm the technical reviewer of the book Internet of Things with Arduino Blueprints(published by PacktPub). I love creating IoT projects using Arduino, Raspberry Pi,
Android, and other platforms. I am interested in the convergence
between IoT and the mobile applications. I'm SCEA, SCWCD, and SCJP
certified.
Follow on: Twitter | Linkedin

Joseph McKenna

Any way to impliment this with Outlook. Say, whenever you have an unopened email in your inbox, the light goes on?

bhaskar

can anyone tell me why im getting an
error : #include expects “FILENAME” or
on the arduino sketch on line 2.

The idea is the same, you should check, using some Mail Api, if there is an unopened email and contact arduino to turn on the light.

Bongjun Hur

it's very simple and good project for starter. so, If you don't mind, I would like to introduce on WIZnet museum (http://wiznetmuseum.com) for everyone.WIZnet produce the W5100 chipset on Ethernet shield. Hopefully, you will allow this.Thanks.~

shehab

can you please give me the android Source code ,please
as i’m facing some errors with my project .
thanks

Mainak Dev

Sir, i am getting error in the arduino code at line no 63 saying, “amp was not declared in its scope”, my question is what is amp, can you please help me remove this error. Thank You

hi, senior thank you for helping me ,
sir i had a problem with the way you showed to me , that the parse .com they are no longer accepting new accounts and i do not have one , i’m winder if there is another solution < thank you

As far as I know i don’t know an alternative, you could search it and if you find please write it the link so you can help other readers! Thank you

kareem

hi, senior thank you for helping me ,
sir i had a problem with the way you showed to me , that the parse .com they are no longer accepting new accounts and i do not have one , i’m winder if there is another solution < thank you

You should tell me more about this project so that i can have an idea.

Vaishak

Now I’ve decided to use humidity sensor, soil moisture sensor, and temperature sensor and a water pump which works depending on the criteria of these sensors and carries out drip irrigation. I’ll the Arduino microcontroller.

Brian

Hello vaishak, i loved your concept and did u finally succeed in doing this project? Could you help me in doing this project…. The code, the materials required and also the diagram….. My email is briansm96@gmail.com thanq

as far as i know you can use every bluetooth module you like. You could prefer a bluetooth shield that is connected on top of arduino board or a external module. It is up to you.
For my project i use an external module.

Usmar Ismail

hello sir,
i’m usmar ismail from indonesia.
this is awesome,
i have project that i have to create program like this, can you give me a tutorial for android session in this project. i dont get it, please,
i apologize for my english
thankyouuuu
email :usmar69ismail@gmail.com

the android part is in the tutorial. Are you looking for a complete android app source code? If so tell me, i will add it to Github repository.

Liltunechi Chygrynskiychichari

nice tutorial link of your github repository

Aditya Verma

sir i’m using enc28j60 with uipethernet shield.and control lights via android apk.
but problem is that when i press button for led onn/off it will react after 2 to 3 second later.
if i use same apk with wi-fly module rn-171.it reacts within milisecond.
how can i improve speed in ethernet.

hello sir. i want to create a combination of smart mirror and smart window for my iot project with my partner. we want to use the idea of smart mirror and put the idea on the window. the idea of smart window is still there and we just want upgrade the functionality of smart window become smart mirror as well. both of us are lack of knowledge of the arduino. our final year project coordinator wants us to use arduino and preferred the arduino mega. will u help us out with this? we really need help.

Daniel Zachar

Hello, can you please send me the full code via github? I cant find it there. Thank you.

Ihsene Omari

Hi, SIR
the android part is it on Github repositoryt? i’m looking for a complete android app source code?

Gagandeep Brar

Hello sir i want to do project with IOT in the AWS inftastructure…could you please help me to select the idea which king of thing is doable with in 6 weeks.??

HI it seems a prole related to your libraries. You can try to create a new empty sketch and check if it compiles. I sup pose it is a problem not related to the sketch in the post. Let me know the results

Imane Tchantchane

thank you sir ,i fixed the probleme , by downloading the zip file posted in this page, and it has successfuly compiled , the probleme is with posted code cus it s contained some syntaxe error for ex : library is declared : #include <spi.h> #include <ethernet.h>
and the instruction :
if (c == ‘n’ && isLastLin )
could you send me the android complete code , i need it for my final study
project ?

Imane Tchantchane

Hello sir , sorry it was my fault , i compiled the arduino code on the page not the code in the zip file , sir can you send me the full source android code i need it as a part of my final study project , thanks

There are a huge list of projects you can build, it depends on how complex your project must be

Arshad mp

hi sir,
i am a last year eng student,i have a plan to do a project which uses a android application that control a electronic device through internet.i want to get data from the device and store in a server also eant to retrive the data in the app.
can you please help me with the android code and the other server side procedure that i need to follow to complete the project

Get more stuff

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Sign up for our Newsletter

Enter your email and stay on top of things,

Get SwA updates delivered to your inbox. Article, tips, source code

×

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.