Mudanças entre as edições de "O termômetro mais complicado do mundo"
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: | ||
+ | |||
+ | * 7805 | ||
+ | * LM35 | ||
+ | * Oled - protocolo serial | ||
+ | |||
+ | |||
+ | O programa de arduino está abaixo: | ||
Linha 25: | Linha 34: | ||
delay(100); | delay(100); | ||
} | } | ||
− | |||
− | |||
void loop() { | 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); | ||
+ | } | ||
+ | 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) { | ||
+ | Serial.print(text); | ||
+ | delay(10); | ||
+ | int result = Serial.read(); | ||
+ | if (result==6) | ||
+ | return true; | ||
+ | else | ||
+ | return false; | ||
+ | } | ||
+ | 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); | delay(10); | ||
+ | int result = Serial.read(); | ||
+ | if (result==6) | ||
+ | return true; | ||
+ | else | ||
+ | return false; | ||
+ | } | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Edição das 02h45min 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 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.
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.
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:
- 7805
- LM35
- Oled - protocolo serial
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); } 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) { Serial.print(text); delay(10); int result = Serial.read(); if (result==6) return true; else return false; } 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; } }