TERMOMETRO ROLANTE COM MATRIZ 5X7 E LM35



Neste post continuo com as experiencias com a matriz 5x7 mas desta vez resolvi dar um toque extra usando o setup já montado para exibir a temperatura ambiente com um termometro LM35. O chip LM35 é muito simples de usar e preciso é conectado em uma porta analógica da arduino.

Segue abaixo a ilustração desta montagem:




A explicação sobre a conexão dos shift registers e matriz está nesta página e sobre a conexão do LM35 está nesta página, neste vou somente postar o novo código que montei para calcular a temperatura e apresentar na matriz.

O código abaixo funciona baseado na mudança dos caracteres representados matriz sempre que o termometro informar uma mudança de temperatura, estou utilizando um array (caracts) que contém os nomes dos arrays dos caracteres (t0 a t31) no qual a posição de cada array é exatamente igual ao número obtido com a leitura do termometro. Se tenho 24 graus na leitura do termometro, a posição de número 24 no array geral é o nome do array de caracteres que vai ser carregado na variável (tp)que determina a representação na matriz.

Só fiz as temperaturas de 0 até 31 graus porque se estiver mais ou menos que isto provavelmente não vou querer ficar sabendo....

Segue o código:
----------------------------------------------------------------------------------------

/*

Claudio Miklos 25/07/2010 -  www.miklos.blog.br

62,65,65,65,62,     // O
0,0,33,127,1,       // 1
33,67,69,73,49,     // 2
34,65,73,73,54,     // 3
12,20,36,127,4,     // 4
114,81,81,81,78,    // 5
30,41,73,73,6,      // 6
64,71,72,80,96,     // 7
54,73,73,73,54,     // 8
48,73,73,74,60,     // 9
0,0,112,80,112,     // GRAU
0,0,0,0,0           // VAZIO

*/

int pin = 0;
int tempc = 0;
int i=0;
int tp=0;
int latchpin = 8;
int clockpin = 7;
int datapin = 10;
int t0[] = {0,0,0,0,0,0,62,65,65,65,62,0,112,80,112,0,0,0,0,0};
int t1[] = {0,0,0,0,0,0,0,33,127,1,0,112,80,112,0,0,0,0,0};
int t2[] = {0,0,0,0,0,0,0,33,67,69,73,49,0,112,80,112,0,0,0,0,0};
int t3[] = {0,0,0,0,0,0,34,65,73,73,54,0,112,80,112,0,0,0,0,0};
int t4[] = {0,0,0,0,0,0,12,20,36,127,4,0,112,80,112,0,0,0,0,0};
int t5[] = {0,0,0,0,0,0,114,81,81,81,78,0,112,80,112,0,0,0,0,0};
int t6[] = {0,0,0,0,0,0,30,41,73,73,6,0,112,80,112,0,0,0,0,0};
int t7[] = {0,0,0,0,0,0,64,71,72,80,96, 0,112,80,112,0,0,0,0,0};
int t8[] = {0,0,0,0,0,0,54,73,73,73,54, 0,112,80,112,0,0,0,0,0};
int t9[] = {0,0,0,0,0,0,48,73,73,74,60,0,112,80,112,0,0,0,0,0};
int t10[] = {0,0,0,0,0,0,0,0,33,127,1,0,62,65,65,65,62,0,112,80,112,0,0,0,0,0};
int t11[] = {0,0,0,0,0,0,0,0,33,127,1,0,0,0,0,33,127,1,0,112,80,112,0,0,0,0,0};
int t12[] = {0,0,0,0,0,0,0,0,33,127,1,0,0,33,67,69,73,49,0,112,80,112,0,0,0,0,0};
int t13[] = {0,0,0,0,0,0,0,0,33,127,1,0,34,65,73,73,54,0,112,80,112,0,0,0,0,0};
int t14[] = {0,0,0,0,0,0,0,0,33,127,1,0,12,20,36,127,4,0,112,80,112,0,0,0,0,0};
int t15[] = {0,0,0,0,0,0,0,0,33,127,1,0,114,81,81,81,78,0,112,80,112,0,0,0,0,0};
int t16[] = {0,0,0,0,0,0,0,0,33,127,1,0,30,41,73,73,6,0,112,80,112,0,0,0,0,0};
int t17[] = {0,0,0,0,0,0,0,0,33,127,1,0,64,71,72,80,96,0,112,80,112,0,0,0,0,0};
int t18[] = {0,0,0,0,0,0,0,0,33,127,1,0,54,73,73,73,54,0,112,80,112,0,0,0,0,0};
int t19[] = {0,0,0,0,0,0,0,0,33,127,1,0,48,73,73,74,60,0,112,80,112,0,0,0,0,0};
int t20[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,62,65,65,65,62,0,112,80,112,0,0,0,0,0};
int t21[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,0,33,127,1,0,112,80,112,0,0,0,0,0};
int t22[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,0,33,67,69,73,49,0,112,80,112,0,0,0,0,0};
int t23[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,34,65,73,73,54,0,112,80,112,0,0,0,0,0};
int t24[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,12,20,36,127,4,0,112,80,112,0,0,0,0,0};
int t25[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,114,81,81,81,78,0,112,80,112,0,0,0,0,0};
int t26[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,30,41,73,73,6,0,112,80,112,0,0,0,0,0};
int t27[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,64,71,72,80,96,0,112,80,112,0,0,0,0,0};
int t28[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,54,73,73,73,54,0,112,80,112,0,0,0,0,0};
int t29[] = {0,0,0,0,0,0,0,0,33,67,69,73,49,0,48,73,73,74,60,0,112,80,112,0,0,0,0,0};
int t30[] = {0,0,0,0,0,0,0,34,65,73,73,54,0,62,65,65,65,62,0,112,80,112,0,0,0,0,0};
int t31[] = {0,0,0,0,0,0,0,34,65,73,73,54,0,0,33,127,1,0,112,80,112,0,0,0,0,0};
int* caracts[] = {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31};

void setup()

{
   Serial.begin(9600);
   pinMode(latchpin, OUTPUT);
   pinMode(clockpin, OUTPUT);
   pinMode(datapin, OUTPUT);
}

void movealienfromleft(int duration)

{
  {
 
    for(i = 0;i <= 7;i++)
 
  {

    tempc = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
    tp = tempc;
    
   }

   int colbin=0;
   for (int xx=0; xx<=23; xx++)
   
   {
      for (int dd=0; ddfor (int q=0; q<5; q++)
         
         {
           colbin=(xx*1)+q;
           
           columndisplay(caracts[tp][colbin], q,0);
         }
      }
   }
}
}

void columndisplay(int coldata, int column, int holdtime)

{
   int matrixcolumn[5] = {
     1,2,4,8,16};
   digitalWrite(latchpin, LOW);
   shiftOut(datapin, clockpin, MSBFIRST, matrixcolumn[column]);
   shiftOut(datapin, clockpin, MSBFIRST, coldata);
   digitalWrite(latchpin, HIGH);
   delay(holdtime);
}


void loop()

{
   movealienfromleft(30);
   //Serial.print(tp,DEC);
}



------------------------------------------------------------------------------------------

Espero que seja útil e aguardo os comentários e sugestões, estou começando na programação com aduino e meu código certamente não deve estar na melhor forma.

As referências utilizadas foram:

http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/

http://tronixstuff.wordpress.com/2010/06/06/getting-started-with-arduino-%E2%80%93-chapter-nine/

Internet of Things

LUX com arduino GPRS shield e sensor LDR.

/*
Graph: Feed 38642, Datastream lux
*/

Laboratórios, Lojas e Produtos

Blogs, Comunidades e Revistas