Project tutorial
DHT11  Sensor with LEDs and a Piezo Speaker

DHT11 Sensor with LEDs and a Piezo Speaker © CC BY-NC-ND

An Arduino Uno with DHT11 sensor module, three LEDs and a Piezo speaker.

  • 11,633 views
  • 4 comments
  • 22 respects

Components and supplies

Apps and online services

About this project

Hello! My name is Matei, I'm eleven years old and this is my fourth project. In this project we will use a DHT11 temperature and three LEDs that will show you that the temp. is too hot, perfect or too cold.

This is the DHT11:

These are the resistors and the LEDs:

And this is the Piezo speaker:

You will need these libraries:

If you like this project respect the project and follow me!

Donations: https://www.paypal.me/princematthew ( support is really appreciated😃)

Code

DHT11 with LEDs and piezo speakerC/C++
#include <Adafruit_Sensor.h>
#include <DHT.h>
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 A2
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(9600);
  Serial.println("DHT11 test!");

  dht.begin();
}

void loop() {
  pinMode(speakerPin, OUTPUT);
  pinMode (A0 , OUTPUT);
  pinMode (A1 , OUTPUT);
  pinMode (A2 , OUTPUT);
  delay(2000);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);


  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
  if (t <= 20) {
    Serial.println("Too cold!");
    digitalWrite(A0, HIGH);
    digitalWrite(speakerPin, HIGH);
    delay (1000);
    digitalWrite(speakerPin, LOW);
    digitalWrite(A0, LOW);
  }
  if (20 < t < 27) {
    Serial.println("Perfect temperature!");
    digitalWrite(A1, HIGH);
    delay (2000);
    digitalWrite(A1, LOW);
  }
  if (t >= 29) {
    Serial.println("Too hot!");
    digitalWrite(A2, HIGH);
    digitalWrite(speakerPin, HIGH);
    delay (1000);
    digitalWrite(speakerPin, LOW);
    digitalWrite(A2, LOW);
  }

}

Schematics

DHT11
dht11_with_leds_and_piezo_speaker_JRpaa8ISfy.fzz
Renamed a tmp36 to dht 11
Uploads2ftmp2ff7b36905 6787 4495 8ea7 9204fd4c6d652fdht11 with leds and piezo speaker jrpaa8isfy bb u9z1aanoqt

Comments

Similar projects you might like

Bar Graph

Project tutorial by Tech with Matthew

  • 11,836 views
  • 18 comments
  • 48 respects

Sound Sensor Activated LEDs with LCD for Sound Level Data!

Project tutorial by HeathenHacks

  • 6,412 views
  • 5 comments
  • 17 respects

Arduino Airsoft Time Bomb with Button, Speaker and 3 LEDs

Project showcase by Nashboss100

  • 3,098 views
  • 18 comments
  • 11 respects

DHT11 Temperature/Humidity Sensor

Project tutorial by Zachary Haslam

  • 50,958 views
  • 5 comments
  • 53 respects

How to read temperature and humidity on Blynk with DHT11

Project tutorial by Tech with Matthew

  • 19,044 views
  • 5 comments
  • 19 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 11,129 views
  • 7 comments
  • 25 respects
Add projectSign up / Login