Hubduino 8266 multiple ds18b20 sensors OneWire pin assignment

In the pin assignment section of the st_anything_multiples_8266wifi multisensor sketch, it shows one pin assignment for temperature1. If I am running 4 sensors on pin 2 would an individual pin assignment line for each sensor (all using the same pin) be needed in order to get the temps from all of them instead of just the first on the line? I noticed the sketches don't call the OneWire library.

#define PIN_TEMPERATURE_1 D7 //SmartThings Capabilty "Temperature Measurement" (Dallas Semiconductor DS18B20)

It is actually pretty simple.

The DS18B20 sensors can either be each connected to their own GPIO pins, which would require you to define four PINs, and create 4 unique DS18B20 devices...

OR

Take the easy way and connect all 4 DS18B20 sensors to one GPIO pin. Here is an example from one of my projects. Note the last argument is a "4", which indicates the number of sensors connected.

  static st::PS_DS18B20_Temperature  sensor2(F("temperature"), 120, 5, PIN_TEMPERATURE_1, false, 10, 4); 

Here is the documentation for this particular device class.

//******************************************************************************************
//  File: PS_DS18B20_Temperature.h
//  Author: Dan G Ogorchock
//
//  Summary:  PS_DS18B20_Temperature is a class which implements both the SmartThings "Temperature Measurement" capability.
//			  It inherits from the st::PollingSensor class.  The current version uses a digital pin to measure the 
//			  temperature from a Dallas Semiconductor One Wire DS18B20 series sensor. 
//
//			  Create an instance of this class in your sketch's global variable section
//			  For Example:  st::PS_DS18B20_Temperature sensor1(F("temperature1"), 120, 0, PIN_TEMPERATURE, false); (for a single sensor)
//                          st::PS_DS18B20_Temperature sensor1(F("temperature"), 120, 0, PIN_TEMPERATURE, false, 10, 3); (for 3 sensors)
//
//			  st::PS_DS18B20_Temperature() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - either "temperature1" for a single sensor, or "temperature" for multiple sensors
//				- long interval - REQUIRED - the polling interval in seconds
//				- long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time
//				- byte pin - REQUIRED - the Arduino Pin to be used for the One-Wire DS18B20 sensor conenction
//				- bool In_C - OPTIONAL - true = Report Celsius, false = Report Farenheit (Farentheit is the default)
//				- byte resolution - OPTIONAL - DS18B20 sensor resolution in bits.  9, 10, 11, or 12.  Defaults to 10 for decent accuracy and performance
//				- byte num_sensors - OPTIONAL - number of OneWire DS18B20 sensors attached to OneWire bus - Defaults to 1
//				- byte sensorStartingNum - OPTIONAL - Starting number for sending temperature sensor data when using multiple sensors on one pin - Defaults to 1
//

That is exactly what I was looking for. Thank you. I will give this a shot tonight. Thank you for all of your work on this. Sorry I missed this in the docs. I need to read through the documentation again.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.