Lesson 28: DHT11 Temperature Sensor with TM1637 Display | Arduino Step by Step Course
Related or required files and link to this lesson
Part 3: Temperature Sensor
In this lesson we learn how to use DHT11 to measure temperature and display it on TM1637 LED display.
/*
* Robojax Arduino Step By Step Course
* Lesson 28 DHT11 with TM1637
* This is the Arduino code for TM1637 4 digits display.
* *
Please watch video instruction 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: Dec 06, 2017, in Ajax, Ontario, Canada
* Original code from https://github.com/avishorp/TM1637
* Modified for Robojax video on Dec 06, 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 Arduono 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 Arduono 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);
}
}