Go Down

Topic: DHT: Celsius to Fahrenheit Conversion (Read 23046 times) previous topic - next topic

easterly81

does anyone have lib or sektch to convert Fahrenheit Conversion with a dth11 sensor

dannable

#1
Jun 10, 2013, 07:20 pm Last Edit: Jun 10, 2013, 07:22 pm by dannable Reason: 1
For temperatures greater than zero:

Celsius * 1.8 + 32
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

el_supremo

That also works for temperatures below zero degrees C.

Pete
Don't send me technical questions via Private Message.

easterly81

how do i add that to the code

Code: [Select]
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#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)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

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)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
  }
}

el_supremo

Change this:
Code: [Select]
    Serial.print(t);
    Serial.println(" *C");


to this:

Code: [Select]
    Serial.print((int)round(1.8*t+32));
    Serial.println(" *F");


Pete
Don't send me technical questions via Private Message.

Sembazuru


Change this:
Code: [Select]
    Serial.print(t);
    Serial.println(" *C");


to this:

Code: [Select]
    Serial.print((int)round(1.8*t+32));
    Serial.println(" *F");


Pete


Not sure if the round function and casting as an int is needed... The sample code provided has the Celsius temperature stored as a float, and Serial.print() knows what to do with floats.
http://www.catb.org/jargon/html/I/I-didn-t-change-anything-.html

Jimmy60

IIRC the dht library has a method for returning either F or C.

A quick look in the library and yes.

Code: [Select]

t = dht.readTemperature();         // will return C
t =  dht.readTemperature(true);  // returns F

el_supremo

The accuracy of the DHT11 is plus or minus two degrees Celsius so printing fractions of a degree (Celsius or Fahrenheit) is pointless.

Pete
Don't send me technical questions via Private Message.

Sembazuru


The accuracy of the DHT11 is plus or minus two degrees Celsius so printing fractions of a degree (Celsius or Fahrenheit) is pointless.

Pete


Good point. But, I think Jimmy60 has the better solution (let the library deal with it).
http://www.catb.org/jargon/html/I/I-didn-t-change-anything-.html

easterly81


IIRC the dht library has a method for returning either F or C.

A quick look in the library and yes.

Code: [Select]

t = dht.readTemperature();         // will return C
t =  dht.readTemperature(true);  // returns F



Thanks just what i was looking for

Patty0465

I have the same problem changing C to F
This is my first sketch most of it from the internet
My code is a little different from the above example not sure what to change to get F
Code: [Select]
//I2C bus support
#include <Wire.h>
//I2C
#include <LiquidCrystal_I2C.h>
//OneWire bus suport
#include <OneWire.h>
//DS18B20 temperature sensor support
#include <DallasTemperature.h>
//DS18B20 sensor pin
#define ONE_WIRE_BUS 8

// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x3f, 16, 2); // set the LCD address for the LCD display

void setup()
{
  lcd.init();
  lcd.setBacklight(HIGH);; //Turns backlight on
 
  sensors.begin();
}

void loop()

  sensors.requestTemperatures();

  //Temperature Sensor #1
  float temp = sensors.getTempCByIndex(0);

  //Print first sensor results
  float temp50 = sensors.getTempCByIndex(0);  // give temp a better and unique name
  temp50 = temp50 + .4;   // If Temp is out you can add or subtract here
  //Print first sensor results
  lcd.setCursor (0, 0 );
  lcd.print("OutsideTemp ");
  lcd.print(temp50);


  //Read second sensor
  temp = sensors.getTempCByIndex(1);

  //Temperature Sensor #2
  float temp100 = sensors.getTempCByIndex(1);  // give temp a better and unique name
  temp100 = temp100 + .4;   // If Temp is out you can add or subtract here
  //Print second sensor result
  lcd.setCursor (0, 1 );

  lcd.print("Pool Temp   ");
  lcd.print(temp100);

  //Wait 0.1 sec
  delay(100);
}

septillion

What about reading the library you use...

sensors.getTempFByIndex(0);
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Bamatrainfan

IIRC the dht library has a method for returning either F or C.

A quick look in the library and yes.

Code: [Select]

t = dht.readTemperature();         // will return C
t =  dht.readTemperature(true);  // returns F

How do you read a library?  Kind new and still learning

ChrisTenone

Find the library code files (library.h, and .cpp, possibly more files as well) in the libraries folder in your arduino folder. Open the code files with a text editor, such as TextEdit (mac) or NotePad (pc). Read the contents.
What, I need to say something else too?

Go Up