I am experimenting with connecting 8 x DS18B20 temperature sensors to an Arduino MEGA 2560 (before I include them in my main project). I'm using the water resistant DS18B20's, 5 on a 3 metre cable and 3 on a 1 metre cable.
I started by getting the individual address of each DS18B20 by connecting each one to the MEGA individually and using one of the available sketches for that purpose. Each DS18B20 returned its address and temperature correctly.
I then connected all the DS18B20's together by soldering all the red wires, black wires and yellow wires together, put them into a connecting block, then into a breadboard with a 4.7Kohm resistor between the +ve 5v and the yellow data pins, then into the MEGA.
I am using the (c) 2010 Mark McComb, hacktronics LLC sketch, modified, for reading these sensors. The sketch is returning the correct name I've given for each sensor, but all the temperatures are coming back as 0.00 C .
// temperature sensors.
// Copyright (c) 2010 Mark McComb, hacktronics LLC
// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 10 on the Arduino
#define ONE_WIRE_BUS 10
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress intakeThermometer = { 0x28, 0x9E, 0xC2, 0x97, 0x1F, 0x13, 0x01, 0x88 };
DeviceAddress exhaustThermometer = { 0x28, 0xAA, 0x68, 0xF7, 0x17, 0x13, 0x02, 0x60 };
DeviceAddress supplyThermometer = { 0x28, 0x38, 0x4F, 0x95, 0x1F, 0x13, 0x01, 0x46 };
DeviceAddress extractThermometer = { 0x28, 0xAA, 0x03, 0xF0, 0x17, 0x13, 0x02, 0x87 };
DeviceAddress evaporatorThermometer = { 0x28, 0x7D, 0x2A, 0x8D, 0x1F, 0x13, 0x01, 0x3F };
DeviceAddress supplybetweenHECondenserThermometer = { 0x28, 0xA1, 0x38, 0x45, 0x92, 0x12, 0x02, 0x08, };
DeviceAddress exhaustbetweenHEEvaporatorThermometer = { 0x28, 0x08, 0x3E, 0x45, 0x92, 0x12, 0x02, 0x5E, };
DeviceAddress atticspaceThermometer = { 0x28, 0xDB, 0x33, 0x45, 0x92, 0x12, 0x02, 0x2F, };
void setup(void) {
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(intakeThermometer, 10);
sensors.setResolution(exhaustThermometer, 10);
sensors.setResolution(supplyThermometer, 10);
sensors.setResolution(extractThermometer, 10);
sensors.setResolution(evaporatorThermometer, 10);
sensors.setResolution(supplybetweenHECondenserThermometer, 10);
sensors.setResolution(exhaustbetweenHEEvaporatorThermometer, 10);
sensors.setResolution(atticspaceThermometer, 10);
}
void printTemperature(DeviceAddress deviceAddress) {
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print(tempC);
Serial.print(" C");
// Serial.print(" F: ");
// Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop(void) {
delay(2000);
// Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
Serial.print("Intake: ");
printTemperature(intakeThermometer);
Serial.print("\n\r");
Serial.print("Exhaust: ");
printTemperature(exhaustThermometer);
Serial.print("\n\r");
Serial.print("Supply: ");
printTemperature(supplyThermometer);
Serial.print("\n\r");
Serial.print("Extract: ");
printTemperature(extractThermometer);
Serial.print("\n\r");
Serial.print("Evaporator: ");
printTemperature(evaporatorThermometer);
Serial.print("\n\r");
Serial.print("Supply X: ");
printTemperature(supplybetweenHECondenserThermometer);
Serial.print("\n\r");
Serial.print("Extract X: ");
printTemperature(exhaustbetweenHEEvaporatorThermometer);
Serial.print("\n\r");
Serial.print("Attic: ");
printTemperature(atticspaceThermometer);
Serial.print("\n\r\n\r");
}
They should all be returning around 17.0 C .
Could this be an issue with my using 5 x 3 metre and 3 x 1 metre lengths? Or reflections from my soldering? It's strange that the sketch is seeing all the sensor addresses, but not the temperatures.


