Pages: [1]   Go Down
Author Topic: 16 x 2 display Help  (Read 194 times)
0 Members and 1 Guest are viewing this topic.
Springfield, Mass
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I am working on a sketch to display humidity and temp on a 16 x 2 display. This is only my second sketch with this display. I verified my code and fixed the errors I made. Humidity is being displayed on the bottom line instead of the top and temp does not show at all. Here is my code:

Code:
// Sketch for DHT11 humidity/temperature sensor with LCD
// Written by ladyada, public domain
// Modified by Bean

#include "DHT.h"

#define DHTPIN 2     // DHTPIN to pin 2

#define DHTTYPE DHT11   // DHT 11

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

#include <LiquidCrystal.h>

LiquidCrystal lcd (7, 8, 9, 10, 11, 12);

// LCD RS Pin to digital pin 7
// LCD Enable to digital pin 8
// LCD D4 to digital pin 9
// LCD D5 to digital pin 10
// LCD D6 to digital pin 11
// LCD D7 to digital pin 12
// LCD R/W pin to ground
// LCD 15 to 5 volts with a 220 Ohm resistor and LCD 2 to 5 volts
// LCD 16 and 1 to ground
// LCD 3 to wiper on the trimmer pot

void setup() {
  lcd.begin(16, 2);
 
 
  dht.begin();
}

void loop() {
  // Reading temperature and humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  t = (t*1.8)+32; //C to F conversion
 
  // Set cursor to column 0, line 1
  lcd.setCursor(0, 1);

  // check if returns are valid
  if (isnan(t) || isnan(h)) {
    lcd.print("Failed to read from DHT");
  } else {
    lcd.print("Humidity: ");
    lcd.print(h);
    lcd.print(" %\t");
    lcd.print("Temperature: ");
    lcd.print(t);
    lcd.print(" *F");
  }
}

I am probably missing something but can not figure out what. Any help would be appreciated!! Thanks
Logged

BCC AZ USA
Offline Offline
Edison Member
*
Karma: 35
Posts: 1212
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
lcd.setCursor(0, 1);
sets the cursor to the second line.  Lines are numbered from 0. 
you will need to setCursor(0,0) for the first line and setCursor(0,1) to display temperature.
Logged

Springfield, Mass
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks groundfungus!!!!! It is working perfect now. I kinda figured that I was missed something but didn't know what. Thanks again!!!!
Logged

Pages: [1]   Go Up
Jump to: