Temperature Sensing using DS18B20 Digital Sensors
Multiple sensors can be connected to the same data bus; each sensor identifies itself by a unique serial number.
The sensor can operate in normal or parasite power mode. In normal mode, a 3-wire connection is needed. In parasite power mode the sensor derives its power from the data line, meaning only two wires, the data line and a ground connection, are required.
Note: The Arduino positive supply rail is referred to as Vcc and the positive supply for the DS18B20 as Vdd. In this context, these are the same thing.
In normal mode, each sensor is connected between a power line (Vdd pin 3) and ground (GND pin 1), and the data output (DQ pin 2) connects to a third, data, line. The data output is a 3-state or open-drain port (DQ pin 2) and a 4k7 pull-up resistor to the power line is required. The data line is connected to a free Arduino digital input or Arduino digital pin 4 in the case of the emontx.
Normal mode is recommended when many devices and/or long distances are encountered.
Parasite power mode requires both DS18B20 GND (pin 1) and Vdd (pin 3) to be connected to ground. The DQ pin (pin 2 - the middle pin) is the data/parasite power line. The data line requires a pull-up resistor of 4k7 connected to + 5 V. The data line is connected to a free Arduino digital input or Arduino digital pin 4 in the case of the emontx.
Parasite mode should only be used when a small number of devices are used over relatively short distances.
Figure 1: Normal Power Connection Diagram
Figure 2: Parasite Power Connection Diagram
Figure 3: Three DS18B20's in normal power mode
Figure 4: Three DS18B20's in parasite power mode
Connecting multiple sensors
If the sensors are located relatively close to the arduino/emontx, then satisfactory operation should be achieved by making a parallel connection of the sensors at the connection to the arduino or emontx . This is called a radial or 'star' arrangement.
If long cable runs are required, consideration should be given to connecting in 'daisy-chain' fashion where one cable runs from the furthest sensor, connecting to each sensor in turn before ending at the Arduino or emontx.
There is more about this in the note below.
For short cable runs, unscreened two- or three-core cable, or single-core (parasite mode) or twin-core (normal mode) screened audio cable should be suitable. For longer cable runs, low capacitance cable such as rf aerial downlead (parasite mode) has been successfully used over a distance of 10 m. CAT 5 network cable has also been used with success over a distance of 30m, with data & ground using one twisted pair and power & ground using a second twisted pair.
Temperature Sensing with the emonTx
The emonTx supports direct connection of DS18B20 temperature sensors. The emonTx PCB includes the option to solder a DS18B20 sensor directly onto the PCB for monitoring the temperature where the emonTx is located. A more useful option is to connect DS18B20 temperature sensors to the 3.5mm temperature jack port for monitoring remote temperatures such as outside temperature, living room temperature and boiler temperature.
The sensors can be connected either in normal or parasite power mode. We recommend normal power mode for increased reliability. 3-core 22AWG wire is perfect for wiring up sensors. The sensors can also be bought ready encapsulated and wired up, and the 4k7 pull-up resistor is provided on the pcb.
Wire up the sensor(s) to a male 3.5mm jack as follows:
|Connection||Normal Mode||Parasite Mode||Voltage|
|Tip||DQ (data line)||DQ (data line)||3.9 V approx|
|Ring||Vdd||no connection||+ 5 V|
|Sleeve||GND||GND + Vdd||0 V|
(Voltages are for V2.2 boards powered at 5 V)
Note: If you purchased the Waterproof DS18B20 temperature sensing kit from the shop, it is pre-wired:
Data: White wire
Vcc: Red wire
GND: Black wire
The one-wire temperature data line is hardwired to Arduino Dig I/O 4 on the emonTx PCB. See the emonTx referance page for schematic and PCB layout.
The emonTx runs internally at 3.3V. On emonTx PCB version 2.0 and 2.1 the DS18B20 also runs at 3.3V.
On emonTx V2.2 the temperature sensors are connected to the PWR rail which is 5V when the emonTx is powered via 5V USB. Note: ignore the solder jumper, if you look carefully it is already connected to PWR. Running the sensors at 5V gives increased reliability and allows for more sensors and longer cable runs to be used
GitHub emonTx temperature example also includes a sketch to extract the serial number from the DS18B20.
Each sensor has an unique serial number given to it in manufacture, and your sketch (unless it is the "low-power" one that only expects a single sensor) must be programmed with these numbers so that it can identify and interrogate each sensor individually. Download the examples from GitHub emonTx temperature example and in there you will find the temperature search test sketch. You need run this once only to extract and list the serial number from each DS18B20, then you manually copy the serial numbers into your monitoring sketch.
Notes and further reading
"If you intend to have a large 1-wire network, it is important that you design the network correctly, otherwise you will have problems with timing/reflection issues and loss of data. For very small networks, it is possible to connect each sensor in a star or radial arrangement. This means that each sensor is connected via its own cable back to a central point and then connected to the 1-wire to serial adapter. However, it is strongly recommend that you connect each sensor to a single continuous cable which loops from sensor to sensor in turn (daisy chain). This will reduce potential mis-reads due to reflections in the cable. Each sensor should have a maximum of 50mm (2") of cable connected off the main highway. Even using this method, connecting more than 10-15 sensors will still cause problems due to loading of the data bus. To minimise this effect, always place a 100-120 ohm resistor in the data leg of each sensor before connecting to the network."
quoted from: http://www.jon00.me.uk/onewireintro.shtml
Lots of info about 1-wire bus problems here: http://www.shucksmith.co.uk/blog/ds2480bds18b20drivers-1