Socket TCP/IP between an Android System and Arduino
ABSTRACT
The project presented here it
is a system in which a microcontroller captures the voltage level provided by a
temperature sensor, a humidity sensor and a potentiometer. The measures are
transmitted through an Ethernet crosswire to a touch panel with Android 2.2.
The communication between the two devices will be developed with a socket
TCP/IP.
COMPONENTS
Figure
1: components
|
1- Humidity Sensor: 808H5V5.
2- Temperature Sensor: MCP9700A.
3- Potentiometer: 10kΩ.
4- Arduino Uno Board.
5- Arduino Ethernet Shield.
6- Ethernet Cat.5 Crosswire.
7- 7’’ Touch panel with Android 2.2: FDT (EKEP70Q4A0-FDR)
It is necessary powered the Arduino Board and the
touch panel. I have used a charger of 12V/1mA for the touch panel. The Arduino
board is powered with a power-USB wire between it and the touch panel.
DEVELOPMENT
DEVELOPMENT
The first step is to put the sensors on the microcontroller and to
interpreter the voltage level that they provide. In this project, I have chosen
a temperature sensor, humidity sensor and potentiometer of 10K. The features of
the sensors are described in the reference five. The wire connections of the
sensors are directly to Arduino, without resistances, the currents are low,
they are not necessary. The pins 1 of the sensors go to 3.3V and the pin 3 to
GND. The pin 2 of the thermometer is connected to the analog input 0 of the
Arduino, the pin 2 of the humidity sensor is connected to the analog input 1,
and the pin 2 of the potentiometer is connected to the analog input 3.
The second step is to achieve an Ethernet full-duplex data transmitting
with a TCP/IP socket between the microcontroller and the touch panel. The data
will be the measures of the sensors.
Basically the Arduino code reads the voltage levels, it translates them
and opens a client socket to send the data. The code is in the Appendix 1.
The third step is to visualize the data received in the touch panel. The
computer has the Android 2.2 SO, so we will have to write a little Android code
that it will open an Ethernet server socket that it always will be listening in
a specific port to show the sensor data in touch panel. The code is not
provided here.
RESULTS
The final assembly is showed is the Figure 2. The
sensor information is represented in charts similar to speedometers. The sensor
value is drawn in the red characters below the graphs. The temperature is represented between -40ºC and
100ºC. The humidity is in the range between 0%HC and 100%HC. The potentiometer is in the range between 0 and 1024
because it is the range of Arduino 2*10. The refreshing time is 100ms however it could be
less.
Figure 2: Picture of the project. |
PROPOSAL OF IMPROVEMENT
To check that the interactivity is total, it would be
fine that if you push a button in the Arduino board the color of a circle
changes in the Android application. Furthermore, if you push a button in the
Android application, the Arduino digital output changes for switching on or
switch off a led.
The next application could be with a microcontroller
of MICROCHIP, for example the development tool of PIC32 Ethernet Starter Kit.
REFERENCES
[1] Arduino Cookbook by Michael Margolis. Published by O'Reilly
[3] www.arduino.com
[4] EKEP70Q4A0-FDR User
manual
[5]
http://www.libelium.com/documentation/waspmote/gases-sensor-board
APPENDIX 1
Arduino code:
#include
#include
static int temperaturePin =
0;//Analog input
static int potenciometroPin =
1;//Analog input
static int humidityPin=2;//Analog
input
int value=0;
// Enter a MAC address for your
controller below.
// Newer Ethernet shields have a
MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD,
0xBE, 0xEF, 0xFE, 0xED };//The is in the bottom layer of the Ethernet Shield
byte port=2000;//I've choosen 2000
because I like this number. You can change the port
IPAddress server(169,254,1,4); //
IP server
// Initialize the Ethernet client
library with the IP address and port of the server
EthernetClient client;
float Temperatura(void);
float Potenciometro (void);
float Humedad(void);
void setup()
{
Serial.begin(9600);
// start the Ethernet
connection:
if (Ethernet.begin(mac) ==
0)
{
Serial.println("Failed to configure Ethernet");
// no point in
carrying on, so do nothing forevermore:
for(;;)
;
}
// give the Ethernet shield
a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection,
report back via serial:
if (client.connect(server,
port))
{
Serial.println("connected");
// Make a HTTP
request:
client.println("Connecting
with Arduino Ethernet");
client.println();
}
else
{
// if you
didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
float temp=Temperatura();
float pot=Potenciometro();
float hum=Humedad();
// if you get a connection,
report back via serial:
if (client.connect(server,
port))
{
client.print("Temperatura: ");
client.print(temp,2);
client.println("\260C");
client.print("Humedad: ");
client.print(hum,1);
client.println("%");
client.print("Valor del potenciometro: ");
client.println(pot,DEC);
}
else
{
// if you
didn't get a connection to the server:
Serial.println("connection failed");
}
delay(1000);
// if there are incoming
bytes available from the server, read them and print them:
if (client.available())
{
char c =
client.read();
Serial.print(c);
}
delay(1000);
// if the server's
disconnected, stop the client:
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing
forevermore:
for(;;)
;
}
delay(1000);
}
float Temperatura(void)
{
//the analog pin the TMP36's
Vout (sense) pin is connected to the resolution is 10 mV / degree centigrade.
//(500 mV offset) to make
negative temperatures an option
float
temperature=analogRead(temperaturePin) * .004882814;//converting from a 0 to
1023 digital range
// to 0 to 5 volts (each 1
reading equals ~ 5 millivolts.Example: 5:1024=0.004882814
temperature = (temperature -
.5) * 100;//0 degree begins in 500mV
Serial.print("Temperatura:
");
Serial.print(temperature,2);
Serial.println("\260C");
delay(1000);
return(temperature);
}
float Potenciometro (void)
{
//Función que muestra el valor de tensión de la
entrada analogica, que depende del valor del potenciometro
float Vout=analogRead(potenciometroPin);
Serial.print("Valor del potenciometro:
");
Serial.println(Vout,DEC);
delay(1000);
return(Vout);
}
float Humedad (void)
{
//Función que convierte los voltios a humedad
relativa
float humidity=analogRead(humidityPin);
//humidity=((humidity/1000)*33)+0.66;
Serial.print("Humedad:
");
Serial.print(humidity,1);
Serial.println("%");
delay(1000);
return(humidity);
}