I have two DS18B20 temperature sensors connected via a OneWire bus to an arduino. I noticed that these sensors get hot, when permanently powered and decided to just turn them on for measurment.
First attempt: Define a pin as output and feed the sensors. Because I received only one value (first sensor on bus), I assumed that the current delivered may not be high enough and utilized a transistor (+resistor) as switch for the main 5V line to feed the sensors from the mains (as before). The result is the same. I only get the value of the first sensor. When I connect the sensors directly, I get both values.
I tried up to 4 seconds delay after switching the bus on and again after reading the values (before switching the bus off again), with no luck. Only the first sensor answers.
Do I have a timing or a current problem here?
UPDATE
Wiring (working): Two DS18B20 in parrallel with a 4,7k resisor between DATA
and VIN
. One Arduino pin used, Sensors directly powered by power-supply (same as arduino)
Wiring (not working): Broke the VIN
line and added a transistor as switch between power-supply and sensors VIN
. Used a second pin and a resistor to power up the line.
The transistor is a TC124E
(npn) logic level transistor. I have the feeling, that this boy is not providing enough current to the sensors, which in addidtion have five meter cables attached...
UPDATE II It is not the current. I replaced the transistor with a mosfet (70T03H) and the result is exactly the same: When switched, only one sensor answers . When I connect the gate directly to a +5V line, I get both values as expected.
Kinda think, that the switching of the pin irritates the bus or the specific device.
UPDATE III (Solution)
I tracked this down to a mixture of
- Different resolution settings on the sensors
- my code not waiting long enough to get the sensor with the higher resolution to setup (on-to-read time). Giving the bus slightly more time to setup before any reading is accepted, solved my problem.