Last active
June 7, 2019 00:01
-
-
Save MindstormFan/4a5ab2648ff8871ccf16ff2cc33dd66b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SimpleDHT.h> | |
#include <LiquidCrystal.h> | |
#include "pitches.h" | |
// for DHT11, | |
// VCC: 5V or 3V | |
// GND: GND | |
// DATA: 2 | |
int pinDHT11 = 2; | |
SimpleDHT11 dht11; | |
int melody[] = {NOTE_B0, NOTE_DS8}; | |
int duration = 1500; // 1500 miliseconds | |
int buzzer = 5;//the pin of the passive buzzer | |
// initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// Print a message to the LCD. | |
lcd.print("The temp is: "); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
Serial.println("================================="); | |
Serial.println("Sample DHT11..."); | |
// read with raw sample data. | |
byte temperature = 0; | |
byte humidity = 0; | |
byte data[40] = {0}; | |
if (dht11.read(pinDHT11, &temperature, &humidity, data)) { | |
Serial.print("Read DHT11 failed"); | |
return; | |
} | |
Serial.print((int)temperature); Serial.print(" *C, "); | |
Serial.print((int)humidity); Serial.println(" %"); | |
// DHT11 sampling rate is 1HZ. | |
delay(1000); | |
lcd.setCursor(0, 1); | |
lcd.print((int)temperature); | |
Serial.print("temperature: "); | |
Serial.println(temperature); | |
if(temperature < 30) { | |
digitalWrite(6, HIGH); //pin 6 is for LED | |
tone(buzzer, melody[0], duration); | |
} | |
if(temperature >= 30) { | |
digitalWrite(6, LOW); //pin 6 is for LED | |
//tone(buzzer, melody[0], duration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment