I'm using the DHT-11 Temperature and Humidity Sensor to make a re-mix of the Arduino Starter Kit Project 03: The Love-O-Meter on pages 43-51 in the Arduino Starter Kit Projects Book. The code for the original project is available on the Arduino IDE in File>Examples>Arduino
In the project, the sensor used is a TMP36 temperature sensor. The schematic can be found on page 44 of the Arduino Starter Kit Projects book. The only variations I made on it was to connect the Data pin of the DHT-11 to digital pin 6 instead of analog input pin 0 (A0).
I learned how to use the DHT-11 on Arduino and DHT11 Temperature Measurement: 3 Steps (with Pictures) on Instructables. Here is my code:
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const float baselineTemp = 25.00;
void setup() {
// open a serial connection to display values
Serial.begin(9600);
dht.begin();
// set the LED pins as outputs
// the for() loop saves some extra coding
for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop() {
// read the value on AnalogIn pin 0 and store it in a variable
float temperature = dht.readTemperature();
Serial.println('It is ');
Serial.print(temperature);
Serial.print(' degrees Celsius');
// if the current temperature is lower than the baseline turn off all LEDs
if (temperature < baselineTemp + 2) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} // if the temperature rises 2-4 degrees, turn an LED on
else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} // if the temperature rises 4-6 degrees, turn a second LED on
else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
} // if the temperature rises more than 6 degrees, turn all LEDs on
else if (temperature >= baselineTemp + 6) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1);
}
When I opened the serial monitor, it displayed
nan3006729472
over and over again.
I don't know what this means, but I had hoped it would display
It is [temperature] degrees Celsius
I think that the letters in the printed value may have affected the section of code where temperature is compared with baseLineTemp.
The other significant problem is that the LEDs don't light up. When I press the temperature sensor, I had hoped they would light up in proportion to my body heat, but they never even light up at all.
Here are some things that I think might be the matter:
--My code is not configured correctly
--My sensor is not exact enough to measure the difference in body temperature
--I am not connecting the sensor correctly
--My sensor is faulty
I have checked, and I do not think that these things need fixing:
--Power connection is not good
--My Arduino Board is faulty