Pages: [1]   Go Down
Author Topic: Creating a 2-digit 7-Segment Display for Temperature  (Read 1334 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:

#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);
}
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
 pinMode(digitOne, OUTPUT);
  pinMode(digitTwo, OUTPUT);

}

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?
« Last Edit: October 24, 2012, 02:45:09 pm by Arrch » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
 pinMode(digitOne, OUTPUT);
  pinMode(digitTwo, OUTPUT);

}

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 (http://www.futurlec.com/74LS/74LS47.shtml).
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not sure what kind of resistors are driving the LEDs, but this is the datasheet (http://www.futurlec.com/74LS/74LS47.shtml).

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.
« Last Edit: October 24, 2012, 03:24:58 pm by Arrch » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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?
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you go about finding the correct pin number?

By looking at what pin you plugged it into on the Arduino.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you go about finding the correct pin number?

By looking at what pin you plugged it into on the Arduino.

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?

I have written this:

Code:
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);
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
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.
Logged

Pages: [1]   Go Up
Jump to: