Μετάβαση στο κύριο περιεχόμενο

Αισθητήρας σχετικής υγρασίας και θερμοκρασίας DHT11

 Αισθητήρας σχετικής υγρασίας και θερμοκρασίας DHT11

 

Κώδικας για τον DHT11 από τα παραδείγματα της βιβλιοθήκης του

 


// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define DHTPIN 2     // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!

#define DHTTYPE DHT11   // DHT 11
// #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

Σχόλια

Δημοφιλείς αναρτήσεις από αυτό το ιστολόγιο

PWM στο Arduino

  PWM στο Arduino Εισαγωγή στο PWM Η διαμόρφωση πλάτους παλμού (PWM)   είναι μια τεχνική με την οποία το πλάτος ενός παλμού μεταβάλλεται διατηρώντας τη συχνότητα του κύματος σταθερή. Είναι μια μέθοδος παραγωγής αναλογικού σήματος με χρήση ψηφιακής πηγής. Γενιά PWM   Ένα σήμα PWM αποτελείται από δύο κύρια στοιχεία που καθορίζουν τη συμπεριφορά του: έναν  κύκλο λειτουργίας  και μια  συχνότητα  .   Τι είναι ο κύκλος λειτουργίας του σήματος Η περίοδος ενός παλμού αποτελείται από έναν  κύκλο  ON   (5V) και έναν    κύκλο  OFF  (0V). Το κλάσμα για το οποίο το σήμα είναι ενεργοποιημένο για μια περίοδο είναι γνωστό ως   κύκλος λειτουργίας  . Π.χ.  Ένας παλμός με περίοδο 10 ms θα παραμείνει ενεργός (υψηλό) για 2 ms. Επομένως, ο κύκλος λειτουργίας θα είναι D = 2ms / 10ms = 20%   Μέσω της τεχνικής PWM, μπορούμε να ελέγξουμε την ισχύ που παρέχεται στο φορτίο χρησιμοποιώντας το σήμα ON-O...

Tmp36GZ θερμόμετρο με LCD οθόνη

 Tmp36GZ με LCD οθόνη // Define to which pin of the Arduino the output of the TMP36 is connected: #include <LiquidCrystal_I2C.h> // Look for LiquidCrystal I2C library by Marco Schwartz LiquidCrystal_I2C lcd ( 0x 27 , 16 , 2 ) ;  // set the LCD address to 0x3F for a 16 chars and 2 line display #define sensorPin A0 void setup () {   // Begin serial communication at a baud rate of 9600:   Serial . begin ( 9600 ) ;   lcd . init () ;   lcd . clear () ;           lcd . backlight () ;      // Make sure backlight is on     // Print a message on both lines of the LCD.   lcd . setCursor ( 2 , 0 ) ;   //Set cursor to character 2 on line 0   lcd . print ( "Hello world!" ) ;     lcd . setCursor ( 2 , 1 ) ;   //Move cursor to character 2 on line 1   lcd . print ( "LCD Tutorial" ) ; } void loop () {   // Get a reading from the temperature sensor:   int reading ...

Πώς να χρησιμοποιήσετε ένα Breadboard

  Πώς να χρησιμοποιήσετε ένα Breadboard Το breadboard έχει εσωτερικές συνδέσεις μεταξύ των οπών του. Μερικές κάθετες συνδέσεις και μερικές οριζόντιες συνδέσεις. Κανονικά, χρησιμοποιείτε τις κολώνες στα πλάγια για να συνδέσετε το τροφοδοτικό σας. Και χρησιμοποιείτε τις σειρές στη μέση για να συνδέσετε τα στοιχεία σας. Στήλες Τροφοδοτικού Είναι σύνηθες να χρησιμοποιείτε τις στήλες στα αριστερά και δεξιά για τη σύνδεση του τροφοδοτικού. Αυτές οι στήλες συνδέονται κάθετα. Έτσι, εάν συνδέσετε 5 βολτ στην επάνω οπή μιας από τις πλευρικές κολώνες, θα έχετε 5 βολτ σε όλες τις οπές αυτής της στήλης. Χρησιμοποιήστε τις στήλες που επισημαίνονται με κόκκινη γραμμή για το συν και τη στήλη με μπλε γραμμή για το μείον. Τέλος φόρμας Σημείωση: Μερικές μεγαλύτερες πλάκες   breadboard χωρίζονται στα δύο έτσι ώστε το πάνω μισό να αποσυνδεθεί από το κάτω μισό. Αυτό υποδεικνύεται από τις κατακόρυφες μπλε και κόκκινες γραμμές που χωρίζονται στα δύο.   Περιοχή Συστατικού Σ...