Hey,
So I've been working on a humidity and temperature sensor for my 3d printer enclosure, and it seems to work.
But after a few minutes, the display starts to display random characters. I'm currently using a usb cord to power the Nano. I have the usb plugged into a surge protector with 2 usb slots. After some research I found people suggesting adding a capacitor between the power and ground in order to fix this problem, but it hasn't seemed to change anything for me.
This diagram attached is the exact wiring I'm using. The capacitor is 1uF, while the resistor is 4.7k ( if you can't tell).
This is the code I'm using, but it doesn't seem to be a code problem, considering the program itself seems to have no problem running. The only thing I'm skeptical about is the delays.
#include "DHT.h" //including the dht22 library
#include "LiquidCrystal.h"
#define DHTPIN 2 //Declaring pin 9 of arduino for the dht22
#define DHTTYPE DHT22 //Defining which type of dht22 we are using (DHT22 or DHT11)
DHT dht(DHTPIN, DHTTYPE); //Declaring a variable named dht
LiquidCrystal lcd(9,8,7,6,5,4); // Initializing the LCD pins.
void setup() { //Data written in it will only run once
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
dht.begin(); //This command will start to receive the values from dht22
}
void loop() { //Data written in it will run again and again
lcd.clear();
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float temp = dht.readTemperature(true); //Reading the temperature as Celsius and storing in temp
// Check if any reads failed and exit early (to try again).
if (isnan(hum) || isnan(temp)) {
lcd.print("Failed to read");
delay(2200);
return;
}
lcd.setCursor(0,0); //Setting the cursor at the start of the LCD
lcd.print("Temp.: "); //Writing the temperature on the LCD
lcd.print(temp); //Writing the value of temperature on the LCD
lcd.print(" F");
lcd.setCursor(0,1); //setting the cursor at next line
lcd.print("Humi.: "); //Writing the humidity on the LCD display
lcd.print(hum); //Writing the humidity value stored in hum on the LCD display
lcd.print(" %");
delay(2200);
}
So if anyone has suggestions for why this might be happening, and how to fix it, that'd be great.
Thanks!