Advertisement
Jorge_moises

Termostato com Lm35

Apr 19th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <LiquidCrystal595.h>
  2. LiquidCrystal595 lcd (2,3,4);
  3.  
  4. int Temp, valor, LM35; // Variaveis para LM35 - Temperatura, gravar valor e porta A0 LM35
  5. int Pot = A2, ValorPot = 0, ValorBinario = 0; // Variaveis para o potenciometro
  6. byte led = 9;
  7.  
  8. unsigned long Tempo, Tempo2; // Controle de tempo
  9.  
  10. void setup(){
  11.   lcd.begin (16,2);
  12.   pinMode (led, OUTPUT); // Define led como saida
  13. }
  14.  
  15. void loop(){
  16.  if ((millis() - Tempo) > 3000){
  17.   sensor();
  18.  Tempo = millis();
  19.  }  
  20.  if ((millis() - Tempo2) > 50){
  21.    Potenciometro();
  22.    Tempo2 = millis();
  23.  }
  24. }
  25.  
  26. void sensor(){
  27.   valor = analogRead(LM35);
  28.   Temp= ( 5 * valor * 100) / 1024;
  29.   lcd.setCursor (0,0);
  30.   lcd.print ("Sensor: ");
  31.   lcd.print(Temp) ;
  32.   lcd.print((char)223); // Ponto de graus
  33.   lcd.print ("C");
  34. }
  35. void Potenciometro(){
  36.   valor = analogRead(LM35);
  37.   Temp= ( 5 * valor * 100) / 1024;
  38.  
  39.   ValorPot = analogRead (Pot);
  40.   ValorBinario = map(ValorPot, 0, 1023, 0 , 41);
  41.   lcd.setCursor (0,1);
  42.   lcd.print ("Pot: ");
  43.   lcd.print (ValorBinario); // imprime o valor do pot de 0 a 40
  44.  
  45.   if (valor > ValorPot){
  46.     digitalWrite (led, HIGH);
  47.   }
  48.   else {
  49.     digitalWrite (led, LOW);
  50.   }
  51.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement