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();
}
}
}
