Ds18b20 2 wires

I'm a beginer on arduino and I bought a ds18b20 with 2 wires (yellow &red).
I don't know if it could work with an arduino MEGA and if yes how to connect it.
Thanks in advance for your support.

Best regards,


Please post a link to where you got it

I am not very familiar with the DS18B20, but it seems unusual that it would have only 2 wires due to the way that it works

@Heyes68, your topic was moved to a more suitable location of the forum.

Can you please post a link to hte product that you bought.

Hi, @Heyes68
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Can you post a link to where you purchased your DS18B20?

A DS18B20 has three wires.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

1 Like

You can run a DS18B20 with two wires - "parasitic power" is what you'll need to search for. IIRC, not all versions of the sensor do this, you need the 'P' version, but since you've only got two wires, I'd assume that's what it is.

True, but it also can be used in the 'parasite power mode' where GND and DATA are connected together. That connection is generally not recommended but some devices are actually packaged that way from the supplier.


(Bill types faster than me)

There are libraries for the DS18B20 which contain examples on how to use it .
Google will find it.

The two wire devices may not work with long cable connections , if that is what you have . For testing connect the sensor close to your Arduino .

thanks for your help. the link of the parts I bought.


I know this, BUT why sell them as two wire?
Are they factory seconds?

Tom... :grinning: :+1: :coffee: :australia:

Not surprizing at all if you've read the datasheet...

This sensor can be used in parasite power mode, only using data and ground - its definitely less robust than using it three-wire. If you haven't bought it from a reputable supplier be warned, there are a vast amount of counterfeits out there for this expensive chip.

Did I say that I was surprised ?

It seemed unusual, you weren't expecting it, you were thus surprized? Better to check the datasheet before answering a question like this I'd have thought?

It seemed unusual, but due to my limited experience with the device, which I made clear, I was not surprised. However, unlike @TomGeorge I did not give a definitive answer as I was not sure of my ground. This was the reason that I asked for more information

Hi, @Heyes68

Your sensors if only two wire need to be used in what is called "parasitic power" mode.
This link will show you the ways to connect the sensors, no matter if it is a Mega for this application.

Tom... :grinning: :+1: :coffee: :australia:

Hi, @TomGeorge

Thanks for your help. I try to connect it with the OneWire librairie but it doesn't work. It's something special to know about the code or the wiring?

Please post you test sketch

Can you post a circuit diagram showing how you connected the sensor to your Mega?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

There are examples in the library , have you tried those ?

Alas there are a lot of fake DS18B20's out there, so beware of that.

2-wire use is much flakier than 3-wire, I'd never elect to use this device in 2-wire mode as you cannot decouple it so it will be more susceptible to noise pickup.
Driving 2-wire mode requires a flag in the library to drive the line active-high, not just
with a pull-up resistor - if you forget this 2-wire is unlikely to work even with a good

Dallas Library examples include parasitic mode .

As implied only good for short leads !! Some eBay devices ( with three wires) are faked and won’t work parasitic