user27871: 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?


user27557: 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.

user27653: 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.


27871: <p>I was using a temperature sensor DS18B20 with Arduino. </p>

<p>I've <a href="https://arduino-info.wikispaces.com/Brick-Temperature-DS18B20" rel="noreferrer">read</a> that you should connect the digital input line and the 5V line with a 4.7kOhm resistor - like in the picture. </p>

<p>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?</p>

<p><a href="https://i.stack.imgur.com/T1O4j.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/T1O4j.jpg" alt="Dallas DS18B20 with the 4.7kOhm resistor"></a></p>
 27557: <p>Adding to jose's answer above to answer your other two questions</p>

<p>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.</p>

<p>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.</p>
 27653: <p>The product page FAQ [<a href="https://www.maximintegrated.com/en/support/faqs/ds18b20-faq.html]">https://www.maximintegrated.com/en/support/faqs/ds18b20-faq.html]</a> has an entry:</p>

<pre><code>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.
</code></pre>

<p>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".</p>

<p>The data sheet notes another purpose:</p>

<pre><code>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.
</code></pre>
