Introdução ao Arduino ESCOLA DE ARTES VISUAIS DO PARQUE LAGE Núcleo de Arte e Tecnologia julio lucio martin Aula 07
O que vamos entender? sensor temperatura LM35
No datasheet do sensor vemos a gráfica da temperatura com a voltagem.
De aqui podemos deduzir a seguinte fórmula: Temp em C = ( Volt in mv - 500 ) / 10
Também sabemos que : 1 V = 1000 mv
E sabemos que quando lemos da porta analógica com analogread obtemos valores de 1023 que significa que estamos lendo 5 volts, porém podemos mapear os valores do sensor a mili-voltios: int voltagem_mv = map( sensor, 0, 1023, 0, 5000 ); int temp = ( voltagem_mv - 500 ) / 10;
1: Medindo a temperatura e mostrando no terminal Serial
materiais Arduino LM35 temperatura sensor
montagem
código void setup(){ Serial.begin(9600); } void loop() { int sensor = analogread( A0 ); int millivolts = map( sensor, 0, 1023, 0, 5000 ); int temperatura = ( millivolts - 500 ) / 10; } Serial.print( "Valor do sensor = "); Serial.println( sensor ); Serial.print( "Voltagem em millivolts = "); Serial.println( millivolts ); Serial.print( "Temperatura = "); Serial.println( temperatura ); delay( 200 );
2: termômetro v1.0 medindo a temperatura e mostrando em três LEDs:
O primeiro liga para temperaturas menores que temperatura 1. t <= t1 O segundo para maiores que temperatura 1 e menores que temperatura 2. t > t1 && t <= t2 O terceiro para maiores de temperature 2. t > t2
materiais Arduino LED x 3 resistor 200 ohm x 3 Sensor LM35
esquema
montagem
código int pinled01 = 6; int pinled02 = 7; int pinled03 = 8; int temp01 = 25; int temp02 = 30; int temp03 = 35; void setup(){ Serial.begin(9600); pinmode( pinled01, OUTPUT ); pinmode( pinled02, OUTPUT ); pinmode( pinled03, OUTPUT ); } void loop() { int sensor = analogread( A0 ); int millivolts = map( sensor, 0, 1023, 0, 5000 ); int temperatura = ( millivolts - 500 ) / 10; Serial.print( "Sensor = " ); Serial.println( sensor ); Serial.print( "Tem = " ); Serial.println( temperatura ); digitalwrite( pinled01, LOW ); digitalwrite( pinled02, LOW ); digitalwrite( pinled03, LOW ); if( temperatura < temp01 ) digitalwrite( pinled01, HIGH ); if( temperatura >= temp01 && temperatura < temp02 ) digitalwrite( pinled02, HIGH ); } if( temperatura >= temp02 ) digitalwrite( pinled03, HIGH );
3: termômetro v2.0 Adicionando sirena si for maior que temperatura 3.
materiais Arduino LED x 3 resistor 200 ohm x 3 Sensor LM35 piezelétrico
esquema
montagem
código int pinled01 = 6; int pinled02 = 7; int pinled03 = 8; int temp01 = 25; int temp02 = 30; int temp03 = 35; int temp04 = 35; void setup(){ Serial.begin(9600); pinmode( pinled01, OUTPUT ); pinmode( pinled02, OUTPUT ); pinmode( pinled03, OUTPUT ); } void loop() { int sensor = analogread( A0 ); int millivolts = map( sensor, 0, 1023, 0, 5000 ); int temperatura = ( millivolts - 500 ) / 10; Serial.print( "Sensor = " ); Serial.println( sensor ); Serial.print( "Tem = " ); Serial.println( temperatura ); digitalwrite( pinled01, LOW ); digitalwrite( pinled02, LOW ); digitalwrite( pinled03, LOW ); if( temperatura < temp01 ) digitalwrite( pinled01, HIGH ); if( temperatura >= temp01 && temperatura < temp02 ) digitalwrite( pinled02, HIGH ); if( temperatura >= temp02 ) digitalwrite( pinled03, HIGH ); } if( temperatura >= temp03 ){ tone( 9, 600, 200 ); delay( 200 ); tone( 9, 300, 200 ); delay( 200 ); }
O que vamos entender? Atuador LCD Display
O que vamos entender? Atuador LCD DISPLAY
O que vamos aprender? programação Vamos a aprender usar a biblioteca LiquidCristal http://www.arduino.cc/en/reference/liquidcrystal
biblioteca LiquidCrystal Primeiro incluímos a biblioteca de para tela de cristal liquido #include <LiquidCrystal.h>
biblioteca LiquidCrystal Depois criamos uma variável do tipo LiquidCrystal indicando os pinos onde esta ligada. LiquidCrystal tela(12, 11, 5, 4, 3, 2);
biblioteca LiquidCrystal LiquidCrystal tela(12, 11, 5, 4, 3, 2);
biblioteca LiquidCrystal Depois dentro do setup inicializamos a tela com o tamanho em caracteres que ela tem usando a mensagem begin lcd.begin(16, 2); Neste caso indicamos que a tela que estamos usando tem 16 caracteres por linha e 2 linhas de caracteres. 16x2
biblioteca LiquidCrystal Usamos a mesagem clear para apagar caracteres da tela lcd.clear();
biblioteca LiquidCrystal Posicionamos o cursor num posição X, Y d tela usando a mensagem setcursor. lcd.setcursor(x, y);
biblioteca LiquidCrystal Imprimimos na tela na posição que o cursor foi colocado anteriormente com a mensagem print. lcd.print( Temp = ); lcd.print( temperatura );
4: termômetro v3.0 medindo a temperatura e mostrando na tela LCD com sinais sonoros.
montagem
código #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int pinluz = 7; int pinspeaker = 9; int temperaturaanterior; void setup(){ lcd.begin(16, 2); pinmode( pinluz, OUTPUT ); digitalwrite( pinluz, HIGH ); } void loop() { int sensor = analogread( A0 ); int millivolts = map( sensor, 0, 1023, 0, 5000 ); int temperatura = ( millivolts - 500 ) / 10; lcd.clear(); lcd.setcursor(0, 0); lcd.print( "Volt = " ); lcd.setcursor(7, 0); lcd.print( sensor ); lcd.setcursor(14, 0); lcd.print( "mv" ); lcd.setcursor(0, 1); lcd.print( "Temp = " ); lcd.setcursor(7, 1); lcd.print( temperatura ); lcd.setcursor(15, 1); lcd.print( "C" ); } if( temperatura > temperaturaanterior ) tone( pinspeaker, 600, 200 ); delay( 200 ); if( temperatura < temperaturaanterior ) tone( pinspeaker, 300, 200 ); delay( 200 ); } temperaturaanterior = temperatura;