Got dht working.
This commit is contained in:
parent
38affc3c98
commit
8bd54f6e73
1 changed files with 17 additions and 21 deletions
|
@ -1,12 +1,14 @@
|
|||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include <dht11.h>
|
||||
#include <DHT.h>
|
||||
|
||||
#define DHT11_PIN 7
|
||||
#define photos A0
|
||||
#define LED 3
|
||||
#define button 2
|
||||
#define buzzer 6
|
||||
|
||||
DHT dht(DHT11_PIN, DHT11);
|
||||
volatile int buttonState;
|
||||
volatile int value = 0;
|
||||
int count;
|
||||
|
@ -26,6 +28,9 @@ void setup()
|
|||
lcd.printstr("Hello, World!");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.printstr("hello, Roald!");
|
||||
|
||||
dht.begin();
|
||||
|
||||
Serial.print("done setting up!\n");
|
||||
}
|
||||
|
||||
|
@ -35,25 +40,18 @@ void loop()// the loop function runs over and over again forever
|
|||
Serial.print(count);
|
||||
Serial.print("] hey\n");
|
||||
|
||||
int chk;
|
||||
chk = DHT.read(DHT11_PIN);
|
||||
switch (chk) {
|
||||
case DHTLIB_OK:
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
float hum;
|
||||
float temp;
|
||||
temp = dht.readTemperature();
|
||||
hum = dht.readHumidity();
|
||||
{
|
||||
Serial.print("humidity:");
|
||||
Serial.print(DHT.humidity);
|
||||
Serial.print(" temperature:");
|
||||
Serial.println)DHT.temperature);
|
||||
delay(200);
|
||||
Serial.print("humidity:");
|
||||
Serial.print(hum);
|
||||
Serial.print(" temperature:");
|
||||
Serial.println(temp);
|
||||
delay(200);
|
||||
}
|
||||
|
||||
value = analogRead(photos);
|
||||
Serial.println(value);
|
||||
if (value > 300){
|
||||
|
@ -66,7 +64,6 @@ void loop()// the loop function runs over and over again forever
|
|||
|
||||
//blink();
|
||||
|
||||
|
||||
buttonState = digitalRead(button);
|
||||
if(buttonState == 0) {
|
||||
digitalWrite(LED, HIGH);
|
||||
|
@ -76,9 +73,8 @@ void loop()// the loop function runs over and over again forever
|
|||
}
|
||||
delay(100);
|
||||
|
||||
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
void birthdaySong() {
|
||||
tone(buzzer, 294);
|
||||
|
|
Loading…
Reference in a new issue