Posts: 1
Joined: Mon Aug 01, 2016 11:56 pm

Length for Temperature Sensor

Tue Aug 02, 2016 10:29 am

Hi Everyone,

This is my first post on this forum. I use PI for regular networking stuff but I have a requirement to permanently install temperature sensor around 100 ft underground attached to a steel pipe in tight space.

As per my current findings, the length of cable between temperature sensor and PI could not be very long and the one way of doing is to push the PI underground near the sensor.

Does anyone know what is the maximum cable length we can have and if there are any ideas to extend it? I will be happy to get temperature with accuracy of +- 1 degree celsius.


User avatar
Posts: 6203
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Length for Temperature Sensor

Wed Aug 03, 2016 10:09 am

Which temperature sensor? There are lots out there, with varying requirements, so more information would be helpful

User avatar
Posts: 978
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: Length for Temperature Sensor

Wed Aug 03, 2016 10:48 am

my guess is a 'k type thermocouple' .

User avatar
Posts: 4301
Joined: Wed Aug 28, 2013 3:31 am

Re: Length for Temperature Sensor

Thu Aug 04, 2016 6:28 am

I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Posts: 599
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: Length for Temperature Sensor

Sat Aug 06, 2016 7:17 pm

You really don't want to run the wire from the temperature sensor any substantial distance - just enough to get it away from the heat generated by the Pi itself. Get it converted over to digital data (assuming it isn't one of the I2C devices) as soon as possible, and use something like ethernet for fast reliable lossless long distance transmission - analog sensor readings will be substantially affected by cable length and even I2C is only good for a few meters. FWIW, for a somewhat different application (a weather station / home automation control panel), I'm using an Arduino shield (a WxShield, http://www.osengr.org/WxShield/Web/WxShield.shtml - its scope extends beyond what you need, it also listens to 433MHz remote temperature sensors) that uses a Sensirion SHT15 temperature/humidity sensor on the end of a 3ft cord to get it away from the hardware's heat (the Arduino continually reads the sensor and sends the raw data over USB to a Pi, which decodes/translates the data into human-readable form and publishes it to an in-house MQTT broker).

There are off-the-shelf remote temperature sensors (from Oregon Scientific and others) that will take readings every minute or so and broadcast over 433MHz, and there are various maker projects out there to read them (the protocols were reverse-engineered some time ago), for both Arduino and Raspberry Pi. For these, 100ft straight-line range is not out of the realm of possibility, but if you've got a lot of earth/etc. in the way, then reading a local sensor, converting to useful data and sending over ethernet would be a much more reliable approach. The hardware next to the sensor doesn't have to be a Pi, but the ethernet port built into most Pi's simplifies things.

Note that most of these sensors don't read out in celsius or fahrenheit, the raw data needs a lot of massaging to turn into the numbers that humans want, and that can be tricky for the most accurate results. Seek known good code for this.

