Covert degrees C to degrees F LCD display

Not proficient in any coding (besides Basic & Boolean from 20 yrs ago). Retired and just playing around.

I have managed to get Temp & Humidity to display correctly in the serial monitor (degree symbol (176) appears as a square so disabled line.

On my 16x2 LCD I2c the display reads Temp: 24.9076.82 and for the life of me cannot remove the degree C (I figure it is the default for the DHT11).

Here’s part of my code: What am I missing?

<void setup()
{
//Initialize serial port
Serial.begin(9600);
Serial.println(“DHT11 sensor testing”);
dht.begin();
lcd.begin(16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);

//Initialize the DHT sensor
dht.begin();
}

void loop()
{
int tempReading = analogRead(tempPin);
float converted = 0.0;

//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();

//Fahrenheit
//T(°F) = T(°C) × 9/5 + 32
converted = ( temp * 1.8 ) + 32;
Serial.print(“Temp : “);
Serial.print(converted);
//Print degree symbol
//Serial.write( 176);
Serial.println(” F”);
Serial.print("Humidity ");
Serial.println(hum);

converted = ( temp * 1.8 ) + 32;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: “);
lcd.print(temp);
lcd.print(converted);
lcd.print(” ");
//lcd.print((char)176);
lcd.print(“F”);
lcd.setCursor(0,1);
lcd.print(“Hum: “);
lcd.print(hum);
lcd.print(” %”);

//2000mS delay between reads>

What am I missing?

  1. Code tags.
  2. The rest of the code.

Hi,

Here’s a working example:

/* YourSmartDuino-EM  EZP-TEMPERATURE-HUMIDITY
  - WHAT IT DOES: Measures and displays Temperature and Humidity
  - Changes from C to F with a switch
  - Uses the KEYES Easy-Plug Modules

  - V3. 2/13/2019
   Questions: terry@yourduino.com
  - SEE the comments after "//" on each line below
  - CONNECTIONS: KEYES Easy-Plug Control Board V2.0
    NOTE: Different Software examples use a different sets of modules.


  /*-----( Import needed libraries )-----*/

// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

#include <dhtnew.h>     // DHT11 Temperature-Humidity Sensor 
// [Rob Tillaart's new version: It finds out what module is being used

/*----------------( Declare Constants and Pin Numbers )-------------------*/
#define LED_MODULE_PIN    6
#define BUZZER_PIN        7
#define ONBOARD_LED_PIN   13

//----( DIGITAL INPUT Pins)----
#define SWITCH_PIN        A3   // Used for a variety of On-OFF Devices
#define DHT11_PIN         8    // Temperature/Humidity Sensor

//------( LOCAL DEFINITIONS )---------
#define ON       1
#define OFF      0

/*--------------------( Declare objects )-------------------------*/
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);   // Define the LCD Display
DHTNEW Temp_Humid_Sensor(DHT11_PIN);   // Define the DHT11 Temperature / humidity sensor

/*------------------------( Declare Variables )-----------------------------------*/
float temperatureC;
float temperatureF;
float humidityPercent;

boolean TempIsC = true;   // For switching between C and F


void setup()   /******************* SETUP: RUNS ONCE *************************/
{
  Serial.begin(115200);        // Start up the Serial Monitor

  lcd.begin(16, 2);  // initialize the lcd for 16 chars 2 lines, turn on backlight
  lcd.noBacklight();
  delay(500);
  lcd.backlight(); // finish with backlight on

  lcd.setCursor(0, 0); //Start at character 0 on line 0
  lcd.print(F("YourSmart!Duino"));
  lcd.setCursor(0, 1); //Start at character 0 on line 0
  lcd.print(F("YourDuino.com"));
  //
  pinMode(LED_MODULE_PIN, OUTPUT);
  pinMode(ONBOARD_LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(SWITCH_PIN, INPUT_PULLUP);

  Serial.println("Option 4: Temperature / Humidity");

  lcd.setCursor(0, 0); //Start at character 0 on line 0
  //-----------1234567890123456----------
  lcd.print(F("4: Temp-Humidity"));
  lcd.setCursor(0, 1); //Start at character 0 on line 1
  lcd.print(F("DHT11 Sensor "));

  delay(2000);
}//--(end setup )---


void loop()   /********************** LOOP: RUNS CONSTANTLY ************************/
{

  /*-------------( Option 4 )---------------

          User connects:
          switch to A3
          DHT11 Temperature/Humidity sensor to D8
          LCD display to I2C
  */

  Temp_Humid_Sensor.read();
  delay(1000);
  lcd.setCursor(0, 0); //Start at character 0 on line 0
  lcd.print("Humidity   = ");
  humidityPercent = Temp_Humid_Sensor.humidity;
  lcd.print(humidityPercent, 0);
  lcd.print("%");

  if (digitalRead(SWITCH_PIN ) == OFF)  //Active pushbutton
    TempIsC = true;
  else
    TempIsC = false;

  if (TempIsC == true)
  {
    lcd.setCursor(0, 1); //Start at character 0 on line 1
    lcd.print("Temperature= ");
    temperatureC = Temp_Humid_Sensor.temperature;
    lcd.print(temperatureC, 0);
    lcd.print("C");
  }
  else
  {
    lcd.setCursor(0, 1); //Start at character 0 on line 1
    lcd.print("Temperature= ");
    temperatureC = Temp_Humid_Sensor.temperature;
    temperatureF = (temperatureC * (9.0 / 5.0)) + 32.0;
    lcd.print(temperatureF, 0);
    lcd.print("F");
  }

}//--(end main loop )---


/*--------------------( Declare User-written Functions )------------------------*/
//NONE
//*********( THE END )***********

Here’s the part where you print to the LCD

converted = ( temp * 1.8 ) + 32;  
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Temp: ");
 lcd.print(temp);                // <----- try removing this line
 lcd.print(converted);
 lcd.print(" ");
 //lcd.print((char)176);
 lcd.print("F");
 lcd.setCursor(0,1);
 lcd.print("Hum:  ");
 lcd.print(hum);
 lcd.print(" %");

I don’t think you need to print both temp and converted.

You are printing Temp: then temp and then converted to the LCD. 24.90 is Celsius, 76.82 is Fahrenheit

Steve

PaulS:

  1. Code tags.
  2. The rest of the code.

Will post entire code next time, my apologies and was my first real request for help here!

was my first real request for help here!

Then have a look at this from the stickies at the top of the forum page:

Read this before posting a programming question ...

GypsumFantastic:
Here’s the part where you print to the LCD

converted = ( temp * 1.8 ) + 32;  

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: “);
lcd.print(temp);                // <----- try removing this line
lcd.print(converted);
lcd.print(” ");
//lcd.print((char)176);
lcd.print(“F”);
lcd.setCursor(0,1);
lcd.print(“Hum:  “);
lcd.print(hum);
lcd.print(” %”);




I don't think you need to print both temp and converted.

Thank you Gypsum, that fixed it.

evanmars:
Then have a look at this from the stickies at the top of the forum page:

Read this before posting a programming question ...

I read through the stickies B4 posting, apparently I missed something!

Care to reference?

terryking228:
Hi,

Here’s a working example:

/* YourSmartDuino-EM  EZP-TEMPERATURE-HUMIDITY

- WHAT IT DOES: Measures and displays Temperature and Humidity
 - Changes from C to F with a switch
 - Uses the KEYES Easy-Plug Modules

- V3. 2/13/2019
  Questions: terry@yourduino.com
 - SEE the comments after “//” on each line below
 - CONNECTIONS: KEYES Easy-Plug Control Board V2.0
   NOTE: Different Software examples use a different sets of modules.

/-----( Import needed libraries )-----/

// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library “Docs” folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

#include <dhtnew.h>     // DHT11 Temperature-Humidity Sensor
// [Rob Tillaart’s new version: It finds out what module is being used

/----------------( Declare Constants and Pin Numbers )-------------------/
#define LED_MODULE_PIN    6
#define BUZZER_PIN        7
#define ONBOARD_LED_PIN   13

//----( DIGITAL INPUT Pins)----
#define SWITCH_PIN        A3   // Used for a variety of On-OFF Devices
#define DHT11_PIN         8    // Temperature/Humidity Sensor

//------( LOCAL DEFINITIONS )---------
#define ON       1
#define OFF      0

/--------------------( Declare objects )-------------------------/
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);   // Define the LCD Display
DHTNEW Temp_Humid_Sensor(DHT11_PIN);   // Define the DHT11 Temperature / humidity sensor

/------------------------( Declare Variables )-----------------------------------/
float temperatureC;
float temperatureF;
float humidityPercent;

boolean TempIsC = true;   // For switching between C and F

void setup()   /******************* SETUP: RUNS ONCE *************************/
{
 Serial.begin(115200);        // Start up the Serial Monitor

lcd.begin(16, 2);  // initialize the lcd for 16 chars 2 lines, turn on backlight
 lcd.noBacklight();
 delay(500);
 lcd.backlight(); // finish with backlight on

lcd.setCursor(0, 0); //Start at character 0 on line 0
 lcd.print(F(“YourSmart!Duino”));
 lcd.setCursor(0, 1); //Start at character 0 on line 0
 lcd.print(F(“YourDuino.com”));
 //
 pinMode(LED_MODULE_PIN, OUTPUT);
 pinMode(ONBOARD_LED_PIN, OUTPUT);
 pinMode(BUZZER_PIN, OUTPUT);
 pinMode(SWITCH_PIN, INPUT_PULLUP);

Serial.println(“Option 4: Temperature / Humidity”);

lcd.setCursor(0, 0); //Start at character 0 on line 0
 //-----------1234567890123456----------
 lcd.print(F(“4: Temp-Humidity”));
 lcd.setCursor(0, 1); //Start at character 0 on line 1
 lcd.print(F("DHT11 Sensor "));

delay(2000);
}//–(end setup )—

void loop()   /********************** LOOP: RUNS CONSTANTLY ************************/
{

/*-------------( Option 4 )---------------

User connects:
         switch to A3
         DHT11 Temperature/Humidity sensor to D8
         LCD display to I2C
 */

Temp_Humid_Sensor.read();
 delay(1000);
 lcd.setCursor(0, 0); //Start at character 0 on line 0
 lcd.print(“Humidity   = “);
 humidityPercent = Temp_Humid_Sensor.humidity;
 lcd.print(humidityPercent, 0);
 lcd.print(”%”);

if (digitalRead(SWITCH_PIN ) == OFF)  //Active pushbutton
   TempIsC = true;
 else
   TempIsC = false;

if (TempIsC == true)
 {
   lcd.setCursor(0, 1); //Start at character 0 on line 1
   lcd.print("Temperature= ");
   temperatureC = Temp_Humid_Sensor.temperature;
   lcd.print(temperatureC, 0);
   lcd.print(“C”);
 }
 else
 {
   lcd.setCursor(0, 1); //Start at character 0 on line 1
   lcd.print("Temperature= ");
   temperatureC = Temp_Humid_Sensor.temperature;
   temperatureF = (temperatureC * (9.0 / 5.0)) + 32.0;
   lcd.print(temperatureF, 0);
   lcd.print(“F”);
 }

}//–(end main loop )—

/--------------------( Declare User-written Functions )------------------------/
//NONE
//( THE END )**

Thank you Terry, had some debug errors that are beyond my ability but will research your methods down the road after the basics.

JMcGraw:
I read through the stickies B4 posting, apparently I missed something!

Care to reference?

Disregard, found the section regarding Code Tags.

Hi,

had some debug errors

Sorry!
Latest Rob Tillart library etc. here:

https://arduinoinfo.mywikis.net/wiki/DHT11-Humidity-TempSensor

download the .zip