how could i program the arduino uno read 10 dht11 or dht22 tempeture sensors one after another so that i can program them to control relays. im having a hard time figuring out how i can even connect 10 of them to the same bored. i could even split it up between 2 boards too. but im trying to figure out how to hookup more than one in the code?? thanks
notsolowki:
how could i program the arduino uno read 10 dht11 or dht22 tempeture sensors one after another so that i can program them to control relays. im having a hard time figuring out how i can even connect 10 of them to the same bored. i could even split it up between 2 boards too. but im trying to figure out how to hookup more than one in the code?? thanks
You can't without additional hardware. The protocol is a proprietry one-wire protocol that does not support multiple devices on the bus.
The simplest way is to use a CMOS Analog Switch. 3 quad switches will give you access to 12 sensors using 3 pairs of address lines. Another 3 data lines and you can manage 12 sensors 3 at a time.
From a hardware perspective this is the simplest. You need 3 cmos chips and 3 pullup resistors on the input data lines (data line idle state is high). You must use analog switches to enable the pullups to work through the chip. Tristate cmos would work too but need more pins.
There are other smarter ways that reduce the resource usage of the Arduino at the expense of more external hardware.
Another solution would be a cmos tristate one of 16 decoder. This would be economical on Arduino pins but require 16 resistors for pullups (10 for 10 sensors).
A tristate 16 bit shift register would also work just fine and be even more economical on pins. The advantage of the shift register is that you can connect it directly to the SPI pins of the Arduino and pump out the sensor addresses on the SPI bus. I have used these shift registers in the past to make SPI interfaces to various hardware whilst still enabling other SPI hardware to coexist. You need some way for the register outputs to enable the DH11 data lines. Discrete transistors or open collector logic gates is the solution.
With this approach you use the DH11 libraries as supplied. Send the sensor address out via an SPI 16 bit write. Read the sensor. Loop away
In a nutshell, there is no easy way unless you are comfortable with hardware, which you should be (or aiming to be) if you are programming embedded controllers.
The software approach is processor hardware resource intensive and a gigantic waste of computing power. You will end up using up all of the micro's pins and more and having a trivial little bit of code that does not much more than drive the address lines.
Hope this helps.
Rob Tillaart's library can apparently read multiple devices provided each has a separate signal line. So given 10 DHT11s and assuming 10 relays to go with them, if you give up serial and use the analog pins as digital, you have exactly enough pins.
Personally, I'd use DS18B20s instead for such an exercise - do you need to use the DHT11?
since the output signal is digital, you can use any pins. the analog pins can be used as digital btw.
if you need more pins, the use of the switch offers a way of putting two sensors on one pin.
a Mega would offer more pins
a NANO could be used for all inputs and send the data to a second one that does control.
in other words, there are more than a few ways.
anyone have someone's ear at Phillips ? BME280 should be !2C with multiple addresses. only 2 addresses sucks.