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
Am desenat schema completa de conectare a senzorilor din familia DS18x20 (DS18B20, DS18S20, DS1822, MAX31820) si a afisajului LCD 1602 cu interfata i2c:

