I've been trying to make a weather station using a I2C LCD Display and a DHT11, I know, the DHT11 is a bit low res and all that, but it came with the kit I ordered, so it's okay.
However, I'm trying to have it display like a "title" screen, and after a 2sec delay it should proceed to say "Welcome!" and "Press to Start", and wait there until the button is pressed, and after the button is pressed it should proceed to show the temp and humidity.
However it doesn't seem to mind any of the functions added, unless I set the "if" statement at the beginning of the loop to "LOW", then for some reason, the program stops at "Welcome!" and "press to start". If I change the "if" statement condition to "HIGH" it just proceeds straight through to the temp and humidity.
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//CONSTANTS
#define DHTPIN 3
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
const int buttonPin = 6;
int buttonState = 1;
void setup()
{
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
dht.begin();
lcd.begin();
lcd.clear();
delay(1000);
lcd.setCursor(0, 0);
lcd.print("WeatherMate");
lcd.setCursor(0, 1);
delay(250);
lcd.print("Press 'Start'");
delay(1000);;
if (buttonState = 0)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome!");
lcd.setCursor(0, 1);
lcd.print("Press Start");
}
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState = 1) {
delay(500);
hum = dht.readHumidity();
temp = dht.readTemperature();
if (temp <= 25) {
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
if (temp >= 25) {
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
}
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" ");
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Hum: ");
lcd.print(hum);
lcd.print(" %");
delay(500); //Delay 2 sec.
}
}
Anyone? I'm stuck on this one.