Mudanças entre as edições de "O termômetro mais complicado do mundo"

De wiki da nuvem
Ir para: navegação, pesquisa
 
(4 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
  
−
Depois de meses passando frio na Nuvem, já era hora de entender se a sensação térmica era real, imaginária ou provocada pela umidade. Juntando algumas do jardim para epicuro (da cinthia) e da minha fonte para pescar satélites, fiz o termômetro que provavelmente é o mais desnecessariamente complicado. Ficou bonito.
+
Depois de meses passando frio na Nuvem, já era hora de entender se a sensação térmica era real, imaginária ou provocada pela umidade. Juntando algumas peças do jardim para epicuro (da cinthia) e da minha fonte para pescar satélites, fiz o termômetro que provavelmente é o mais desnecessariamente complicado. Ficou bonito.
  
 
[[Arquivo:termometro.jpg]]
 
[[Arquivo:termometro.jpg]]
Linha 8: Linha 8:
 
[[Arquivo:Circuito-termometro.jpg]]
 
[[Arquivo:Circuito-termometro.jpg]]
  
−
O sensor de temperatura LM35 dá a temperatura em Celsius, mas o arduino precisa de uma voltagem de referência para a entrada analógica. Por isso conectamos duas saídas do sensor. O arduino faz as contas e envia o número usando o protocolo serial do display oled. O programa de arduino está abaixo:
+
O sensor de temperatura LM35 dá a temperatura em Celsius, mas o arduino precisa de uma voltagem de referência para a entrada analógica. Por isso conectamos duas saídas do sensor. O arduino faz as contas e envia o número usando o protocolo serial do display oled.  
  
−
{
+
Aqui vão as datasheets dos componentes:
−
#include<stdlib.h>
 
  
−
#define LM35pin 2
 
−
#define LM35ref 1
 
  
−
long referencia;
+
* LM35 - [[Arquivo:Lm35.pdf]]
−
float v_alim, temp_c;
+
* Oled - protocolo serial [[Arquivo:GOLDELOX-SGC-COMMANDS-SIS-rev3.pdf ]]
−
byte data[20];
+
* Oled - pinout etc [[Arquivo:UOLED-160-G1SGC-DS-rev4.pdf]]
−
void setup() {
 
−
  // initialize serial communications at 9600 bps:
 
−
  Serial.begin(19200);
 
−
  delay(1000);
 
−
  Serial.write("U"); // send an U to the oled so it can fix the baud rate
 
−
  delay(100);
 
−
}
 
  
−
void loop() {
 
−
    delay(1000);
 
−
    Serial.write("E"); //clear screen
 
−
    delay(100);
 
  
−
    int analogVal = 0;
+
O programa de arduino está abaixo:
−
    for(int i = 0; i < 10; i++) { // read 10 times the sensor and calculates the average
 
−
      analogVal += (analogRead(LM35pin)-analogRead(LM35ref));
 
−
      delay(10);
 
−
    }
 
−
    temp_c = (5.0 * analogVal * 10) / 1023;
 
−
    char t[5];
 
−
    dtostrf(temp_c,2,1,t); //convert to string
 
−
    printSgc(t, 10,50,0,255,255,5,5); //send the string to the display
 
  
−
    //Serial.println(temp_c);
 
−
}
 
  
−
long readVcc() {
 
−
  long result;
 
−
  // Leemos la referencia de 1.1V contra AVcc
 
−
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
 
−
  delay(2); // Esperamos a que Vref se estabilize
 
−
  ADCSRA |= _BV(ADSC); // Convertimos
 
−
  while (bit_is_set(ADCSRA,ADSC));
 
−
  result = ADCL;
 
−
  result |= ADCH<<8;
 
−
  result = 1126400L / result; // Calculamos AVcc en mV
 
−
  return result;
 
−
}
 
  
−
boolean sendSerial(String text) {
+
    #include<stdlib.h>
−
  Serial.print(text);
+
    #define LM35pin 2
−
  delay(10);
+
    #define LM35ref 1
−
  int result = Serial.read();
+
    long referencia;
−
  if (result==6)
+
    float v_alim, temp_c;
−
    return true;
+
    byte data[20];
−
  else
+
    void setup() {
−
    return false;
+
      // initialize serial communications at 9600 bps:
−
}
+
      Serial.begin(19200);
−
 
+
      delay(1000);
−
boolean printSgc(char * text, int x, int y, int font, int color_1, int color_2, int w, int h) {
+
      Serial.write("U"); // send an U to the oled so it can fix the baud rate
−
+
      delay(100);
−
    Serial.write("S");
+
    }
−
    Serial.write(x);
+
    void loop() {
−
    Serial.write(y);
+
      delay(1000);
−
    Serial.write(font);
+
      Serial.write("E"); //clear screen
−
    Serial.write(color_1);
+
      delay(100);
−
    Serial.write(color_2);
+
      int analogVal = 0;
−
    Serial.write(w);
+
      for(int i = 0; i < 10; i++) { // read 10 times the sensor and calculates the average
−
    Serial.write(h);
+
        analogVal += (analogRead(LM35pin)-analogRead(LM35ref));
−
 
+
        delay(10);
−
    for (int i = 0; i< strlen(text); i++){  
+
      }
−
      Serial.write(text[i]);
+
      temp_c = (5.0 * analogVal * 10) / 1023;
 +
      char t[5];
 +
      dtostrf(temp_c,2,1,t); //convert to string
 +
      printSgc(t, 10,50,0,255,255,5,5); //send the string to the display
 +
      //Serial.println(temp_c);
 +
    }
 +
    boolean printSgc(char * text, int x, int y, int font, int color_1, int color_2, int w, int h) {
 +
      Serial.write("S");
 +
      Serial.write(x);
 +
      Serial.write(y);
 +
      Serial.write(font);
 +
      Serial.write(color_1);
 +
      Serial.write(color_2);
 +
      Serial.write(w);
 +
      Serial.write(h);
 +
      for (int i = 0; i< strlen(text); i++){  
 +
        Serial.write(text[i]);
 +
      }
 +
      Serial.write(0,1);
 +
      delay(10);
 +
      int result = Serial.read();
 +
      if (result==6)
 +
        return true;
 +
      else
 +
        return false;
 +
      }
 
     }
 
     }
−
    Serial.write(0,1);
 
−
  delay(10);
 
−
  int result = Serial.read();
 
−
  if (result==6)
 
−
    return true;
 
−
  else
 
−
    return false;
 
−
}
 
−
}
 

