need help converting temperature to Fahrenheit

I have a DHT11 sensor that i'm using with Arduino and displaying the output on an LCD. However the

DHT11 measures temperature in Celsius and I want it in Fahrenheit but I'm not good with codes so I

have no idea how or where to edit it to convert the temperature.

Here is my code below, I appreciate any help I can get.

#include <DHT11.h>
int pin=8;
DHT11 dht11(pin); 
void setup()
{
   Serial.begin(9600);
  while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
}

void loop()
{
  int err;
  float temp, humi;
  if((err=dht11.read(humi, temp))==0)
  {
    Serial.print("temperature:");
    Serial.print(temp);
    Serial.print(" humidity:");
    Serial.print(humi);
    Serial.println();
  }
  else
  {
    Serial.println();
    Serial.print("Error No :");
    Serial.print(err);
    Serial.println();    
  }
  delay(DHT11_RETRY_DELAY); //delay for reread
}

I still need help with the question I posted, and I know how to anwser this one, so I'm going to fix this for you, and hope the other guys that know a lot a good deal about programing will use their valuable time to look into harder questions. This is something Google would have solved.

Your temp (temp) is measured in C. To convert simply do the math

#include <DHT11.h>
int pin=8;
DHT11 dht11(pin); 
float tempF = 0.0; // -------------------------------------------------------add this
void setup()
{
   Serial.begin(9600);
  while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
}

void loop()
{
  int err;
  float temp, humi;
  tempF = ((temp) x  9/5) + 32 // ------------------------------Math here
  if((err=dht11.read(humi, temp))==0)
  {
    Serial.print("temperature:");
   // Serial.print(temp); // -------------------------------------We don't want this
    Serial.print(tempF); // --------------------------------------This is what we want
    Serial.print(" humidity:");
    Serial.print(humi);
    Serial.println();
  }
  else
  {
    Serial.println();
    Serial.print("Error No :");
    Serial.print(err);
    Serial.println();    
  }
  delay(DHT11_RETRY_DELAY); //delay for reread
}

Thanks for taking the time to help me. I did what you said and this is the error message i'm getting:

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows Vista), Board: "Arduino Uno"
dht11_read_code:4: error: expected constructor, destructor, or type conversion before '=' token
dht11_read_code.ino: In function 'void loop()':
dht11_read_code:17: error: 'tempF' was not declared in this scope
dht11_read_code:18: error: expected `;' before 'if'
dht11_read_code:26: error: 'else' without a previous 'if'

Here's the code after your suggestion

#include <DHT11.h>
int pin=8;
DHT11 dht11(pin); 
tempF = 0;
void setup()
{
   Serial.begin(9600);
  while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
}

void loop()
{
  int err;
  float temp, humi;
  tempF = (temp * (9/5))+32
  if((err=dht11.read(humi, temp))==0)
  {
    Serial.print("temperature:");
    Serial.print(tempF);
    Serial.print(" humidity:");
    Serial.print(humi);
    Serial.println();
  }
  else
  {
    Serial.println();
    Serial.print("Error No :");
    Serial.print(err);
    Serial.println();    
  }
  delay(DHT11_RETRY_DELAY); //delay for reread
}

I updated the mistake seconds after I posted it to include float before tempF. I got a little excited, this was the first post I knew the answer to, and got a little ahead of myself. My apologizes.

You saved my life man. I really appreciate it, thank you very much. Here's the final working code below
I just ran it and it's working fine and accurately.

#include <DHT11.h>
int pin=8;
DHT11 dht11(pin); 
float tempF = 0.0;
void setup()
{
   Serial.begin(9600);
  while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
}

void loop()
{
  int err;
  float temp, humi;
  tempF = ((temp) * 9/5)+32;
  if((err=dht11.read(humi, temp))==0)
  {
    Serial.print("temperature F:");
    Serial.print(tempF);
    Serial.print(" humidity:");
    Serial.print(humi);
    Serial.println();
  }
  else
  {
    Serial.println();
    Serial.print("Error No :");
    Serial.print(err);
    Serial.println();    
  }
  delay(DHT11_RETRY_DELAY); //delay for reread
}

glad I could help.

It's kind of nice to have the privilege of returning the favor to someone else.

If you want to take the added .0 off the end of the reading , just change float tempF to int tempF

Later,
Thomas

If you place this in a tight loop, you might try:

#define TEMPCONSTANT 1.8     // This is 9 / 5

// ...rest of code to...

 tempF = ((temp) * TEMPCONSTANT) + 32.0;

Division is one of the slowest operations you can do and adding the ".0" to 32 tells the compiler to use float data types when resolving the expressions.

Also, if you define temp in loop(), how does it ever get set to a meaningful value for use in the equation?

adding the ".0" to 32 tells the compiler to use float data types when resolving the expressions.

That only applies to the portion that involves the addition.

The fact that the TEMPCONSTANT value is not integral is what forces the multiplication to be done using floating point math. If it was an integral value, integer math would have been used, and then a floating point addition performed.