Created
February 12, 2016 19:11
-
-
Save kachurovskiy/e28e715fcc9323556a51 to your computer and use it in GitHub Desktop.
Arduino program showing data from DHT11 temperature and humidity sensor on 4-digit display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DHT.h> | |
#include <SevSeg.h> | |
// DHT data wire connected on A0 | |
#define DHTPIN 14 | |
#define DHTTYPE DHT11 | |
SevSeg sevseg; | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup() { | |
byte numDigits = 4; | |
// 4-digit display HS420561K-32 on digital pins 2 to 13 | |
byte digitPins[] = {2, 3, 4, 5}; | |
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; | |
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins); | |
sevseg.setBrightness(90); | |
dht.begin(); | |
} | |
void loop() { | |
int h = (int) dht.readHumidity(); | |
int t = (int) dht.readTemperature(); | |
sevseg.setNumber(h * 100 + t, 2); | |
// DHT11 can only be queried every 1s and takes 300ms to return result. | |
// Removing for-loop and delay will result in much more blinky display. | |
for (int i = 0; i < 300; i++) { | |
sevseg.refreshDisplay(); | |
delay(10); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment