7

I was using a temperature sensor DS18B20 with Arduino.

I've read that you should connect the digital input line and the 5V line with a 4.7kOhm resistor - like in the picture.

Can someone explain why do we need to do this? And why this resistance? What happens if we don't put a resistor at all or use a different resistance?

Dallas DS18B20 with the 4.7kOhm resistor

closed as off-topic by Dat Ha, jfpoilpret, Mattia, KIIV, Code Gorilla Nov 18 '16 at 13:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – Dat Ha, jfpoilpret, Mattia, KIIV, Code Gorilla
If this question can be reworded to fit the rules in the help center, please edit the question.

8

The product page FAQ [https://www.maximintegrated.com/en/support/faqs/ds18b20-faq.html] has an entry:

Q: Is the 4.7kΩ resistor needed for 5V and 3.3V operation?
A: Yes, the 4.7kΩ pullup resistor is required for both 5V and 3.3V applications.

The 1-wire bus requires that the control signal be pulled high so the master device can pull it low to ask for data, and the slave device can pull it low to give the data. This allows you to have multiple 1-wire devices on the same "one wire".

The data sheet notes another purpose:

Another feature of the DS18B20 is the ability to operate
without an external power supply. Power is instead
supplied through the 1-Wire pullup resistor through the
DQ pin when the bus is high. The high bus signal also
charges an internal capacitor (CPP), which then supplies
power to the device when the bus is low. This method of
deriving power from the 1-Wire bus is referred to as “parasite
power.” As an alternative, the DS18B20 may also be
powered by an external supply on VDD.
2

Adding to jose's answer above to answer your other two questions

And why this resistance? When the device doesnt have its own power supply it uses the power going through the pull up resistor-thus with this resistance it is powered properly. Also the other reason- as Jose wrote is because it the value which differentiates high or low bits.

What happens if we don't put a resistor at all or use a different resistance? If you are going to you an out of spec value-dont expect the device to work properly because its using the wrong resistance-e.g. it may not work because if the resistance is too high-then according to ohms law it may not receive enough parasitic power. Though it should be able to tolerate the error tolerance of the resistor-so changing it by a few ohms either way from 4700 ohms will not make a difference. You may damage the device without a resistor.

  • Thanks! What I still don't understand, is that we do supply the power to the temperature sensor by the 5V line directly (one of the legs of the sensor is conntected to the Arduino's 5V). So, does that mean that the power supply goes from 5V, through the resistor to the digital input line (the middle leg)? – camillejr Nov 3 '16 at 22:49
  • How do you think the sensor works when its powered from the arduino? – Dat Han Bag Nov 3 '16 at 22:55
  • Im trying to understand what you are thinking thats why I asked that. – Dat Han Bag Nov 3 '16 at 22:55
  • 1
    In your particular use-case, you aren't using the parasitic-power feature. The 4.7k ohm resistor is a "pull-up" resistor for the bus's data line. Why 4.7k? At 5V, the most current that can flow through the resistor is about 1mA. That's weak enough that all any other device on the bus needs to do to bring the line down to (near) 0V is sink more than 1mA of current. But when that device let's go (stops sinking current) the line always rises back to 5V. – jose can u c Nov 4 '16 at 2:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.