The project uses an Arduino and the following components:
RTClib.h - RTC clock support,Arduino.h - Arduino platform base functions,TM1637Display.h - 4-digit display control,DHT.h - DHT11 sensor control,OneWire.h i DallasTemperature.h - DS18B20 support,SPI.h, Wire.h - communication libraries (Wire™ used by RTC).CLK 6, DIO 4 - TM1637 display pins,DHTPIN 9, DHTTYPE DHT11 - DHT11 sensor configuration,ONE_WIRE_BUS 3 - bus for DS18B20.RTC_DS1307 rtc;TM1637Display display(CLK, DIO);DHT dht(DHTPIN, DHTTYPE);OneWire oneWire(ONE_WIRE_BUS);DallasTemperature sensors(&oneWire);rtc.begin() - starts the RTC clock,sensors.begin() - initialises the DS18B20,setBrightness) and shows “8888” as a test,Serial.begin) - to debug measurements,dht.begin() - initialises the DHT11 sensor.sensors.requestTemperatures() i getTempCByIndex(0) - DS18B20 temperature reading,int - rounding (round),rtc.now() - gets the current time; extracts the hour and minute,readHumidity() i readTemperature(),toInt()) and displaying sequentially:Each reading - 2 seconds.
The device is a 'digital' type clock with temperature and humidity measurement, visualising the values on a TM1637 display. It uses three different sensors and simple Arduino libraries, making the project a great example of hardware and software integration in a single system.
Video recorded a long time ago and in English, so please be understanding ;)
#include ''RTClib.h'' #include <Arduino.h> #include <TM1637Display.h> #include ''DHT.h'' #include <OneWire.h> #include <DallasTemperature.h> #include <SPI.h> #include <Wire.h> #define CLK 6 #define DIO 4 #define DHTPIN 9 #define DHTTYPE DHT11 #define ONE_WIRE_BUS 3 RTC_DS1307 rtc; TM1637Display display(CLK, DIO); DHT dht(DHTPIN, DHTTYPE); OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup() { rtc.begin(); sensors.begin(); display.setBrightness(0x0f); display.showNumberDecEx(8888,0b01000000, false); delay(3000); display.clear(); display.setBrightness(3); Serial.begin(57600); dht.begin(); } void loop() { sensors.requestTemperatures(); float tempC = sensors.getTempCByIndex(0); int tempINT = round(tempC); DateTime now = rtc.now(); int Minute = now.minute(); int Hour = now.hour(); String strMinute; String strHour; float h = dht.readHumidity(); float t = dht.readTemperature(); if(Hour < 10) {strHour = ''0'' + String(Hour);} else if(Hour >= 10) {strHour = String(Hour);} else if(Hour == 0) {strHour = ''00'';} if(Minute < 10) {strMinute = ''0'' + String(Minute);} else if(Minute >= 10) {strMinute = String(Minute);} else if(Minute == 0) {strMinute = ''00'';} String Time; Time += strHour; Time += strMinute; if(Time == ''0''){ Time = ''0000''; } Serial.println(tempC); Serial.println(tempINT); int numTime = Time.toInt(); display.clear(); display.showNumberDecEx(numTime,0b01000000, true); delay(2000); display.clear(); display.showNumberDec(t,false,2,1); delay(2000); display.clear(); display.showNumberDec(h,false,2,1); delay(2000); display.clear(); display.showNumberDec(tempINT,false,2,1); delay(2000); }