LCD producing weird, but not random, characters

So Im building a weather station. It has a LCD installed and a push button to swap from LCD output to serial output.

For this I have a transistor connected to 5v and a certain digital pin. This powers the LCD. but the LCD is just outputting weird characters.

(image posted above)

But it only ever shows this string of characters, its not random. My code is here if you need it

#include <dht_nonblocking.h>
#include <LiquidCrystal.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
#include <math.h>

bool mobile = true;
bool pressed = false;
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
  pinMode(5, INPUT);
  pinMode(3, OUTPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop() {
  float temperature;
  float humidity;

  if (digitalRead(5) == HIGH && !pressed) { // if the button is pressed
    pressed = true;
    if (mobile) {
      mobile = false;  // toggle mobile mode (LDC being on)
    } else {
      mobile = true;
    }
  } else if (digitalRead(5) == LOW) {
    pressed = false;
  }

  if (mobile) {
    digitalWrite(3, HIGH);  //write transistor power pin high to power the LCD
  } else {
    lcd.clear();
    digitalWrite(3, LOW);
  }

  if (dht_sensor.measure(&temperature, &humidity)) { // weather stuff
    if (mobile && int(millis()) > 5000) {
      lcd.setCursor(0, 0);
      lcd.print("Temperature: " + String(round((temperature * 1.8) + 32)));
      lcd.setCursor(0, 1);
      lcd.print("Humidity: " + String(round(humidity)));
    }

    if (!mobile) {
      Serial.print( (temperature * 1.8) + 32, 1 );
      Serial.print(":");
      Serial.print( humidity, 1 );
      Serial.println();
    }
  }
}


OK, a few things here.

Why are you wanting to muck about "powering the LCD"? You do not turn the LCD itself on and off. else you will not have it properly initialised. It sounds as if your transistor is not properly powering it in any case if it is an NPN transistor with base connected to an output pin and collector to 5 V. You need to provide a schematic diagram of how you have wired this.

If you wish such as to reduce the current consumption of your system, to switch off the backlight, then you can use a transistor to do that or in fact if on your module resistor "R8" is "101" or 100 Ohm, then you can control just the backlight (pin 15) directly with an Arduino pin.

If you are concerned about current consumption, then the current used by the actual LCD itself can be nearly halved (to less than 1 mA) by correcting a persistent mistake in published circuits where the 10k contrast potentiometer has one end connected to 5 V. Disconnect that end and in fact, given that you have a 10k potentiometer, just connecting both ends to ground will make contrast setting easier, the wiper of course going to pin 3 of the display and pin 2 connected directly to 5 V.

Having made these corrections, run the standard "Hello World" test code and see what happens. :grinning:

This topic was automatically closed after 120 days. New replies are no longer allowed.