Multiples Heat Sensors for Arduino ONU Issue

Hello everyone, my problem is certainly easy to resolve but i am a beginner and i actually don’t know what to do…

I purchased 3x MCP9809 Temp Sensor and i’m trying to read their temperature all together with an Arduino Uno.

Here is my code :

#include <Wire.h>
#include "Adafruit_MCP9808.h"

// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor_1 = Adafruit_MCP9808();
Adafruit_MCP9808 tempsensor_2 = Adafruit_MCP9808();
Adafruit_MCP9808 tempsensor_3 = Adafruit_MCP9808();

void setup() {
  Serial.begin(9600);
  Serial.println("MCP9808 demo");
 
  
   
  if (!tempsensor_1.begin(0x18)) {
    Serial.println("Couldn't find MCP9808 #1!");
   while (1);
    }
  if (!tempsensor_2.begin(0x19)) {
   Serial.println("Couldn't find MCP9808 #2!");
   while (1);
    }
  if (!tempsensor_3.begin(0x1A)) {
Serial.println("Couldn't find MCP9808 #3!");
   while (1);
  }
}

void loop() {

  float c1 = tempsensor_1.readTempC();
  float c2 = tempsensor_2.readTempC();
  float c3 = tempsensor_3.readTempC();
  Serial.print(c1); Serial.print(';'); Serial.print(c2) ; Serial.print(';') ;
 Serial.print(c3) ; Serial.println(';') ;
 delay(3000);
}

And here is the problem :

The program doesn’t find the sensors related with 0x19 (linked with A0) and 0x1A (linked with A1)…
It always returns “Couldn’t find MCP9808 #2!” (or #3 if i put the line related with the #2 in commentary (//))
The code works with only one sensor ( the one which is not linked with A0,A1 or A2) : (0x18)…

I checked several times my conections and i think they are good, so i guess this is a problem related with the code, but i honestly don’t know what to do as i used the basic example from the MCP9808 website (which works with only one sensor)

I’ll be glad if someone knows how to fix that :wink:

Julo159:
...
Here is my code :
...

and here are my code tags [code]  [/code]

The sensor is (assumption) an I2C sensor.

The sensors break outs have 3 pads A0..A2 which must be connected to GND or 5V.
This changes the addres you use.

What you could do is load a I2C scanner and check if it can find 3 sensors with 3 addresses.

download - Arduino Playground - I2cScanner

give it a try.

According to the datasheet you shouldn't leave any of the address pins unconnected. Please provide a wiring diagram of your setup.

Do you use the chip directly or some breakout board? If the later is used, please provide a link to that product.

robtillaart:
The sensor is (assumption) an I2C sensor.

The sensors break outs have 3 pads A0..A2 which must be connected to GND or 5V.
This changes the addres you use.

What you could do is load a I2C scanner and check if it can find 3 sensors with 3 addresses.

download - Arduino Playground - I2cScanner

give it a try.

Hello, I did it and the program scans only the 0x18 adress, it looks like the A0/A1/A2 doesn't work. Should i buy a new Arduino UNO card ?

Julo159:
Hello, I did it and the program scans only the 0x18 adress, it looks like the A0/A1/A2 doesn't work. Should i buy a new Arduino UNO card ?

If you connect the sensors one at a time, do they all appear as sensor 0x18?

robtillaart:
If you connect the sensors one at a time, do they all appear as sensor 0x18?

Yes, if only one is connected (with A0/A1/A2 OR nothing more ( juste vdd/gnd/scl and sda) ) the program only scans the adress 0x18

Now do two tests:

connect 1 sensor to I2C and connect all A0/1/2 to 5V and run the I2C scanner again, what do you see?

connect 1 sensor to I2C and connect all A0/1/2 to GND and run the I2C scanner again, what do you see?

robtillaart:
Now do two tests:

connect 1 sensor to I2C and connect all A0/1/2 to 5V and run the I2C scanner again, what do you see?

connect 1 sensor to I2C and connect all A0/1/2 to GND and run the I2C scanner again, what do you see?

For the first test :

I2C Scanner
Scanning...
I2C device found at address 0x1F !
done

For the second test :

I2C Scanner
Scanning...
I2C device found at address 0x18 !
done

I think i understood the problem, i'll plug the A0...A2 to 5V and it will recognize the sensors #2 and #3 ! doesn't it ? Should i plug also to the A0/A1/A2 from the Arduino uno in addition of 5V or just to 5V?

so the connections look like this map for certain addresses

Address        A0    A1    A2
---------------------------------
 18            GND   GND   GND
 19            +5V   GND   GND
 1A            GND   +5V   GND
 1B            +5V   +5V   GND
 1C            GND   GND   +5V
 1D            +5V   GND   +5V
 1E            GND   +5V   +5V
 1F            +5V   +5V   +5V

It's done ! I finally have this :

I2C Scanner
Scanning...
I2C device found at address 0x18 !
I2C device found at address 0x19 !
I2C device found at address 0x1C !
done

So my 3 sensors work and i can go further in my project ! Thank you Rob Tillaart :smiley:

Julo159:
It's done ! I finally have this :

I2C Scanner
Scanning...
I2C device found at address 0x18 !
I2C device found at address 0x19 !
I2C device found at address 0x1C !
done

So my 3 sensors work and i can go further in my project ! Thank you Rob Tillaart :smiley:

Actually I put the first code i gave you in this topic and now i have the error message : Couldn't find MCP9808 #1

However your program finds the adress 0x18.... What's the problem here?

Julo159:
Actually I put the first code i gave you in this topic and now i have the error message : Couldn't find MCP9808 #1

However your program finds the adress 0x18.... What's the problem here?

try to add a Wire.begin(); statement in setup()

robtillaart:
try to add a Wire.begin(); statement in setup()

I think i found the problem, one of my sensor is broken because of my bad solder....

I have this :

20.37;0.00;20.19;
20.31;0.00;20.19;
20.31;0.00;20.12;
20.31;0.00;20.12;
20.31;0.00;20.06;
20.25;0.00;20.06;
20.25;0.00;20.06;
20.19;0.00;20.06;
20.19;0.00;20.00;
20.12;0.00;20.00;

The adress is OK but i have a temperature of 0° which is obviously not the case.
As the code is the same for the 3 sensors it must be a problem related with the #2... It must be unfunctional !
Actually i really need just 2 sensors so it's ok ^^
Thank's again