code question.... coding a beginners simple weather station need help

There is something off in my code & I cant figure out what it is, i am a beginner coding arduinos.

  1. The LCD is not printing what I want in the write way. I want the first line to read off the temperature from the DHT11 and display on the LCD with “F” at the end of degree symbol for “Fahrenheit”. The 2nd line on the LCD should read the humidity percentage… I want the percent symbol on the LCD after the number. It keeps looping one after another in the same line. I know it is in the loop method but I couldnt get it to work inside the setup function.

  2. I want the temp and humidity to be read every 2 seconds and display that result.

3)How would I send numbers digit by digit converting to ASCII to display as character

I will attach a picture of my LCD problem and my code…thanks
#include <LiquidCrystal.h>
#include<DHT.h>

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

int maxTime = 1600;
#define DHTPin 2
#define DHTType DHT11
DHT dht (DHTPin, DHTType );

void setup() {
Serial.begin( 9600 );
dht.begin();
lcd.begin(16, 2);
lcd.print(“Loading…”);
delay(4000);
lcd.clear();
lcd.setCursor(0, 1);

Serial.println(“DHT monitor starting up!”);
Serial.println(“Starting up…”);
}

float humidity, temperature;

void loop() {

delay( 2000 );
float temperature = dht.readTemperature(true);
float humidity = dht.readHumidity();

lcd.print("Temp(F): ");
lcd.print(int(temperature));
lcd.print((char)223);

lcd.print("Humidity: ");
lcd.print(int(humidity));

if (readDHT(&temperature, &humidity)) {
//print to serial monitor
Serial.print("Temp: “);
Serial.print(temperature);
Serial.print(” Humidity : ");
Serial.println(humidity);
}
else {
Serial.print(“Oops”);
}
}
boolean readDHT(float* temperature, float* humidity) {
int values[80];

pinMode(DHTPin, OUTPUT);
digitalWrite(DHTPin, LOW);
delay(18);

digitalWrite(DHTPin, HIGH);
delayMicroseconds(40);

pinMode(DHTPin, INPUT_PULLUP);
delayMicroseconds(10);

int lowResponse = readCycle(LOW);
int highResponse = readCycle(HIGH);
if ( lowResponse == 0 || highResponse == 0 )
{
Serial.println(“Oops, Reading response low”);
return false;

}
for (int i = 0; i < 40; i++) {
values[2 * i] = readCycle (LOW);
values[2 * i + 1] = readCycle(HIGH);
}

byte highHumidity;
byte lowHumidity;
byte highTemperature;
byte lowTemperature;
byte checkSum;

highHumidity = assembleByte(values, 0);
lowHumidity = assembleByte(values, 8);

highTemperature = assembleByte(values, 16);
lowTemperature = assembleByte(values, 24);

checkSum = assembleByte(values, 32);
if (checkSum != highHumidity + lowHumidity + highTemperature + lowTemperature) {
Serial.println(“Checksum bogus”);
return false;
}

*humidity = (float)highHumidity;
*temperature = (float)highTemperature;
return true;

}

byte assembleByte(int* arr, int index) {
byte val = 0;
for (int i = index; i < index + 8; i++) {
val <<= 1;
if (arr[2 * i + 1] > arr[2 * 1])
{
val |= 0x01;

}
}
return val;
}

int readCycle(boolean state) {
int count = 0;
while (digitalRead(DHTPin) == state) {
count++;
if (count >= maxTime)
return 0;
}
return count;

}

WeatherStation.ino (2.4 KB)

Hi MChillington,

In the loop section of your sketch I notice:

lcd.print("Temp(F): "); lcd.print(int(temperature)); lcd.print((char)223);

lcd.print("Humidity: "); lcd.print(int(humidity));

Because in Setup section yu have defined

lcd.setCursor(0, 1);

the LCD will start displaying text or parm values on the first line position zero

Suggestion is to change the loop section frament into something like

lcd.setCursor (0,1); lcd.print("Temp(F): "); lcd.print(int(temperature)); lcd.print((char)223);

lcd.setCursor (1,1); lcd.print("Humidity: "); lcd.print(int(humidity));

Actually this will print every cycle text and parm value since "humidity" and "Temp(F)" need to be printed once this action can be moved to the Setup section.

Setup could look like this: void setup() { Serial.begin( 9600 ); dht.begin(); lcd.begin(16, 2); lcd.print("Loading..."); delay(4000); lcd.clear(); lcd.setCursor(0, 1); lcd.print("Temp(F): "); lcd.setCursor (1,1); lcd.print("Humidity: "); Serial.println("DHT monitor starting up!"); Serial.println("Starting up..."); }

and in Loop: lcd.setCursor(10,0); lcd.print(int(temperature)); lcd.print((char)223); lcd.setCursor(10, 1); lcd.print(int(humidity));