3 Temperature Sensor

Hi everyone,

In one of my project I need to mesure 3 different temperature so I decided to use the "MCP9808 temperature sensor"

With one it is ok, I just plug it to pin A4 and A5

The problem is, I can't plug the 3 of them to A4 & A5. I was thinking about plugging one to A2&A3 and the other one on A0&A1.

But how do I choose the pins I'm on in the code ? Can I even do that ? If not how can I plug different temperature sensor ?

Thank you for your time and help!!!

TeamTanguy:
The problem is, I can't plug the 3 of them to A4 & A5. I was thinking about plugging one to A2&A3 and the other one on A0&A1.

A much bigger problem is that you need to learn about what a MCP9808 temperature sensor actually is, and then about the I2C bus. You should then find that you can put several on pins A4,A5, and putting them on any other pins is a really bad idea. Adafruit have a clear tutorial on these.

Oh I see !! Thank you verry much for not letting me do a really big mistake :confused:

But then how can I make the difference between them ?

Rignt now I call one :

"Adafruit_MCP9808 tempsensor1 = Adafruit_MCP9808(); // Create the MCP9808 temperature sensor object"

Then it should be alright

Most of it is in the Adafruit tutorial - including how to set the addresses (connect one or more of the A0/A1/A2 pins of the sensor to Vcc).

They unfortunately forgot to tell you how to select the address... but a quick look at the library source revealed how this works, as I expected you just pass it to the constructor:

Adafruit_MCP9808 tempsensor1 = Adafruit_MCP9808(address);

With address the configured I2C address. This way you can connect up to 8 such sensors to a single I2C bus.

wvmarle:
They unfortunately forgot to tell you how to select the address

(Ahem!) I should have said "Adafruit have a clear tutorial on these, but I have not actually used these sensors", I stayed with DS18B20s

DS18B20: small; cheap; very good value for money; longer cables are possible; the cable needs only three wires; a single Arduino pin is enough for three sensors; easy to connect (only three pins); excellent OneWire and DallasTemperature library; reliable hardware and software.
9.5 out of 10 points (not the full 10 points, because the libraries turn off the interrupts).

MCP9808: not often used; the I2C bus can be only 0.5 or 1 meter long; why?
Good sensor, but to use it with an Arduino only 5 out of 10 points.

Koepel:
MCP9808: not often used; the I2C bus can be only 0.5 or 1 meter long; why?

I2C can be a bit longer than that, 2 meters or even more, a bit depending on the wire used.

That's inherent to the simple design of this bus, especially the open collector part of it. I2C is designed for on-PCB communications.

Ok, still when I'm writing an address for exemple :

Adafruit_MCP9808 tempsensor2 = Adafruit_MCP9808(0x19);

I got an error message :
exit status 1
no matching function for call to 'Adafruit_MCP9808::Adafruit_MCP9808(int)'

Do you have any explanation ? :confused:

Thank you :roll_eyes:

The I2C address is default 0x18, for 0x19 you can use it as a parameter with "begin".

Adafruit_MCP9808 tempsensor2 = Adafruit_MCP9808();

void setup() {
  tempsensor2.begin(0x19);
  ...

Did you buy a DS18B20 yet ? Give it a try :slight_smile:

Thank you verry much :slight_smile:

No but I'm going to check it !!

What is so better in a DS18B20 ? It seems like you guys find it way better and easier to use !