Adafruit has a couple of nice I2C-based sensors, the Sensiron SHT31-D (https://www.adafruit.com/products/2857) and Microchip Technology MCP9808 (https://www.adafruit.com/products/1782), along with sample code. You'll find most of these lean towards Arduino implementations, but many can be (or have been) ported to the Pi.

Also, there are also some nice Pi-specific pointers in this thread: "Setting up SHT11 Humidity and Temperature Sensor" viewtopic.php?f=37&t=38506.

Posts: 220
Joined: Thu Nov 22, 2012 9:38 pm

Re: Length for Temperature Sensor

Sun May 07, 2017 3:16 pm

Does anyone have any code examples that determine which sensor is connected? I need to know if SHT31D or MCP9808 is connected, before attempted to read data from said sensor? Walking /sys/ does not seem to show this detail?

# ls /sys/bus/i2c/devices/i2c-1
delete_device device i2c-dev name new_device of_node power subsystem uevent

Posts: 3
Joined: Tue May 09, 2017 7:00 am

Re: Length for Temperature Sensor

Tue May 09, 2017 3:21 pm

Common opinion about 1-wire is that it do not work on long cables. Mostly this seems to caused by 1-wire driver issues. Correctly done 1-wire is suitable up to ½km or 1500feet cat5 cable. Currently Pi's 1-wire driver is broken and it do not support proper way to use parasitic mode, there is no working control for internal(w1-gpio) or external(w1-gpio-pullup) pullup.

Proper 1-wire interface is specified here:
https://www.maximintegrated.com/en/app- ... mvp/id/244

Black part can be done internally on Pi, but blue part have to do with external mosfet. Without level sifter this gives 3.3v interface and maybe 100feet cable lenght. With level sifter (like PCA9306) this offer full 1500feet cable support for one parasitic DS18b20. But currently Pi's w1-gpio driver do not support this, proper parasitic mode is disabled even if you have right external hardware interface..

I this case need is only 30feet, this should work with three conduct mode (power, DQ and ground). Only issue is that needed voltage level is 5v and this needs level siftin for DQ. Levelsiftin can be done with PCA9306 and only one channel is needed for DQ. With 3.3v three conductor 1-wire works a few meters. And this has been found also by several Pi users.

Posts: 35
Joined: Fri Aug 05, 2011 3:04 pm

Re: Length for Temperature Sensor

Tue May 16, 2017 4:31 pm

Been thinking the same thing. I think SPI has promise as it's a lot dumber protocol and uses a separate wire for each data direction.

I currently have a RPi0w connected via SPI to a MAX31856 board to read a K-type thermocouple. Works great, but the intended kiln is just a little bit outside my house's Wifi range so I was experimenting with putting the RPi0w outside the Faraday cage which is my garage and running plain old phone wire to the MAX31856.

Initially it didn't work, however I was able to manually bit-bang it - so if I slowed it waaay down to take a whole second to get the 24bit temperature value it worked fine! I don't know exactly how long the wire was as I just attached the lose ends of a left over spool. I inserted delays into Stephen Smith's python library https://github.com/steve71/MAX31856/blo ... ax31856.py

Also, given SPI is one-direction per wire, you can easily use an RS422 driver to get a balanced pair -
you could probably manage 100 meters: http://www.ti.com/lit/an/slyt441/slyt441.pdf

Posts: 6776
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Length for Temperature Sensor

Tue May 16, 2017 5:35 pm

One option is to use a cheap and easy to program micro-controller which can handle the sensor then send data back via serial or even PCM.

You will probably need a three-wire connection to that micro for V+, 0V and signal though you could perhaps modulate the V+ rail with the signal if you needed to make it 2-wire.

User avatar
Posts: 37134
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Length for Temperature Sensor

Sun May 21, 2017 2:14 pm

hippy wrote:One option is to use a cheap and easy to program micro-controller which can handle the sensor then send data back via serial or even PCM.
Do it with something like an ESP8266 and you can use WiFi to send data back. Easy protocol for that is MQTT.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Posts: 7
Joined: Mon Aug 28, 2017 7:22 am

Re: Length for Temperature Sensor

Mon Aug 28, 2017 7:38 am

To extend the cable to a temperature sensor for the Raspberry, what I have successfully done is to lower the pull-up resistor.
I was trying to extend the cable to about some 30 feet myself, and it did not work with the 4,7k resitor so I hooked my oscilloscoop to see what was going on. There I could see the sensor was able to pull the signal to a 'low' rapidly, but the resitor took a lot of time to pull the signal to a 'high', because of the capacity of the cable. By putting in a extra resistor in parallel (so the resistor becomes actually only about 2.3k, the signal looked much better, and the long cable worked without a problem. I have not tried how low one could go, nor what the maximum of cable then would be, but my solution is now working about two years without a problem.
One could argue that by doing this, also the dissipation the sensor has to do because it needs more power to pull down, and hence the accuracy of the sensor is less as well. and although theoretical that for sure is the case, I did not notice any real difference. So for a lot of the DIY projects that is a good solution. My application can be see at my blog at www.solarair.livotel.com. The technical details there as well.

Return to “Interfacing (DSI, CSI, I2C, etc.)”