Se afișează postările cu eticheta MAX31820. Afișați toate postările
Se afișează postările cu eticheta MAX31820. Afișați toate postările

miercuri, 19 martie 2014

Indicator date mediu pentru masina

   Cand ne aflam in masina, este util sa stim ce temperatura este afara, cat este tenmperatura si ce umiditate este in masina, tensiunea bateriei, asa ca m-am gandit sa vizualizez datele pe un afisaj LCD cu 16 coloane si 2 randuri, sub forma:
   Pentru exterior m-am gandit la un senzor DS18B20 in carcasa protejata, ceva de genul:
deoarece domeniul de masura este -55..+1250C, arhisuficient in zona noastra.
   Pentru interior, m-am gandit la senzorul DHT11, mai putin precis care masoara temperatura in domeniul 0..+500C, cu eroare de +20C, iar umiditate in domeniul 20..90%, cu eroare de +5%.
   Deoarece nu cred ca as putea sofa sau sta intr-o masina in care temperatura e sub zero grade, o sa pun sa apara cu intermitenta un simbol de temperatura scazuta, eventual o sa apelez la un alt senzor DS18B20, de exemplu.
   Pentru a masura tensiunea bateriei o sa folosesc un divizor rezistiv, care sa poata masura pana la cca. 20V (acoperitor pentru tensiunile de pe masina):
   Eu am prezentat senzorul de temperatura DS18B20 (si verisorul lui MAX31820) in mai multe articole:

   De asemenea, senzorul de temperatura si umiditate DHT11 l-am prezentat in mai multe articole, dar cel mai bine vedeti informatiile de la Ministatie meteo cu senzorul DHT11 si.. Arduino.
   Partea de voltmetru o gasiti in articolele:
   Pentru a fi montat pe masina, o sa fac trecerea pe un cablaj indpendent cu un microcontroler ATmega328P-PU programat ca Arduino sau voi folosi un Arduino Pro Mini, cum am prezentat in articolul Transferarea unui proiect Arduino pe un cablaj
sau 
20.3.2014
   O schema de conectare ar putea fi:

   Dupa cum se observa, pentru primele teste o sa folosesc:
- o placa de dezvoltare Arduino;
- un regulator de tensiune pentru 5V,pentru alimentarea placii Arduino, afisajului si senzorilor;
- un senzor de temperatura DS18B20, pentru exterior;
- un senzor DHT11 pentru temperatura si umiditatea din interior;
- un divizorul rezistiv, pentru a putea masura tensiunea de pe baterie

21.03.2014
   Am realizat ca nu am nevoie de stabilizator, ca are placa Arduino, asa ca schema se simplifica:

luni, 10 februarie 2014

Mai multi senzori de tip DS18B20 (sau MAX31820) in paralel (2)

   In articolul anterior, Mai multi senzori de tip DS18B20 (sau MAX31820) in paralel, am conectat 3 senzori din familia DS18x20 (unul DS18B20 si 2 de tipul MAX31820), acum ca am primit inca 2 monstre de tipul DS18B20 de la Dallas Semiconductor (Maxim Integrated), cum primisem, in ianuarie, si pe cei 2 senzori MAX31820, am zis ca pot citi temperatura in 5 puncte.
 
   Schema de conectare a senzprilor este identica, toti 5 vor fi in paralel:
iar prezentarea datelor am facut-o pe un afisaj LCD alfanumeric cu 16 coloane si 2 randuri (1602 sau 16x2):
   Montajul arata asa:
   Am adaptat sketch-ul folosit in articolul Mai multi senzori de tip DS18B20 (sau MAX31820) in paralel combinandu-l cu cel din articolul Interfata i2c la LCD pentru Arduino:
// full sketch by niq_ro from http://nicuflorica.blogspot.com
// or http://www.tehnic.go.ro
// or http://arduinotehniq.blogspot.com/

#include <Wire.h> // for i2c protocol

#include <OneWire.h>
// http://www.pjrc.com/teensy/td_libs_OneWire.html
// http://milesburton.com/Dallas_Temperature_Control_Library
OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)  

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adresss for LCC 16x2

