ArduinoGeneral

Multiple sht20 sensors on Arduino uno rev2

userHead scoobie2002 2019-08-12 17:06:43 4495 Views5 Replies
Hi,

i am creating an gardening project for my home. I have two sht20 sen0227 sensors on one arduino. Sensor1 has adress 0x40 and sensor2 has adress 0x60 (i found these adresses using an i2c scanner).

This is all good and well but... how do i make use of this knowledge? I tried modifying the samplecode that is for just one sensor. Please bear in mind that i have just a bit of Arduino coding knowledge and i am tryinbg for lots of hours these last three months. I really tried. Google has proven nót to be my best friend.

Can anyone help me out? I am totally empty and lost...

Thanks!!

Scoobie

This is where i crashed:
Code: Select all
#include <Wire.h>
#include "DFRobot_SHT20.h"

DFRobot_SHT20    sht20;
DFRobot_SHT20    sht21;

void setup()
{
    Serial.begin(9600);
    Wire.begin();
    Serial.println("SHT20 Example!");


}

void loop()
{
    Wire.beginTransmission(0x40);

    sht20.initSHT20;                                  // Init SHT20 Sensor
    delay(100);
    sht20.checkSHT20();                                 // Check SHT20 Sensor
    float humd = sht20.readHumidity();                  // Read Humidity
    float temp = sht20.readTemperature();               // Read Temperature
    
    Wire.endTransmission(); 
    
    Serial.print("Time:");
    Serial.print(millis());
    Serial.print(" Temperature 1 :");
    Serial.print(temp, 1);
    Serial.print("C");
    Serial.print(" Humidity 1 :");
    Serial.print(humd, 1);
    Serial.print("%");
    Serial.println();
    delay(1000);
    
    Wire.beginTransmission(0x60);

    sht21.initSHT20();                                  // Init SHT20 Sensor
    delay(100);
    sht21.checkSHT20();                                 // Check SHT20 Sensor
    float humd2 = sht21.readHumidity();                  // Read Humidity
    float temp2 = sht21.readTemperature();               // Read Temperature

    Wire.endTransmission(); 
    
    Serial.print("Time:");
    Serial.print(millis());
    Serial.print(" Temperature 2 :");
    Serial.print(temp2, 1);
    Serial.print("C");
    Serial.print(" Humidity 2 :");
    Serial.print(humd2, 1);
    Serial.print("%");
    Serial.println();
    delay(1000);
}
2019-08-15 13:56:34 Ok...

in an earlier stage i tried a i2c bus scanner and that returned two i2c adresses: 0x40 and 0x60. Both connected on the same sda and scl pins. That should mean that it has to be possible? I'm no script hero and am in the early stages of learning...so i could be wrong?

Please advice :)
userHeadPic scoobie2002
2019-08-14 22:39:04 Thank you for the reply.

as you stated, i should use the code in the wiki. I deleted the code as shown above and started new with the code as mentioned in the wiki.

Could you clearify which pins i should use for both sensors? One of them is now connected to SDA and SCl pins on my Arduino board. Which pins should i connect the second sensor to?

What should i add in the basic code as to get the readings from that second sensor? The sensor connected to my SDA and SCL pins is working perfectly.

Many thanks!!!! You are a lifesaver !!!
userHeadPic scoobie2002