Edição atual tal como às 11h24min de 14 de fevereiro de 2012

Depois de meses passando frio na Nuvem, já era hora de entender se a sensação térmica era real, imaginária ou provocada pela umidade. Juntando algumas peças do jardim para epicuro (da cinthia) e da minha fonte para pescar satélites, fiz o termômetro que provavelmente é o mais desnecessariamente complicado. Ficou bonito.

Termometro.jpg

Aqui vai o esquema de funcionamento do circuito. Um 7805 regula a voltagem do transformador em 5v, o que alimenta o arduino, sensor e tela oled. O regulador de voltagem do arduino também dá 5v mas a corrente que ele fornece era insuficiente para a tela.

Circuito-termometro.jpg

O sensor de temperatura LM35 dá a temperatura em Celsius, mas o arduino precisa de uma voltagem de referência para a entrada analógica. Por isso conectamos duas saídas do sensor. O arduino faz as contas e envia o número usando o protocolo serial do display oled.

Aqui vão as datasheets dos componentes:



O programa de arduino está abaixo:


   #include<stdlib.h>
   #define LM35pin 2
   #define LM35ref 1
   long referencia;
   float v_alim, temp_c;
   byte data[20];
   void setup() {
     // initialize serial communications at 9600 bps:
     Serial.begin(19200); 
     delay(1000);
     Serial.write("U"); // send an U to the oled so it can fix the baud rate
     delay(100);
   }
   void loop() {
     delay(1000);
     Serial.write("E"); //clear screen
     delay(100);
     int analogVal = 0;
     for(int i = 0; i < 10; i++) { // read 10 times the sensor and calculates the average
       analogVal += (analogRead(LM35pin)-analogRead(LM35ref));
       delay(10);
     }
     temp_c = (5.0 * analogVal * 10) / 1023;
     char t[5];
     dtostrf(temp_c,2,1,t); //convert to string
     printSgc(t, 10,50,0,255,255,5,5); //send the string to the display
     //Serial.println(temp_c);
   }
   boolean printSgc(char * text, int x, int y, int font, int color_1, int color_2, int w, int h) {
     Serial.write("S");
     Serial.write(x);
     Serial.write(y);
     Serial.write(font);
     Serial.write(color_1);
     Serial.write(color_2);
     Serial.write(w);
     Serial.write(h);
     for (int i = 0; i< strlen(text); i++){ 
       Serial.write(text[i]);
     }
     Serial.write(0,1);
     delay(10);
     int result = Serial.read();
     if (result==6)
       return true;
     else
       return false;
     }
   }