byte grad[8] = {
  B01110,
  B10001,
  B10001,
  B01110,
  B00000,
  B00000,
  B00000,
};

int ics =0; //count number of sensor

void setup(){
  lcd.init(); 
  lcd.backlight(); //backlight is now ON
  // set up the LCD's number of columns and rows: 
  lcd.createChar(0, grad);
  lcd.begin(16, 2);
  // Print a logo message to the LCD.
  lcd.print("www.tehnic.go.ro");  
  lcd.setCursor(0, 1);
  lcd.print("creat de niq_ro");
  delay (2500);
  lcd.clear();
   
  // Print a message to the LCD.
  lcd.setCursor(1, 0);
  lcd.print("temperatura in");
  lcd.setCursor(1, 1);
  lcd.print("mai multe zone");
  delay (2500);
  lcd.clear();
}



void loop(){
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius;
  
  
  if ( !ds.search(addr)) {
    lcd.clear();   
    lcd.setCursor(0, 1);
    lcd.print("doar ");
    lcd.print(ics);
    lcd.print(" senzor(i)");    
    ds.reset_search();
    ics=0;
    return;
  }
  
ics++; 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }
  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }

lcd.clear();
lcd.setCursor(0, 1);
  lcd.print("ROM=");
  for( i = 0; i < 8; i++) {
    lcd.print(' ');
    lcd.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      lcd.print("CRC is not valid!");
      return;
  }

  celsius = (float)raw / 16.0;

  lcd.setCursor(0,0);
  lcd.print("Temp");
  lcd.print(ics);
  lcd.print(" = ");
  lcd.print(celsius);
  lcd.write(byte(0));
  lcd.print("C   ");
  
  delay(3000);
}
   Am facut si 2 filmulete:
masurare temperatura in mai multe puncte cu DS18B20 si MAX31820 folosind Arduino si LCD1602 cu i2c
multipoint thermometer with DS18B20 and MAX31820, Arduino and LCD1602 with i2c interface
11.02.2014
   Am desenat schema completa de conectare a senzorilor din familia DS18x20 (DS18B20, DS18S20, DS1822, MAX31820) si a afisajului LCD 1602 cu interfata i2c:

sâmbătă, 11 ianuarie 2014

Mai multi senzori de tip DS18B20 (sau MAX31820) in paralel

   In articolul anterior, Noii senzori de temperatura MAX31820 fata de "clasicii" DS18B20, am conectat in paralel un senzor DS18B20 (cu precize garantata de +0,50pe domeniul de la -10 la +850C, in rest e de +20C) si 2 de tipul MAX31820 (care este o varianta noua, cu precize garantata de +0,50doar pe un domeniu de +10...+450 Celsius, in rest e de +20C).
   Schema de conectare este simpla:
   Deoarece sunt din aceeasi clasa, ele sunt indentificate de Arduino ca fiind DS18B20.
   In articolul  Arduino 1-Wire Address Finder este prezentat un sketch, care gaseste adresele tuturor senzorilor pe comunicatia 1-Wire. L-am incarcat si eu si am obtinut:
   Sketch-ul, in care doar am pus pinul de date la 10, cum aveam eu facut, este:
// This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial: 
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#include <OneWire.h>

OneWire  ds(10);  // Connect your 1-wire device to pin 10

