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