marți, 26 aprilie 2022

Simple Arduino Project with DHT11/22 sensor and TM1637 LCD

 This is a simple Arduino project based on DHT11 or DHT22 temperature&humidity sensor and TM1637 4 digit 7 segment LCD.



 

// Include the libraries
#include <TM1637Display.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
// Define the connections pins
#define CLK 8
#define DIO 9
#define DHTPIN 5
// Create variable
int temperature_celsius;
int temperature_fahrenheit;
int humidity_read;
// Create °C symbol
const uint8_t celsius[] = {
SEG_A | SEG_B | SEG_F | SEG_G, // Circle
SEG_A | SEG_D | SEG_E | SEG_F // C
};
// Create °F symbol
const uint8_t fahrenheit[] = {
SEG_A | SEG_B | SEG_F | SEG_G, // Circle
SEG_A | SEG_E | SEG_F | SEG_G // F
};
// Create H symbol
const uint8_t humidity[] = {
SEG_B | SEG_C | SEG_G | SEG_E | SEG_F // H
};
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
// Create display object of type TM1637Display
TM1637Display display = TM1637Display(CLK, DIO);
// Create dht object of type DHT:
DHT dht = DHT(DHTPIN, DHTTYPE);
void setup() {
// Set the display brightness (0-7)
display.setBrightness(5);
// Clear the display
display.clear();
// Setup sensor
dht.begin();
}
void loop() {
// Read the temperature as Celsius and Fahrenheit
temperature_celsius = dht.readTemperature();
temperature_fahrenheit = dht.readTemperature(true);
humidity_read = dht.readHumidity();
// Display the temperature in celsius format
display.showNumberDec(temperature_celsius, false, 2, 0);
display.setSegments(celsius, 2, 2);
delay(2000);
display.clear();
// Display the temperature in fahrenheit format
display.showNumberDec(temperature_fahrenheit, false, 2, 0);
display.setSegments(fahrenheit, 2, 2);
delay(2000);
display.clear();
// Display the humidity
display.showNumberDec(humidity_read, false, 2, 0);
display.setSegments(humidity, 1, 3);
delay(2000);
display.clear();
}

Niciun comentariu:

Trimiteți un comentariu