Lesson 28: DHT11 Temperature Sensor with TM1637 Display | Arduino Step-by-Step Course
In this lesson, we learn how to use a DHT11 to measure temperature and display it on a TM1637 LED display.
520-Lesson 28: DHT11 Temperature Sensor with TM1637 Display | Arduino Step-by-Step Course
语言: C++
/*
* Robojax Arduino Step-by-Step Course
* Lesson 28: DHT11 with TM1637
* This is the Arduino code for TM1637 4-digit display.
*
* Please watch video instructions here: https://youtu.be/C-1iaCPzNtU
* This code is available at: http://robojax.com/course1/?vid=lecture11
*
* With over 100 lectures free on YouTube. Watch it here: http://robojax.com/L/?id=338
* Get the code for the course: http://robojax.com/L/?id=339
*
* Date: December 6, 2017, in Ajax, Ontario, Canada
*
* Original code from: https://github.com/avishorp/TM1637
* Modified for Robojax video on December 6, 2017
*/
#include <dht11.h>
dht11 DHT11; // create object of DHT11
#define dhtpin 2 // set the pin to connect to DHT11
// start of settings of TM1637 LED display
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);
uint8_t blank[] = { 0x0, 0x0, 0x0, 0x0 };// blank value for all digits
// The amount of time (in milliseconds) between tests
#define TEST_DELAY 2000
// start of settings of TM1637 LED display
void setup()
{
//Robojax Step-by-Step Arduino Course YouTube Watch it here: http://robojax.com/L/?id=338
Serial.begin(9600);// setting up serial monitor
display.setBrightness(0x0f);
}
void loop()
{
//Robojax Step-by-Step Arduino Course YouTube Watch it here: http://robojax.com/L/?id=338
DHT11.read(dhtpin);// initialize the reading
int humidity = DHT11.humidity;// get humidity
//code for Robojax.com video
Serial.print(getTemp('C'));
Serial.print("C ");
Serial.print(getTemp('F'));
Serial.print("F ");
Serial.print(getTemp('K'));
Serial.print("K ");
Serial.print(" humidity:");
Serial.print (humidity);
Serial.print("% ");
Serial.println();
delay(500);
display.setSegments(blank);
display.showNumberDec(23, false, 2,1);
delay(TEST_DELAY);
display.setSegments(data);
display.showNumberDec(153, false, 3, 1);
delay(TEST_DELAY);
display.setSegments(data);
for(int i=0; i<=500; i++)
{
display.showNumberDec(i);
}
}
资源与参考
-
外部DHT11 手册 (PDF)robojax.com
-
外部GitHub上的DHT11库github.com
文件📁
没有可用的文件。