I am a relative noob and in need of some guidance. I am working from the book "Arduino Workshop" by John Boxall. I am working on project 12 which is to make a temp sensor display to the serial monitor using functions.
So far I am able to get the program to run but the temps don't seem right. Instead of Celsius and Fahrenheit I get some weird numbers like 449.51 deg C and 841.12 deg F. I suspect the conversion part of the code (posted below) is off. I am using a DHT11 3 pin temp/humidity sensor. Some guidance on where to look in my code or what should I looking at to do a proper converson.
thanks
John G.
Code:
//Project 12 - Display temp in serial monitor
#include <dht.h>
dht DHT;
float celsius = 0;
float fahrenheit = 0;
void setup()
{
Serial.begin(9600);
}
void findTemps()
{
float voltage = 0;
float sensor = 0;
// read the temp sensor and convert the result to degrees C & F
sensor = analogRead(0);
voltage = (sensor * 5000) / 1024; //covert the raw data to millivolts
voltage = voltage - 500; //remove the voltage offset
celsius = voltage /10; //convert millivots to celsius
fahrenheit = (1.8 * celsius )+ 32; //convert celsius to fahrenheit
}
void displayTemps()
{
Serial.print("Temp is ");
Serial.print(celsius, 2);
Serial.print(" deg. C/");
Serial.print(fahrenheit, 2);
Serial.println(" deg. F/");
//use prinln here so the next reading starts on a new line
}
void loop()
{
findTemps();
displayTemps();
delay(1000);
}
This is a digital type sensor, and it produces digital data for Temperature and Humidity; but, your codes are processing analog signals.
Try to run the following sketch (tested on UNO):
#include <dht.h>
dht DHT;
#define DHT11_PIN 2
void setup()
{
Serial.begin(9600);
}
void loop()
{
delay(2000); //Delay 2 sec.
//Read data and store it to variables hum and temp
DHT.read11(DHT11_PIN);
int hum = DHT.humidity;
int temp = DHT.temperature;
Serial.print("Humidity is = ");
Serial.println(hum);
Serial.print("Temperature is = ");
Serial.println(temp);
Serial.println("===========================");
}
/*
example 2.1 - digital thermometer
Created 14/04/2010 --- By John Boxall --- http://tronixstuff.com --- CC by-sa v3.0
Uses an Analog Devices TMP36 temperature sensor to measure temperature and output values to the serial connection
Pin 1 of TMP36 to Arduino 5V power socket
Pin 2 of TMP36 to Arduino analog 0 socket
Pin 3 of TMP36 to Arduino GND socket
*/
void setup()
{
Serial.begin(9600); // activate the serial output connection
}
float voltage = 0; // setup some variables
float sensor = 0;
float celsius = 0;
float fahrenheit = 0;
void loop()
{ // let's get measurin'
sensor = analogRead(0);
voltage = (sensor*5000)/1024; // convert raw sensor value to millivolts
voltage = voltage-400; // remove voltage offset
celsius = voltage/10; // convert millivolts to Celsius
fahrenheit = ((celsius * 1.8)+32); // convert celsius to fahrenheit