Hello all, I am very new to Arduino and I have an assignment to create a 2-digit 7-segment display that shows the current temperature.
I am using a DHT11 temperature & humidity sensor module and my board is set up like this (
http://i49.tinypic.com/157ocv7.jpg).
I have the separate integers being pulled from the sensor correctly, but for some reason the 7-segment displays show completely wrong numbers. I feel like there is a standard piece of code missing that is needed to make the display work. Any suggestions?? Thanks in advance for any help.
This is my code (tweaked from an example):
Note -- click 'Serial Monitor' to see the data.
#include <dht11.h>
dht11 DHT11;
void setup()
{
DHT11.attach(2);
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
}
void loop()
{
Serial.println("\n");
int chk = DHT11.read();
Serial.print("Read sensor: ");
switch (chk)
{
case 0:
Serial.println("OK");
break;
case -1:
Serial.println("Checksum error");
break;
case -2:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, DEC);
Serial.print("Temperature (°C): ");
Serial.println((float)DHT11.temperature, DEC);
Serial.print("Temperature (°F): ");
Serial.println(DHT11.fahrenheit(), DEC);
Serial.print("Temperature (°K): ");
Serial.println(DHT11.kelvin(), DEC);
Serial.print("Dew Point (°C): ");
Serial.println(DHT11.dewPoint(), DEC);
Serial.print("Dew PointFast (°C): ");
Serial.println(DHT11.dewPointFast(), DEC);
int temp = DHT11.fahrenheit();
int digitOne = temp / 10;
int digitTwo = temp % 10;
// This is to make sure the correct numbers are being pulled
Serial.println(temp);
Serial.println(digitOne);
Serial.println(digitTwo);
pinMode(digitOne, OUTPUT);
pinMode(digitTwo, OUTPUT);
delay(5000);
}