void setup(void) {
  Serial.begin(9600);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i], HEX);
      if (i < 7) {
        Serial.print(", ");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

void loop(void) {
  // nothing to see here
}
   Deoarece trebuie sa le identific cumva, m-am inspirat din articolul Two DS18B20 Temp Sensors on LCD Display! in care apare si o librarie numita DallasTemperature Arduino Library, care se gaseste tot in articolul mentionat la inceput, Arduino 1-Wire Address Finder.
   Dupa descarcarea librariei, dezarhivarea si mutarea in subdirectorul de librarii al programului Arduino, am ales exemplul numit Multiple:
si l-am modificat pentru cazul meu, cu 3 senzori, in dreapta e DS18B20, iar ceilalti 2 senzori MAX31820 sunt in mijloc, respectiv stanga.
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 10 on the Arduino
#define ONE_WIRE_BUS 10
#define TEMPERATURE_PRECISION 12

// 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);

// arrays to hold device addresses
DeviceAddress rightThermometer, midleThermometer, leftThermometer;

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();

  // locate devices on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either oneWire.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
  //outsideThermometer   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };

  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then 
  // use those addresses and manually assign them (see above) once you know 
  // the devices on your bus (and assuming they don't change).
  // 
  // method 1: by index
  if (!sensors.getAddress(rightThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  if (!sensors.getAddress(midleThermometer, 1)) Serial.println("Unable to find address for Device 1"); 
  if (!sensors.getAddress(leftThermometer, 2)) Serial.println("Unable to find address for Device 2"); 
  
  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices, 
  // or you have already retrieved all of them.  It might be a good idea to 
  // check the CRC to make sure you didn't get garbage.  The order is 
  // deterministic. You will always get the same devices in the same order
  //
  // Must be called before search()
  //oneWire.reset_search();
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
  // assigns the seconds address found to outsideThermometer
  //if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(rightThermometer);
  Serial.println();

  Serial.print("Device 1 Address: ");
  printAddress(midleThermometer);
  Serial.println();

  Serial.print("Device 2 Address: ");
  printAddress(leftThermometer);
  Serial.println();


  // set the resolution to 9..12 bit
  sensors.setResolution(rightThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(midleThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(leftThermometer, TEMPERATURE_PRECISION);

  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(rightThermometer), DEC); 
  Serial.println();

  Serial.print("Device 1 Resolution: ");
  Serial.print(sensors.getResolution(midleThermometer), DEC); 
  Serial.println();
  
  Serial.print("Device 2 Resolution: ");
  Serial.print(sensors.getResolution(leftThermometer), DEC); 
  Serial.println();
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.print(DallasTemperature::toFahrenheit(tempC));
}

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
  Serial.print("Resolution: ");
  Serial.print(sensors.getResolution(deviceAddress));
  Serial.println();    
}

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address: ");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}

void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");

  // print the device information
  printData(rightThermometer);
  printData(midleThermometer);
  printData(leftThermometer);
  delay(3000);
  
}
   Pe ecranul de monitorizare seriala am acum datele:
 
cu minime modificari: 
 

12.ian.2014
   M-a gandit sa nu las neterminata treaba, asa ca m-am mai jucat cu sketch-ul si pe ecram am obtinut:

iar sketch-ul folosit este:
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 10 on the Arduino
#define ONE_WIRE_BUS 10
#define TEMPERATURE_PRECISION 12

// 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);

// arrays to hold device addresses
DeviceAddress rightThermometer, midleThermometer, leftThermometer;


void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library use by niq_ro");
  Serial.println("---------------------------------------------------");

  // Start up the library
  sensors.begin();
  DeviceAddress rightThermometer = { 0x28, 0xAC, 0x7A, 0xD4, 0x4, 0x0, 0x0, 0x7E };
  DeviceAddress midleThermometer = { 0x28, 0xF5, 0xFB, 0x58, 0x5, 0x0, 0x0, 0xA0 };
  DeviceAddress leftThermometer = { 0x28, 0xCB, 0xF0, 0x58, 0x5, 0x0, 0x0, 0x2E };


  // method 1: by index
  if (!sensors.getAddress(rightThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  if (!sensors.getAddress(midleThermometer, 1)) Serial.println("Unable to find address for Device 1"); 
  if (!sensors.getAddress(leftThermometer, 2)) Serial.println("Unable to find address for Device 2"); 


  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(rightThermometer);
  Serial.println();

  Serial.print("Device 1 Address: ");
  printAddress(midleThermometer);
  Serial.println();

  Serial.print("Device 2 Address: ");
  printAddress(leftThermometer);
  Serial.println();


  // set the resolution to 9..12 bit
  sensors.setResolution(rightThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(midleThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(leftThermometer, TEMPERATURE_PRECISION);

/*
  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(rightThermometer), DEC); 
  Serial.println();

  Serial.print("Device 1 Resolution: ");
  Serial.print(sensors.getResolution(midleThermometer), DEC); 
  Serial.println();
  
  Serial.print("Device 2 Resolution: ");
  Serial.print(sensors.getResolution(leftThermometer), DEC); 
  Serial.println();
*/
}


// function to print a device address
void printAddress(DeviceAddress device)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    if (device[i] < 16) Serial.print("0");
    Serial.print(device[i], HEX);
  }
    Serial.println(" - ");
}

// function to print the temperature for a device
void printTemperature(DeviceAddress device)
{
  float tempC = sensors.getTempC(device);
  Serial.print("Temp C: ");
  if (tempC == -127.00) {
  Serial.print("Error");
} else {
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
// function to print a device's resolution
void printResolution(DeviceAddress device)
{
  Serial.print("Resolution: ");
  Serial.print(sensors.getResolution(device));
  Serial.println();    
}

// main function to print information about a device
void printData(DeviceAddress device)
{
  Serial.print("Address: ");
  printAddress(device);
  Serial.print(" ");
  printTemperature(device);
  Serial.println();
}

void loop(void)
{ 
  DeviceAddress rightThermometer = { 0x28, 0xAC, 0x7A, 0xD4, 0x4, 0x0, 0x0, 0x7E };
  DeviceAddress midleThermometer = { 0x28, 0xF5, 0xFB, 0x58, 0x5, 0x0, 0x0, 0xA0 };
  DeviceAddress leftThermometer = { 0x28, 0xCB, 0xF0, 0x58, 0x5, 0x0, 0x0, 0x2E };

   // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.println("---------------------------------------");
  Serial.println(" ");
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");
  Serial.println("---------------------------------------");
  Serial.println(" ");

  // print the device information
  Serial.print("Device DS18B20 (right) ");
  printData(rightThermometer);
  Serial.println("---------------------------------------");
  Serial.print("Device MAX31820 (center) ");
  printData(midleThermometer);
  Serial.println("---------------------------------------");
  Serial.print("Device MAX31820 (left) ");
  printData(leftThermometer);
  Serial.println("---------------------------------------");
  delay(3000);
}

17.01.2014
PS: Dupa cum am mentionat si la finalul articolului anterior (Noii senzori de temperatura MAX31820 fata de "clasicii" DS18B20), in datasheet-ul senzorilor MAX31820, se mentioneaza ca tensiunea de alimentare normala este intre 3 si 3,7V deci ar functiona perfect cu microcontroler-e alimentate la tensiunea de 3,3V. Tot in datasheet se mentioneaza ca tensiunea maxima admisa este de 6V, exact ca la DS18B20... Eu le-am alimentat la 5V, cat era la Arduino si au mers perfect.

Noii senzori de temperatura MAX31820 fata de "clasicii" DS18B20

  Cautand la Maxim Integrated pe site, am descoperit un senzor nou, MAX31820, care are fisa de catalog (datasheet) si ca prezentare "1-Wire Ambient Temperature Sensor", asa ca am cerut si eu 2 monstre (samples) si, spre uimirea mea, in 3 zile a si sosit tocmai din Filipine:
  La inceput nu mi-am dat seama care e diferenta fata de "clasicul" DS18B20,care are fisa de catalog si are denumirea de "Programmable Resolution 1-Wire Digital Thermometer".
  Diferenta este de gama de masura cu precizie mare de +0,5 grade Celsius, care este la DS18B20 de la -10 pana la +85 grade Celsius, iar la MAX31820 de la +10 pana la +45 grade Celsius, pana si cei 8 biti de identificare ai familiei de senzori este identic 028h.
   Prima data am conectat doar un senzor MAX31280 in paralel cu DS18B20, ca sa-i aflu adresa, folosind 2 sketch-uri, unul fin cel din exemplul de la libraria OneWire si celalalt in care masoara temperaturi si cu un LM35:
 
   Am conectat si pe al doilea senzor MAX31820, folosind cele 2 sketch-uri si am obtinut:
 
   Modul de conectare in paralel este prezentat, de exemplu, in articolul Temperature Sensing using DS18B20 Digital Sensors:
   Primul sketch folosit, in care se folosesc doar senzorii DS1820, respectiv MAX31820, este cel clasic din exemplul de la libraria OneWire, cu mici modificari:
#include <OneWire.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library

OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  
  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(3000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
  Serial.println("-----------------------");
}
  Al doilea sketch, care masoara si cu un LM35:
// original sketch from http://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor
// adapted sketch by niq_ro from http://nicuflorica.blogspot.com
// LM35 datasheet: http://www.ti.com/lit/ds/symlink/lm35.pdf
// inspired by http://www.roroid.ro/wiki/pmwiki.php/Main/TermometruCuArduino
// OneWire DS18S20, DS18B20, DS1822 Temperature Example: http://www.pjrc.com/teensy/td_libs_OneWire.html
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library
#include <OneWire.h>


//LM35 Pin Variables
int sensorPin = 0; //the analog pin the LM35 Vout (sense) pin is connected to A0
                        //the resolution is 10 mV / degree centigrade with a
int diodePin = 1;  //pin for measure voltage diode             

 /*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */

// added part by niq_ro
float vmed = 0;
float ve = 0;  

OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)


void setup()
{
  Serial.begin(9600);  //Start the serial connection with the computer
                       //to view the result open the serial monitor 
}
 
void loop()                     // run over and over again
{
 vmed = 0;
 ve=0;
  
 for (int j = 0; j < 10; j++)  {
  
 //getting the voltage reading from the temperature sensor
 int reading = analogRead(sensorPin);  
 int reading1 = analogRead(diodePin);  
    
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = (reading - reading1) * 5.0;
 voltage /= 1023.0; 
 
 vmed = vmed + voltage;
 delay(200);
 
 }
 ve = vmed/10;
 // print LM35 logo
 Serial.println("--------------------");
 Serial.print("   LM35: ");

/* 
 // print out the voltage
 Serial.print(ve); Serial.println(" volts");
*/

 // now print out the temperature
 float temperatureC = ve * 100 ;  //converting from 10 mv per degree 
                                               //to degrees (voltage) times 100)
 Serial.print(temperatureC); Serial.println(" degrees C");
/* 
 // now convert to Fahrenheit
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degrees F");
*/
 Serial.println("----------------");
 delay(1000);                                     //waiting a second

// DS18B20 part

  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }


  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("DS18B20: ");
  Serial.print(celsius); Serial.println(" degrees C");
/*
  Serial.print(fahrenheit); Serial.println(" degrees F");
*/
delay(2000);
}
   Concluzionand, acest tip senzor MAX31820 poate fi folosit ca inlocuitor pentru DS18B20, mai ales daca domeniul de temperatura este cel ambiant (+10..+45 grade Celsius). 
   Am facut si un mic filmulet, ca un rezumat, numit noii senzori MAX31820 fata de DS18B20
   PS: Am desenat si schema de conectare a senzorilor pentru a nu aparea dificulatati in intelegerea modului de conectare:
   Daca se doreste conectarea doar a senzorilor digitali DS18B20 si/sau MAX31280  schema devine:
12.ian.2014
PS2: Am mai pus 2 filmulete (scuze pentru calitatea sunetului):
new MAX31820 vs DS18B20 and Arduino
17.01.2014
PS2: Trebuie sa mentionez ceva, de care am uitat, in datasheet-ul senzorilor MAX31820, se mentioneaza ca tensiunea de alimentare normala este intre 3 si 3,7V deci ar functiona perfect cu microcontroler-e alimentate la tensiunea de 3,3V. Tot in datasheet se mentioneaza ca tensiunea maxima admisa este de 6V, exact ca la DS18B20... Eu le-am alimentat la 5V, cat era la Arduino si au mers perfect.