0

Pretty simple home automation project I am working on. I'm trying to hook my arduino which has a 16x2 LCD, DHT22 temp/humidity sensor to my Pi via usb. I want to be able to maintain the values on the LCD and send the values to the Pi via serial usb.

I am in Arduino IDE currently and can see the serial values in the monitor...however the LCD is all scrambled. Can someone take a look at my code and tell me what I am doing wrong?

#include <LiquidCrystal.h>
#include "DHT.h"

#define DHTPIN 8 
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup() {

  lcd.begin(16, 2);
  dht.begin();
  Serial.begin(9600);
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);


  if (isnan(h) || isnan(t) || isnan(f)) {
    lcd.print("Failed to read from DHT sensor!");
    return;
  }

  lcd.setCursor(0,0);
  lcd.print("Temp = ");
  lcd.print(f);
  lcd.setCursor(0,1);
  lcd.print("Humidity = ");
  lcd.print(h);
  lcd.clear();

  Serial.println(f);
  Serial.println(h);
}
  • First try a (demo) sketch only for the LCD to see if it works without your own code and the added additional components. – Michel Keijzers Apr 14 '18 at 17:44
  • 1
    pin 1 is TX of Serial, you can't use it for lcd – Juraj Apr 14 '18 at 17:46
  • So I just need to change the pin 1 out? – Eddie Sherman Apr 14 '18 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.