I2C with DHT11

Hello everyone!

I have some problems with parts i mentioned above. They just can't work both. DHT11 is working fine on serial monitor, and 16x2 LCD is showing "Hello World" as it should, but when I use them both, LCD is not working, it's without background light and shows strange letters or nothing. I need them to my project with thermometer. Only pins shared are 5V and GND.

Here is the program I'm using

Greetings from Poland!

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
// #define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);

// LCD
// LCD RS=3, EN=4, DS4=5, DS5=6, DS6=7, DS7=8
#include <Wire.h>   // standardowa biblioteka Arduino
#include <LiquidCrystal_I2C.h> // dolaczenie pobranej biblioteki I2C dla LCD

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);



void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16,2);
  dht.begin();
  lcd.backlight();
}

void loop() {
  
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity();
  int t = dht.readTemperature();

    // set the cursor to (0,0):
  lcd.setCursor(0, 0);
  // print from 0 to 9:
  
   lcd.print("Temp: ");
   lcd.print(t);
   lcd.print("C");
  // set the cursor to (16,1):
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");
    delay(200);
}

do you use pull up resistors?
for both devices?

How do you power the system?
Can you measure the on board voltage?

I do only for DHT11.

I power it from iPhone charger which is 5v 1A by Micro USB

Is it an Arduino Leonardo ? If so, use for example pin 8 for the DHT11.

Sure it's Leonardo.

After I changed it to pin 8 everything is working perfect! Thank you very much!

The Leonardo has SDA on pin 2 and SCL on pin 3.
See the page about the Leonardo : https://www.arduino.cc/en/Main/arduinoBoardLeonardo
"TWI: 2 (SDA) and 3 (SCL). Support TWI communication using the Wire library"