Capteur DHT11 avec LED et haut-parleur piézo
Composants et fournitures
| Capteur de température et d'humidité DHT11 (4 broches) | | × | 1 | |
| | × | 3 | |
| Câbles de raccordement (générique) | | × | 12 | |
| | × | 3 | |
| | × | 1 | |
| | × | 1 | |
Applications et services en ligne
À propos de ce projet
C'est mon quatrième projet. Dans ce projet, nous utiliserons une température DHT11 et trois LED qui vous montreront que la température. est trop chaud, parfait ou trop froid.
Voici le DHT11 :
Voici les résistances et les LED :
Et voici l'enceinte Piezo :
Vous aurez besoin de ces bibliothèques :
- https://github.com/adafruit/Adafruit_Sensor
- https://github.com/adafruit/DHT-sensor-library
Si vous aimez ce projet respectez le projet et suivez-moi !
Code
- DHT11 avec LED et haut-parleur piézo
DHT11 avec LED et haut-parleur piézoC/C++
#include #include int speakerPin =9;int length =1;#define DHTPIN 5#define DHTTYPE DHT11#define LED_TOO_COLD A0#define LED_PERFECT A1#define LED_TOO_HOT A2DHT dht(DHTPIN , DHTTYPE);void setup() { Serial.begin(9600); Serial.println("Test DHT11 !"); dht.begin();}void loop() { pinMode(speakerPin, OUTPUT); pinMode (A0 , SORTIE); pinMode (A1 , SORTIE); pinMode (A2, SORTIE); retard (2000); float h =dht.readHumidity(); float t =dht.readTemperature(); float f =dht.readTemperature(true); if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("Échec de la lecture depuis le capteur DHT !"); retourner; } Serial.print("Humidité :"); Serial.print(h); Serial.print(" %\t"); Serial.print("Température :"); Serial.print(t); Serial.println(" *C "); if (t <=20) { Serial.println("Trop froid!"); digitalWrite(A0, HAUT); digitalWrite(speakerPin, HIGH); retard (1000); digitalWrite(speakerPin, LOW); digitalWrite(A0, LOW); } if (20 =29) { Serial.println("Trop chaud!"); digitalWrite (A2, HAUT); digitalWrite(speakerPin, HIGH); retard (1000); digitalWrite(speakerPin, LOW); écriture numérique (A2, FAIBLE); }}
Schémas
dht11_with_leds_and_piezo_speaker_JRpaa8ISfy.fzzRenommé un tmp36 en dht 11