Help connecting a Temperature/Humidity sensor

I’m working on my first nerves project. (I got a Raspberry Pi 3 for Christmas. :slight_smile: ) The project is mainly working but I’m having trouble with the DHT11 sensor. These ones specifically: I’ve been following this: Elixir Nerves for measuring temperature from a DS18B20 sensor on a Raspberry Pi · Carsten's Blog to see how to setup the project. I’ve tried a lot of different pins for the wiring and data out line. I never get a file that starts with 28- The closest is 00-. And they are in /sys/bus/w1/devices/

For wiring I have + to pin 1, gnd to pin 6 and data to pin 7 on the gpio connector.

I’m not sure what to try next.

Nice! It’s fun but getting past the initial hardware setup can be a bit tricky. Unfortunately some sensors use custom protocols and require more precise timing than is easy to get in linux. 1Wire is built into the Linux kernel so it works well. However, the DHTxx sensor seem to use their own custom protocol according to a tutorial for one here.

It’s not clear if the DHT11 is able to be used with 1wire or not, but if not you’d have to try and port the Arduino library or Adafruit Python library to Elixir using Circtuis.GPIO. However, Adafruit deprecated their Python library on Linux. Arduino’s have more consistent timing so it’s easier to interface to these custom data protocols. Nerves relies on Linux which has much less precise timing for “custom bitbanging” protocols unless you write custom c code or better a Linux kernel module :confused: .

My suggestion would be to switch to an I2C or SPI based temp sensor (or I2C adc wired up to an analog temp sensor). There are a few on Amazon like Adafruit MCP9808 or the BME280. The BME280 part also includes barometric pressure! They also both likely have higher precision temperature than the DHT11.


If you are interested in an inexpensive sensor that works well with Nerves, I wrote an Elixir library to interface with the Bosch BME680 (that measures humidity, temperature, pressure, and gas resistance, correlated to air quality):

Hope it helps :slightly_smiling_face:

1 Like

@lucaong nice! I didn’t know anyone wrote a BME280 library for Elixir. I might use it, well just because why not measure it.

1 Like

did you give a try?
see for usage

@elcritch my library is for the BME680, but I assume creating one for the BME280 should work similarly :slightly_smiling_face:

1 Like

Looking at the source for nerves_dht it only supports Raspberry Pi and Pi 2 and is based on a deprecated library. I have a Raspberry Pi 3 B. It might work, but I may have to add Raspberry Pi 3 support.

I may give a BME680 a try since I’m not willing to invest a lot of time on a deprecated library to make a $10 part work. Or maybe I’ll try to get a BME280 to work. I’ll have to have a look at the code for

Thanks for all the help and pointers guys. This really helpful. I won’t be able to do much for a while. Heading out on a business trip tomorrow.


believe nerves_dht should just work on any rpi… but for numerous reasons it might be better going with a bme* - was more if you just wanted to get going instead of waiting for parts…

Perhaps, but it looks to be based on memory mapped GPIO pins which aren’t necessarily portable between RPi versions.

1 Like

I added BME280 support to @lucaong’s BME680 project. The PR is here: I think it should be okay. In any case it works with this sensor I got off Amazon:


That’s really amazing @baldmountain ! Thanks for your PR! Tomorrow I will have a look at it and merge it :tada: :rocket: I am waiting for a BME280 so I will be able to test it too :slight_smile:

1 Like

@lucaong You’re welcome. I didn’t do much beyond following what you did.

It is tested. I have a version running on a raspberry pi 3 monitoring my basement.

1 Like

I merged your pull request and released version 0.2.0 with support for the BME280. In a few days I will receive a BME280 in addition to my BME680 so I’ll be able to maintain it and test it. Thanks again!