SHARE
TWEET

Untitled

a guest Apr 14th, 2017 121 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Inkubator for Arduino by SwojskaZagroda.pl
  2.  
  3. // LCD TERMOMETR
  4.     // blog.bauerpawel.eu
  5.  
  6.     #include <OneWire.h>
  7.     #include <LiquidCrystal.h>
  8.  
  9.     // Connections:
  10.     // rs (LCD pin 4) to Arduino pin 12
  11.     // rw (LCD pin 5) to Arduino pin 11
  12.     // enable (LCD pin 6) to Arduino pin 10
  13.     // LCD pin 15 to Arduino pin 13
  14.     // LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
  15.     LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  16.     OneWire  ds(8);        // ds18b20 pin #2 (middle pin) to Arduino pin 8
  17.    
  18.    
  19.     byte i;
  20.     byte present = 0;
  21.     byte type_s;
  22.     byte data[12];
  23.     byte addr[8];
  24.     float celsius, fahrenheit;
  25.     int przekaznikPin = 7;
  26.     int buzzerPin = 9;
  27.    
  28.     //alarm
  29.     float ostatniPomiar = 0;
  30.     int odliczanie = 50;
  31.    
  32.    
  33.     float docelowaTemperatura = 38;
  34.     float temperaturaZaNiska = 34;
  35.     float temperaturaZaWysoka = 39.5;
  36.    
  37.    
  38.    
  39.     void setup(void) {
  40.       pinMode(przekaznikPin, OUTPUT);  
  41.       lcd.begin(16, 2);
  42.     }
  43.    
  44.  
  45.      
  46.   int HighByte, LowByte, SignBit, Whole, Fract, TReading, Tc_100, FWhole;
  47.    
  48.  
  49. ///////
  50.  
  51. void loop(void) {
  52.  
  53.  
  54.   if ( !ds.search(addr)) {
  55.     ds.reset_search();
  56.     delay(250);
  57.     return;
  58.   }
  59.  
  60.   if (OneWire::crc8(addr, 7) != addr[7]) {
  61.  
  62.       return;
  63.   }
  64.  
  65.  
  66.   // the first ROM byte indicates which chip
  67.   switch (addr[0]) {
  68.     case 0x10:
  69.  
  70.       type_s = 1;
  71.       break;
  72.     case 0x28:
  73.  
  74.       type_s = 0;
  75.       break;
  76.     case 0x22:
  77.  
  78.       type_s = 0;
  79.       break;
  80.     default:
  81.  
  82.       return;
  83.   }
  84.  
  85.   ds.reset();
  86.   ds.select(addr);
  87.   ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  88.  
  89.   delay(1000);     // maybe 750ms is enough, maybe not
  90.   // we might do a ds.depower() here, but the reset will take care of it.
  91.  
  92.   present = ds.reset();
  93.   ds.select(addr);    
  94.   ds.write(0xBE);         // Read Scratchpad
  95.  
  96.  
  97.   for ( i = 0; i < 9; i++) {           // we need 9 bytes
  98.     data[i] = ds.read();
  99.  
  100.   }
  101.  
  102.  
  103.   // Convert the data to actual temperature
  104.   // because the result is a 16 bit signed integer, it should
  105.   // be stored to an "int16_t" type, which is always 16 bits
  106.   // even when compiled on a 32 bit processor.
  107.   int16_t raw = (data[1] << 8) | data[0];
  108.   if (type_s) {
  109.     raw = raw << 3; // 9 bit resolution default
  110.     if (data[7] == 0x10) {
  111.       // "count remain" gives full 12 bit resolution
  112.       raw = (raw & 0xFFF0) + 12 - data[6];
  113.     }
  114.   } else {
  115.     byte cfg = (data[4] & 0x60);
  116.     // at lower res, the low bits are undefined, so let's zero them
  117.     if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
  118.     else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
  119.     else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
  120.     //// default is 12 bit resolution, 750 ms conversion time
  121.   }
  122.   celsius = (float)raw / 16.0;
  123.   fahrenheit = celsius * 1.8 + 32.0;
  124.       lcd.clear();
  125.       lcd.setCursor(0,0);
  126.       lcd.print("Temp: ");
  127.      
  128.       if (SignBit) {
  129.          lcd.print("-");
  130.       }
  131.       lcd.print(celsius);
  132.       lcd.print(" C ");
  133.      
  134.      
  135.       lcd.setCursor(0,1);
  136.      
  137.      
  138.       if(celsius <= docelowaTemperatura){
  139.        
  140.         lcd.print("Grzeje!");
  141.         // wlaczamy grzanie
  142.         digitalWrite(przekaznikPin, true);
  143.       }
  144.       else{
  145.         lcd.print("NIE grzeje!");
  146.         //wylaczamy grzanie
  147.         digitalWrite(przekaznikPin, false);
  148.       }
  149.      
  150.      
  151.      
  152.      
  153.       if(celsius >= temperaturaZaWysoka){
  154.         digitalWrite(buzzerPin, true);
  155.       }else{
  156.         digitalWrite(buzzerPin, false);
  157.       }
  158.      
  159.      
  160.      
  161.      
  162.       //odliczanie
  163.       if(odliczanie > 0){
  164.         lcd.setCursor(14,1);
  165.         odliczanie = odliczanie - 1;
  166.         lcd.print(odliczanie);
  167.       }
  168.       else if(celsius <= temperaturaZaNiska){
  169.         digitalWrite(buzzerPin, true);
  170.       }else{
  171.         digitalWrite(buzzerPin, false);
  172.       }
  173.      
  174.       ostatniPomiar = celsius;
  175.       delay(5000);  //Czeka 5 sekund i odswierza
  176. }
  177.  
  178. /////
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top