Académique Documents
Professionnel Documents
Culture Documents
FEMEC42082
Rede Industriais
Relatrio Modulo 2
Sumrio
1 Introduo
2 Exerccio 1
3 Exerccio 2
4 Exerccio 3
5 Exerccio 4
6 Exerccio Extra
7 Concluso
10
8 Referncias Bibliogrficas
10
9 Anexos
9.1 Cdigo fonte Exerccio 1
9.1.1 Mestre . . . . . .
9.1.2 Escravo Serial . .
9.1.3 Escravo I2C . . .
9.2 Cdigo fonte Exerccio 2
9.3 Cdigo fonte Exerccio 3
9.3.1 Mestre 1 . . . . .
9.3.2 Mestre 2 . . . . .
9.3.3 Escravo 1 . . . . .
9.3.4 Escravo 2 . . . . .
9.4 Cdigo fonte Exerccio 4
11
11
11
13
14
15
17
17
20
23
26
27
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Lista de Figuras
1
2
3
4
5
Exerccio Mestre-escravo. . . . .
Exerccio Token ring. . . . . . .
Exerccio Multi Mestre-escravo.
Exerccio Arduino Yun. . . . . .
Exerccio Token Passing. . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
6
7
8
9
Introduo
Exerccio 1
Exerccio 2
presentado pelo canal vazio, e cada dispositivo s pode enviar uma mensagem
se seu canal de recebimento estiver vazio. Para este exerccio so utilizados 3
botes e 3 LEDs. Cada boto e LED est conectado a um Arduino. Ao pressionar um boto uma mensagem deve ser enviada para acionar o LED do Arduino
que se encontra na posio anterior a sua no anel.
Exerccio 3
Exerccio 4
O exerccio consiste em utilizar um Arduino Yn com um Web server para colher a temperatura de um sensor LM35 e apresenta-la na pgina Web, alm do
status de algumas sadas digitais.
Exerccio Extra
Concluso
A implementao dos protocolos nos exerccios apresentados facilita a compreenso destas formas de comunicao, pois podemos verificar seu funcionamento.
Referncias Bibliogrficas
10
Anexos
9.1
9.1.1
// MESTRE
# include <Wire . h>
const i n t A d r e s s S l a v e = 3 ;
i n t L1 ;
i n t L2 ;
i n t L3 ;
i n t temperatura ;
int n ;
int s t a t ;
int estado [ 3 ] ;
void setup ( ) {
S e r i a l . begin ( 9 6 0 0 ) ;
S e r i a l 1 . begin ( 9 6 0 0 ) ;
Wire . begin ( ) ;
}
// I n i c i a com . S e r i a l > PC
// I n i c i a com . S e r i a l > Escravo 1
// I n i c i a com . I 2 c > Escravo 2
void loop ( ) {
// S o l i c i t a r temperatura
S e r i a l 1 . p r i n t ( T ) ;
delay ( 5 0 0 ) ;
// Recuperar temperatura
while ( S e r i a l 1 . a v a i l a b l e ( ) ) {
temperatura = S e r i a l 1 . read ( ) ;
Serial1 . flush ( ) ;
}
S e r i a l . p r i n t ( " temperatura : " ) ;
S e r i a l . p r i n t l n ( temperatura ) ;
// D e c i d i r Led a l i g a r
i f ( temperatura <28)
{
L1 =1;
L2 =0;
L3 =0;
}
e l s e i f ( temperatura >=28 && temperatura <30)
{
L1 =1;
L2 =1;
L3 =0;
11
}
e l s e i f ( temperatura >=32)
{
L1 =1;
L2 =1;
L3 =1;
}
// Mandar l i g a r os l e d s
Ligar ( ) ;
// Recuperar os s t a t u s
Recuperar ( ) ;
// Imprimir S t a t u s
estado [0]= s t a t /100;
e s t a d o [ 1 ] = ( s t a t 100* e s t a d o [ 0 ] ) / 1 0 ;
e s t a d o [ 2 ] = ( s t a t 100* e s t a d o [0] 10* e s t a d o [ 1 ] ) ;
// S e r i a l . p r i n t ( e s t a d o [ 0 ] ) ;
// S e r i a l . p r i n t ( e s t a d o [ 1 ] ) ;
// S e r i a l . p r i n t l n ( e s t a d o [ 2 ] ) ;
S e r i a l . p r i n t ( " Led 1 e s t a " ) ;
i f ( estado [0]==0) {
Serial . println ( " desligado " ) ;
}
else {
Serial . println ( " ligado " ) ;
}
S e r i a l . p r i n t ( " Led 2 e s t a " ) ;
i f ( estado [1]==0) {
Serial . println ( " desligado " ) ;
}
else {
Serial . println ( " ligado " ) ;
}
S e r i a l . p r i n t ( " Led 3 e s t a " ) ;
i f ( estado [2]==0) {
Serial . println ( " desligado " ) ;
}
else {
Serial . println ( " ligado " ) ;
}
delay ( 1 0 0 0 ) ;
}
12
void L i g a r ( ) {
Wire . beginTransmission ( A d r e s s S l a v e ) ;
Wire . w r i t e ( L1 ) ;
Wire . w r i t e ( L2 ) ;
Wire . w r i t e ( L3 ) ;
Wire . endTransmission ( ) ;
}
i n t Recuperar ( ) {
Wire . requestFrom ( AdressSlave , 1 ) ;
while ( Wire . a v a i l a b l e ( ) ) {
// o e s c r a v o pode e n v i a r menos do que o
solicitado
s t a t = Wire . read ( ) ; // r e c e i v e a byte as c h a r a c t e
}
// S e r i a l . p r i n t l n ( s t a t ) ;
return s t a t ;
}
Algoritmo Arduino
9.1.2
Escravo Serial
const i n t s e n s o r = A4 ;
i n t temp = 0 ;
i n t cmd ;
// LM35 na p o r t a A4
void setup ( ) {
S e r i a l . begin ( 9 6 0 0 ) ;
}
void loop ( ) {
while ( S e r i a l . a v a i l a b l e ( ) >0) {
cmd = S e r i a l . read ( ) ;
}
i f (cmd== T | | cmd == t ) {
temp =round ( ( ( 4 . 8 * analogRead ( s e n s o r ) ) /1023) * 100) ;
S e r i a l . w r i t e ( temp ) ;
}
}
Algoritmo Arduino
13
9.1.3
Escravo I2C
// ESCRAVO I2C
# include <Wire . h>
const i n t myAdress = 3 ;
const i n t Led1 = 4 ;
const i n t Led2 = 3 ;
const i n t Led3 = 2 ;
boolean e s t a d o ;
i n t cmd [ 3 ] ;
void setup ( ) {
Wire . begin ( myAdress ) ;
pinMode ( Led1 ,OUTPUT) ;
pinMode ( Led2 ,OUTPUT) ;
pinMode ( Led3 ,OUTPUT) ;
Wire . onReceive ( Reception ) ;
Wire . onRequest ( Request ) ;
}
void loop ( ) {
delay ( 1 0 0 ) ;
}
//
//
//
//
//
I n i c i a a comunicacao I2C
Configura a p o r t a 4 como s a i d a
Configura a p o r t a 3 como s a i d a
Configura a p o r t a 2 como s a i d a
Chamda quando r e c e p c a o
14
}
}
void Request ( )
{
i n t L1 , L2 , L3 ;
i f ( d i g i t a l R e a d ( Led1 ) ==HIGH) {
L1 =1;
}
else
{
L1 =0;
}
i f ( d i g i t a l R e a d ( Led2 ) ==HIGH) {
L2 =1;
}
else
{
L2 =0;
}
i f ( d i g i t a l R e a d ( Led3 ) ==HIGH) {
L3 =1;
}
else
{
L3 =0;
}
i n t s t a t =100*L1+10*L2+L3 ;
Wire . w r i t e ( s t a t ) ;
}
Algoritmo Arduino
9.2
15
// Arduino n o 3
c o n s t byte MeuID=B01000000 ;
c o n s t byte I D _ s l a v e=B00100000 ;
//
*/
// C r i a c a o de um s e r i a l v i r t u a l para p e r m i t i r o monitoramento v i a UBSB
S o f t w a r e S e r i a l Ring ( 1 0 , 1 1 ) ; // RX, TX
msg ;
cmd ;
endereco ;
estado_led ;
void setup ( ) {
pinMode ( Led , OUTPUT) ;
pinMode ( botao , INPUT ) ;
S e r i a l . begin ( 9 6 0 0 ) ;
Ring . begin ( 9 6 0 0 ) ;
}
void loop ( )
{
cmd=0;
i f ( d i g i t a l R e a d ( botao ) ==HIGH)
{
cmd = I D _ s l a v e ;
cmd++;
delay ( 2 5 0 ) ;
}
// Para s a b e r s e o c a n a l e s t v a z i o e e l e pode t r a n s m i t i r
i f ( Ring . a v a i l a b l e ( ) ==0 && cmd>0) // no r e c e b e nemhum dados
{ // PODE TRANSMITIR
Ring . w r i t e (cmd ) ;
S e r i a l . p r i n t ( "cmd=" ) ;
S e r i a l . p r i n t l n (cmd ) ;
}
e l s e i f ( Ring . a v a i l a b l e ( ) >0) // s e r e c e b e r alguma mensagem v i a
serial
{
msg = Ring . read ( ) ; // armazena o byte em msg
// d el ay ( 1 0 0 ) ;
S e r i a l . p r i n t ( " msg=" ) ;
16
S e r i a l . p r i n t l n ( msg ) ;
endereco = msg & B11110000 ;
e s t a d o _ l e d = msg & B00001111 ;
i f ( endereco==MeuID )
{
i f ( e s t a d o _ l e d >0)
{
d i g i t a l W r i t e ( Led , ! d i g i t a l R e a d ( Led ) ) ;
}
}
else
{
Ring . w r i t e ( msg ) ;
// d el ay ( 2 5 0 ) ;
}
}
}
Algoritmo Arduino
9.3
9.3.1
/*
MODULO 2
EXERCICIO 3
PROGRAMA MESTRE 1 ( L e i t u r a temperatura e l i g a r l e d )
*/
# include <SPI . h>
# include <E t h e r n e t . h>
# include <EthernetUdp . h>
# include <Wire . h>
# include < S o f t w a r e S e r i a l . h>
# define A d r e s s S l a v e 4
/* I n i c i a l i z a o S e r i a l v i r t u a l */
S o f t w a r e S e r i a l Escravo ( 1 0 , 11) ; // RX, TX
/* */
/* I n i c i a l i z a o para e t h e r n e t */
EthernetUDP Udp ;
byte MAC[ ] = { 0 x90 , 0xA2 , 0xDA, 0x00 , 0x64 , 0x50 } ;
17
byte MyIP [ ] = { 1 9 2 , 1 6 8 , 1 , 1 2 5 } ;
byte OtherIP [ ] = { 1 9 2 , 1 6 8 , 1 , 2 5 0 } ;
unsigned i n t p o r t = 8888;
char p a c k e t B u f f e r [ UDP_TX_PACKET_MAX_SIZE ] ;
/* */
/* Declara o das v a r i a v e i s */
i n t TOKEN=0;
i n t temperatura ;
i n t L1 ;
i n t L2 ;
i n t L3 ;
/* */
void setup ( )
{
E t h e r n e t . begin (MAC, MyIP ) ;
Udp . begin ( p o r t ) ;
S e r i a l . begin ( 9 6 0 0 ) ;
Escravo . begin ( 9 6 0 0 ) ;
Wire . begin ( ) ;
pinMode ( 1 3 ,OUTPUT) ;
d i g i t a l W r i t e ( 1 3 ,LOW) ;
}
void loop ( )
{
S e r i a l . p r i n t ( "TOKEN=" ) ;
S e r i a l . p r i n t l n (TOKEN) ;
while (TOKEN==0)
{
/* V e r i f i c a r Token */
char p a c k e t S i z e = Udp . p a r s e P a c k e t ( ) ;
i f ( packetSize )
{
Udp . read ( p a c k e t B u f f e r , UDP_TX_PACKET_MAX_SIZE ) ;
i f ( p a c k e t B u f f e r [0]== T )
{
TOKEN=1;
d i g i t a l W r i t e ( 1 3 ,HIGH) ;
S e r i a l . p r i n t l n ( "TOKEN r e c e b i d o " ) ;
}
else
18
{
d i g i t a l W r i t e ( 1 3 ,LOW) ;
}
}
/* */
}
i f (TOKEN==1)
{
Escravo . w r i t e ( t ) ;
while ( Escravo . a v a i l a b l e ( ) >0)
{
i n t temperatura = Escravo . read ( ) ;
}
S e r i a l . p r i n t ( " Temperatura = " ) ;
S e r i a l . p r i n t l n ( temperatura ) ;
i f ( temperatura <=26)
{
S e r i a l . p r i n t l n ( " Temperatura < 26 " ) ;
S e r i a l . p r i n t ( "Cama OFF/ C l o s e t OFF/ Banheiro OFF" ) ;
L1 =0;
L2 =0;
L3 =0;
}
e l s e i f ( temperatura >26&&temperatura <=28)
{
S e r i a l . p r i n t l n ( " Temperatura e n t r e 26 e 28 " ) ;
S e r i a l . p r i n t ( "Cama ON/ C l o s e t OFF/ Banheiro OFF" ) ;
L1 =1;
L2 =0;
L3 =0;
}
e l s e i f ( temperatura >28&&temperatura <=30)
{
S e r i a l . p r i n t l n ( " Temperatura e n t r e 28 e 30 " ) ;
S e r i a l . p r i n t ( "Cama ON/ C l o s e t ON/ Banheiro OFF" ) ;
L1 =1;
L2 =1;
L3 =0;
}
else
{
S e r i a l . p r i n t l n ( " Temperatura acima de 30 " ) ;
S e r i a l . p r i n t ( "Cama ON/ C l o s e t ON/ Banheiro ON" ) ;
L1 =1;
L2 =1;
L3 =1;
19
}
Ligar ( ) ;
/* P a s s a r Token */
Udp . b e gi n Pa c ke t ( OtherIP , p o r t ) ;
Udp . w r i t e ( T ) ;
Udp . endPacket ( ) ;
TOKEN=0;
d i g i t a l W r i t e ( 1 3 ,LOW) ;
S e r i a l . p r i n t l n ( "TOKEN mandado " ) ;
/* */
}
}
void L i g a r ( ) {
Wire . beginTransmission ( A d r e s s S l a v e ) ;
Wire . w r i t e ( L1 ) ;
Wire . w r i t e ( L2 ) ;
Wire . w r i t e ( L3 ) ;
Wire . endTransmission ( ) ;
}
Algoritmo Arduino
9.3.2
Mestre 2
/*
MODULO 2
EXERCICIO 3
PROGRAMA MESTRE 2 ( L e i t u r a s t a t u s l e d e l i g a r com botao )
*/
# include <SPI . h>
# include <E t h e r n e t . h>
# include <EthernetUdp . h>
# include <Wire . h>
# include < S o f t w a r e S e r i a l . h>
# define A d r e s s S l a v e 3
/* I n i c i a l i z a o S e r i a l v i r t u a l */
S o f t w a r e S e r i a l Escravo ( 1 0 , 11) ; // RX, TX
/* */
/* I n i c i a l i z a o para e t h e r n e t */
EthernetUDP Udp ;
20
void setup ( )
{
E t h e r n e t . begin (MAC, MyIP ) ;
Udp . begin ( p o r t ) ;
S e r i a l . begin ( 9 6 0 0 ) ;
Escravo . begin ( 9 6 0 0 ) ;
Wire . begin ( ) ;
pinMode ( 1 3 ,OUTPUT) ;
d i g i t a l W r i t e ( 1 3 ,HIGH) ;
}
void loop ( )
{
S e r i a l . p r i n t ( "TOKEN=" ) ;
S e r i a l . p r i n t l n (TOKEN) ;
while (TOKEN==0)
{
/* V e r i f i c a r Token */
i n t p a c k e t S i z e = Udp . p a r s e P a c k e t ( ) ;
i f ( packetSize )
{
Udp . read ( p a c k e t B u f f e r , UDP_TX_PACKET_MAX_SIZE ) ;
i f ( p a c k e t B u f f e r [0]== T )
{
TOKEN=1;
d i g i t a l W r i t e ( 1 3 ,HIGH) ;
S e r i a l . p r i n t l n ( "TOKEN r e c e b i d o " ) ;
}
else
21
{
d i g i t a l W r i t e ( 1 3 ,LOW) ;
}
}
/* */
}
i f (TOKEN==1)
{
Escravo . w r i t e ( s ) ;
while ( Escravo . a v a i l a b l e ( ) >0)
{
i n t s t a t = Escravo . read ( ) ;
}
i f ( s t a t == b )
{
Mandar ( ) ;
S e r i a l . p r i n t l n ( " Bot o acionado " ) ;
}
else
{
estado [0]= s t a t /100;
e s t a d o [ 1 ] = ( s t a t 100* e s t a d o [ 0 ] ) / 1 0 ;
e s t a d o [ 2 ] = ( s t a t 100* e s t a d o [0] 10* e s t a d o [ 1 ] ) ;
S e r i a l . p r i n t ( " Led 1 e s t a " ) ;
i f ( estado [0]==0)
{
Serial . println ( " desligado " ) ;
}
else
{
Serial . println ( " ligado " ) ;
}
S e r i a l . p r i n t ( " Led 2 e s t a " ) ;
i f ( estado [1]==0)
{
Serial . println ( " desligado " ) ;
}
else
{
Serial . println ( " ligado " ) ;
}
S e r i a l . p r i n t ( " Led 3 e s t a " ) ;
i f ( estado [2]==0)
{
Serial . println ( " desligado " ) ;
22
}
else
{
Serial . println ( " ligado " ) ;
}
}
S e r i a l . p r i n t l n ( " ok " ) ;
/* P a s s a r Token */
Udp . b e gi n Pa c ke t ( OtherIP , p o r t ) ;
Serial . println ( " 1 " ) ;
Udp . w r i t e ( T ) ;
Serial . println ( " 2 " ) ;
Udp . endPacket ( ) ;
Serial . println ( " 3 " ) ;
TOKEN=0;
d i g i t a l W r i t e ( 1 3 ,LOW) ;
S e r i a l . p r i n t l n ( "TOKEN mandado " ) ;
/* */
}
}
void Mandar ( ) {
Wire . beginTransmission ( A d r e s s S l a v e ) ;
Wire . w r i t e ( b ) ;
Wire . endTransmission ( ) ;
}
Algoritmo Arduino
9.3.3
Escravo 1
/*
MODULO 2
EXERCICIO 3
PROGRAMA ESCRAVO 1 ( l i g a r os l e d s ( I2C ) e bot o ( S e r i a l ) )
*/
# include <Wire . h>
# define A d r e s s S l a v e 4
/* Declara o das v a r i a v e i s */
i n t L1 ;
i n t L2 ;
i n t L3 ;
i n t Led1 =4;
i n t Led2 =3;
i n t Led3 =2;
23
i n t cmd [ 3 ] ;
i n t botao =10;
/* */
void setup ( )
{
S e r i a l . begin ( 9 6 0 0 ) ;
Wire . begin ( A d r e s s S l a v e ) ;
Wire . onReceive ( Reception ) ;
pinMode ( Led1 ,OUTPUT) ;
pinMode ( Led2 ,OUTPUT) ;
pinMode ( Led3 ,OUTPUT) ;
pinMode ( botao , INPUT ) ;
}
// Chamda quando r e c e p c a o
void loop ( )
{
while ( S e r i a l . a v a i l a b l e ( ) >0)
{
i n t c = S e r i a l . read ( ) ;
i f ( c== s )
{
Serial . write ( estado ( ) ) ;
}
}
i f ( d i g i t a l R e a d ( botao ) )
{
Serial . write ( b ) ;
delay ( 2 5 0 ) ;
}
}
void Reception ( i n t Quanto )
{
i n t n=0;
while ( Wire . a v a i l a b l e ( ) >0)
{
cmd [ n ] = Wire . read ( ) ;
n++;
}
i f (cmd[ 0 ] = = 0 )
{
d i g i t a l W r i t e ( Led1 ,LOW) ;
}
else
{
d i g i t a l W r i t e ( Led1 , HIGH) ;
}
// Recebe o comando 1 , 2 ou 3
24
i f (cmd[ 1 ] = = 0 )
{
d i g i t a l W r i t e ( Led2 ,LOW) ;
}
else
{
d i g i t a l W r i t e ( Led2 , HIGH) ;
}
i f (cmd[ 2 ] = = 0 )
{
d i g i t a l W r i t e ( Led3 ,LOW) ;
}
else
{
d i g i t a l W r i t e ( Led3 , HIGH) ;
}
}
int estado ( )
{
i n t L1 , L2 , L3 ;
i f ( d i g i t a l R e a d ( Led1 ) ==HIGH) {
L1 =1;
}
else
{
L1 =0;
}
i f ( d i g i t a l R e a d ( Led2 ) ==HIGH) {
L2 =1;
}
else
{
L2 =0;
}
i f ( d i g i t a l R e a d ( Led3 ) ==HIGH) {
L3 =1;
}
else
{
L3 =0;
}
i n t s t a t =100*L1+10*L2+L3 ;
return ( s t a t ) ;
}
Algoritmo Arduino
25
9.3.4
Escravo 2
/*
MODULO 2
EXERCICIO 3
PROGRAMA ESCRAVO 2 ( l i g a r o l e d ( I2C ) e temperatura ( S e r i a l ) )
*/
# include <Wire . h>
# define A d r e s s S l a v e 3
/* Declara o das v a r i a v e i s */
i n t s e n s o r = A0 ;
i n t Led =13;
i n t cmd=0;
int c ;
i n t temperatura ;
/* */
void setup ( )
{
S e r i a l . begin ( 9 6 0 0 ) ;
Wire . begin ( A d r e s s S l a v e ) ;
Wire . onReceive ( Reception ) ;
pinMode ( Led ,OUTPUT) ;
}
// Chamda quando r e c e p c a o
void loop ( )
{
while ( S e r i a l . a v a i l a b l e ( ) >0)
{
c = S e r i a l . read ( ) ;
i f ( c== t )
{
temperatura = round ( ( ( 4 . 8 * analogRead ( s e n s o r ) ) /1023) * 100) ;
S e r i a l . w r i t e ( temperatura ) ;
}
Serial . flush ( ) ;
}
}
void Reception ( i n t Quanto )
{
cmd = 0 ;
while ( Wire . a v a i l a b l e ( ) >0)
{
26
Algoritmo Arduino
9.4
//
27
}
void loop ( ) {
// Get c l i e n t s coming from s e r v e r
YunClient c l i e n t = s e r v e r . a c c e p t ( ) ;
// There i s a new c l i e n t ?
if ( client ) {
// read the command
S t r i n g command = c l i e n t . r e a d S t r i n g ( ) ;
command . trim ( ) ;
// k i l l whitespace
S e r i a l . p r i n t l n ( command ) ;
// i s " temperature " command?
i f ( command == " temperature " ) {
// g e t the time from the s e r v e r :
P r o c e s s time ;
time . runShellCommand ( " date " ) ;
String timeString = " " ;
while ( time . a v a i l a b l e ( ) ) {
char c = time . read ( ) ;
t i m e S t r i n g += c ;
}
Serial . println ( timeString ) ;
i n t sensorValue = analogRead ( s e n s o r ) ;
// c o n v e r t the r e a d i n g t o m i l l i v o l t s :
f l o a t v o l t a g e = sensorValue * (5000/ 1024) ;
// c o n v e r t the m i l l i v o l t s t o temperature c e l s i u s :
f l o a t temperature = ( v o l t a g e 500) / 1 0 ;
// p r i n t the temperature :
c l i e n t . p r i n t ( " Temperatura : " ) ;
c l i e n t . p r i n t l n ( temperature ) ;
}
// Close c o n n e c t i o n and f r e e r e s o u r c e s .
c l i e n t . stop ( ) ;
}
delay ( 5 0 ) ; // P o l l every 50ms
}
Algoritmo Arduino
28