Code: Select all
// demo sketch for connecting OneWire temperature sensor DS18B20 to Z-Uno
// add library ds18b20
#include "ZUNO_DS18B20.h"
// pin connection ds18b20
#define PIN_DS18B20 11
#define PIN_DS18B20_B 12
OneWire ow(PIN_DS18B20);
OneWire ow_B(PIN_DS18B20_B);
// onewire connection temperature sensors
DS18B20Sensor ds1820(&ow);
DS18B20Sensor ds1820_B(&ow_B);
byte addr1[8];
byte addr2[8];
int temp; // here we will store the temperature
int temp_B; // here we will store the temperature
ZUNO_SETUP_DEBUG_MODE(DEBUG_ON);
// set up channel
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
SENSOR_MULTILEVEL_SCALE_CELSIUS,
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
tempAgetter),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
SENSOR_MULTILEVEL_SCALE_CELSIUS,
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
tempBgetter)
);
void setup() {
Serial.begin();
Serial.println("start");
}
void loop() {
ds1820.scanAloneSensor(addr1);
ds1820_B.scanAloneSensor(addr2);
// obtaining readings from the sensor ds18b20
float temerature = ds1820.getTemperature(addr1);
float temerature_B = ds1820_B.getTemperature(addr2);
// make scaled word value for report
temp=int(temerature*100);
temp_B=int(temerature_B*100);
Serial.print("Your sensor address A is: ");
for(int i = 0; i < 8; i++) {
// print OneWire code
Serial.print(addr1[i], HEX);
Serial.print(" ");
}
Serial.print("Your sensor address B is: ");
for(int i = 0; i < 8; i++) {
// print OneWire code
Serial.print(addr2[i], HEX);
Serial.print(" ");
}
Serial.println();
Serial.print("TemperatureA: ");
Serial.println(temerature);
Serial.print("TemperatureB: ");
Serial.println(temerature_B);
// send data to channel
zunoSendReport(1);
zunoSendReport(2);
// send every 30 second
delay(30000);
}
word tempAgetter() {
return temp;
}
word tempBgetter() {
return temp_B;
}