Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //www.elegoo.com
- //2016.12.9
- // Atiriya Iyer
- #include <SimpleDHT.h>
- // for DHT11,
- // VCC: 5V or 3V
- // GND: GND
- // DATA: 2
- int pinDHT11 = 7;
- SimpleDHT11 dht11;
- const int pinLEDblue= 9;
- const int pinLEDgreen= 10;
- const int pinLEDred= 11;
- void setup() {
- Serial.begin(9600);
- pinMode (pinLEDblue, OUTPUT);
- pinMode (pinLEDgreen, OUTPUT);
- pinMode (pinLEDred, OUTPUT);
- analogWrite (pinLEDblue, 255);
- delay(500);
- analogWrite (pinLEDblue, 0);
- delay(500);
- analogWrite (pinLEDgreen, 255);
- delay(500);
- analogWrite (pinLEDgreen, 0);
- delay(500);
- analogWrite (pinLEDred, 255);
- delay(500);
- analogWrite (pinLEDred, 0);
- }
- void loop() {
- // start working...
- 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("Sample RAW Bits: ");
- for (int i = 0; i < 40; i++) {
- Serial.print((int)data[i]);
- if (i > 0 && ((i + 1) % 4) == 0) {
- Serial.print(' ');
- }
- }
- Serial.println("");
- Serial.print("Sample OK: ");
- Serial.print((int)temperature); Serial.print(" *C, ");
- Serial.print((int)humidity); Serial.println(" %");
- // DHT11 sampling rate is 1HZ.
- delay(1000);
- if (humidity <= 70)
- {
- analogWrite (pinLEDred, 200);
- delay (1000);
- analogWrite (pinLEDred, 0);
- }
- if (humidity >= 70)
- {
- analogWrite (pinLEDgreen, 200);
- delay (1000);
- analogWrite (pinLEDgreen, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement