My dht11 not showin the tempture

i'm workinng with oled and a dht11 . used some source code from this topic: https://forum.arduino.cc/t/my-1-3-oled-i2c-iic-is-not-working/1283040 from first my oled didnt work now the dht11 sensor is ust teling me the humidity and tempture is 255.00. pls help wuld be apresiated in any way. here is te code:



//********************************************^************************************************
//  OLED_Counter.ino
//
//  LarryD
//  Version   YY/MM/DD     Comments
//  =======   ========     ===============================================
//  1.00      22/04/21     Running code
//
//

//https://lastminuteengineers.com/oled-display-arduino-tutorial/

#include <Wire.h>
//#include <Adafruit_GFX.h>
//#include <Adafruit_SSD1306.h>
#include <Adafruit_SH110X.h>

/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's


//********************************************^************************************************

const byte heartbeatLED     = 13;

#define SCREEN_WIDTH        128   //OLED display width,  in pixels
#define SCREEN_HEIGHT       64   //OLED display height, in pixels


//SSD1306 display
//size 1 is 5X7   pixels therefore, 6X8   to acount for spacing,  21 characters per line
//size 2 is 10X14 pixels therefore, 11X15 to account for spacing, 10 characters per line
//size 4 is 20X28 pixels therefore, 21X29 to account for spacing,  5 characters per line

//Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

#define OLED_RESET -1   //   QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include <dht.h>

dht DHT;

#define DHT11_PIN 7
unsigned long counter       = 0;

//timing stuff
unsigned long heartbeatTime;
unsigned long displayTime;


//                                       s e t u p ( )
//********************************************^************************************************
//
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);
  
  delay(250); // wait for the OLED to power up
  display.begin(i2c_Address, true); // Address 0x3C default

  display.display();
  delay(2000);

//  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
//  {
//    Serial.println(F("SSD1306 allocation failed"));
//    for (;;);
//  }

  display.clearDisplay();

  //display.setTextColor(textColor, backgroundColor);
  //display.setTextColor(WHITE, BLACK);

  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0, 0);

} //END of   setup()


//                                        l o o p ( )
//********************************************^************************************************
//
void loop()
{
   int chk = DHT.read11(DHT11_PIN);
  //*********************************                         heartbeat TIMER
  //is it time to toggle the heartbeatLED (every 500ms)?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the heartbeat LED
    digitalWrite(heartbeatLED, digitalRead(heartbeatLED) == HIGH ? LOW : HIGH);
  }

  //*********************************                         displayTime TIMER
  //is time to update the display ?
  if (millis() - displayTime >= 250ul)
  {
    //restart this TIMER
    displayTime = millis();

    //clear SSD1306 display
    display.clearDisplay();

    //************************************
    display.setTextSize(1);
    display.setCursor(0, 0);

    //Size 1 line is  000000000111111111122
    //21 characters   123456789012345678901
    //Example         ..OLED Counter Demo..
    display.print("  OLED Counter Demo  ");

    //************************************
    //display.setCursor(0,9);
    //Size 1 line is  000000000111111111122
    //21 characters   123456789012345678901
    //display.print ("ABCDEFGHIJKLMNOPQRSTU");

    //************************************
    display.setTextSize(2);
    //2 = current text size, 16 is the pixel row we want to postion to
    display.setCursor(centering(counter, 2), 15);

    //Size 2 line     0000000001
    //10 characters   1234567890
    //Example           100000
    display.print(counter++);
    display.setTextSize(1);
    display.setCursor(0,30);
    display.print("Humidity (%): ");
    display.print(DHT.humidity);
    display.setCursor(0,40);
    display.print("Temp (C): ");
    display.print(DHT.temperature);
    //************************************
    //degree symbol
    //using CP437 ASCII
    //display.cp437(true);
    //display.write(248);

    //************************************
    //  display.setTextSize(2);
    //  display.setCursor(0,16);
    //  display.setCursor(0,32);
    //  //temperature
    //  //Size 2 line is  0000000001
    //  //10 characters   1234567890
    //  //Example         ABCDEFGHIJ
    //  display.print("ABCDEFGHIJ");

    //************************************
    display.display();
  }

  //************************************
  //other non blocking code goes here
  //************************************


} //END of   loop()


//                                 c o u n t D i g i t s ( )
//********************************************^************************************************
//return the number of digits in a number
byte countDigits(int num)
{
  byte count = 0;

  while (num)
  {
    num = num / 10;
    count++;
  }

  return count;

} //END of   countDigits()


//                                    g e t D i g i t ( )
//********************************************^************************************************
//return the selected digit
byte getDigit(unsigned int number, int digit)
{
  for (int i = 0; i < digit - 1; i++)
  {
    number = number / 10;
  }

  return number % 10;

} //END of   getDigit()


//                                   c e n t e r i n g ( )
//********************************************^************************************************
//return the position to print the MSD
byte centering(unsigned long number, byte textSize)
{
  byte count = 0;
  byte charaterCellWidth = 0;

  //a basic character is 5X7, we must scale for this text size
  charaterCellWidth = (5 * textSize) + 1;

  //number of digits in our number
  while (number)
  {
    number = number / 10;
    count++;
  }

  //center location where the MSD character will be displayed
  return (SCREEN_WIDTH / 2 - (charaterCellWidth * count / 2));

} //END of   centering()

//

Have you tried the example sketch from the DHT library? If that does not work correctly then the problem is probably not your code.

that what i used

And?

hey sorry i solved it :worried: :worried: :worried: i didnt put it to gnd and 5v sorry

1 Like