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);
}
I take it this is where you are trying to set the 7 segment LEDs? That's not what pinMode() is for. What are you using to drive the LEDs? Are those ICs shift registers? Link to the 7-Segment datasheet?
I take it this is where you are trying to set the 7 segment LEDs? That's not what pinMode() is for. What are you using to drive the LEDs? Are those ICs shift registers? Link to the 7-Segment datasheet?
I am not sure what kind of resistors are driving the LEDs, but this is the datasheet (74LS47 Datasheet).
RookieOfTheYear:
I am not sure what kind of resistors are driving the LEDs, but this is the datasheet (74LS47 Datasheet).
So you need to connect 4 pins per segment to the Arduino and send the binary code to those four pins. The simple way to do it would be to use digitalWrite() individually. Another (better in my opinion) way would be to use port manipulation. But I don't see how you think that code can drive the LEDs when nowhere in that sketch do you specify what pins the decoders are hooked up to.
Arrch:
So you need to connect 4 pins per segment to the Arduino and send the binary code to those four pins. The simple way to do it would be to use digitalWrite() individually. Another (better in my opinion) way would be to use port manipulation. But I don't see how you think that code can drive the LEDs when nowhere in that sketch do you specify what pins the decoders are hooked up to.
Okay, thanks. I am looking into that as we speak. How do you go about finding the correct pin number?
RookieOfTheYear:
So if the pins used for the values are (3,4,5,6) and (7,8,9,10), what syntax would I use to assign those?
The C++/Arduino syntax.
You use the digitalWrite() function to set the pins as HIGH or LOW. You can use bitRead() function to extract the binary bits that need to be set for each of the pins.
int pinOne = 3;
int pinTwo = 7;
pinMode(pinOne, OUTPUT);
pinMode(pinTwo, OUTPUT);
int digitOne = temp / 10;
int digitTwo = temp % 10;
Serial.println(temp);
Serial.println(digitOne);
Serial.println(digitTwo);
digitalWrite(pinOne, HIGH);
digitalWrite(pinTwo, HIGH);
What is this supposed to do exactly? All this does is determine the digits, print them out to the Serial monitor and set pins 3 and 7 HIGH.