Skip to content
gerrykoun edited this page Oct 1, 2015 · 17 revisions
DESCRIPTION

The DS18B20 is a digital thermometer that communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of -55°C to +125°C and is accurate to ±0.5°C over the range of -10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”). This makes it great for use as an external sensor.

The DS18B20 can be powered between 3.0V and 5.5V. Connect both the GND and VDD pins to 0V. Then connect the DQ pin to pin 2 on the Arduino board (or any digital pin of the Arduino board). Connect a 4K7 ohm pullup resistor between DQ pin and +5 V.

     The DS1820 Sensor  

Dallas Temperature Sensor;

                                         Sensor setup on the breadboard

Code

 #include <OneWire.h> // κανουμε include τη βιβλιοθηκη Onewire 
 #include <DallasTemperature.h> // κανουμε include τη βιβλιοθηκη DallasTemperature 
 
 // Ο ακροδέκτης για τα δεδομένα ειναι συνδεδεμένο στο pin2 
 #define ONE_WIRE_BUS 2 
 
 // Setup a oneWire instance to communicate with any OneWire devices  
 // (not just Maxim/Dallas temperature ICs) 
 OneWire oneWire(ONE_WIRE_BUS); 
 
 // Pass our oneWire reference to Dallas Temperature. 
 DallasTemperature sensors(&oneWire); 
 
 void setup(void) 
 { 
   // start serial port 
   Serial.begin(9600); 
   Serial.println("Dallas Temperature IC Control Library Demo"); 

   // Start up the library 
   sensors.begin(); 
 } 
 
 
 void loop(void) 
 { 
   // call sensors.requestTemperatures() to issue a global temperature 
   // request to all devices on the bus 
   Serial.print(" Requesting temperatures..."); 
   sensors.requestTemperatures(); // Send the command to get temperatures 
   Serial.println("DONE"); 

   Serial.print("Temperature for Device 1 is: "); 
   Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?  
     // You can have more than one IC on the same bus.  
     // 0 refers to the first IC on the wire 
 } 

But we don't want our scale to weight without stop and also we don't want our battery charge off in one day. So we will use atmega's Sleeping modes to reduse the power consumption. In that case we gona use _LowPower.h _library. The maximum time that can use sleeping mode is 8s. For example if we want to take one measurement per minute, one minute is 60 sec / 8 s = 7.5, so if you tell him to take one measurement per 8 times that awakens, then we will have a measure per 1 minute. The following code puts in sleeping mode the arduino and measure one time per minute the temperature.

 #include <OneWire.h> 
 #include <DallasTemperature.h> 
 #include <LowPower.h> // include LowPower library 
 // Data wire is plugged into pin 2 on the Arduino 
 #define ONE_WIRE_BUS 2 
 // Setup a oneWire instance to communicate with any OneWire devices  
 // (not just Maxim/Dallas temperature ICs) 
 OneWire oneWire(ONE_WIRE_BUS); 
 
 // Pass our oneWire reference to Dallas Temperature. 
 DallasTemperature sensors(&oneWire); 
  int wait=1;// μεταβλητή για να μετράει πόσες φορές ξυπνάει απο sleeping mode 
 void setup(void) 
 { 
   // start serial port 
   Serial.begin(9600); 
   Serial.println("Dallas Temperature IC Control Library Demo"); 
   // Start up the library 
   sensors.begin(); 
 } 
 
 void loop(void) { 
 Serial.print("wait =");// debugging 
 Serial.println(wait); //debugging 
   if(wait>=8){ 
      // call sensors.requestTemperatures() to issue a global temperature 
   // request to all devices on the bus 
   Serial.print(" Requesting temperatures..."); 
   sensors.requestTemperatures(); // Send the command to get temperatures 
   Serial.println("DONE"); 
   Serial.print("Temperature for Device 1 is: "); 
   Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?  
     // You can have more than one IC on the same bus.  
     // 0 refers to the first IC on the wire 
     wait=0;// αρχικοποιεί την μεταβλητή wait 
     }             
     delay(100); 
   LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);       
   wait++;// αυξάνει κατα 1 την μεταβλητή wait 
 }

Περιεχόμενα / Contents

  • [English] (Home)

    • [Βuild your own beescale](Βuild your own beescale)
    • [Humidity Sensor](Humidity Sensor)
    • [Load cell sensor](Load cell sensor)
    • [Temperature Sensor](Temperature Sensor)
    • [Why is made for](Why is made for)
    • [Further Development](Further Development)
  • Eλληνικά

    • [Κατασκεύασε το δικό σου beescale](Κατασκεύασε το δικό σου beescale)
    • [Αισθητήρας Υγρασίας](Αισθητήρας Υγρασίας)
    • [Aισθητήρας Θερμοκρασίας](Αισθητήρας Θερμοκρασίας)
    • [Αισθητήρας βάρους](Αισθητήρας βάρους)
    • [Σκοπός χρήσης](Σκοπός χρήσης)
    • [Προτεινόμενες Βελτιώσεις](Προτεινόμενες Βελτιώσεις)
  • Παράρτημα

Clone this wiki locally