/* AHT10 Temperature and humidity sensor with
light sensor addition
*/
#include <TM1637Display.h>
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
//for analog light sensor
#define light A0 // define input pin
//https://deepbluembedded.com/seven-segment-display-generator/
const uint8_t SEG_Over[] = {
SEG_A | SEG_D | SEG_E | SEG_F, // [
};
const uint8_t SEG_OFF[] = {0, 0, 0, 0};
const uint8_t AllOn[] = {0xff, 0xff, 0xff, 0xff};
// In this library, the byte order is .GFEDCBA
// GLOBALS
// Create a display object, specifying parameters (Clock pin, Data pin)
TM1637Display display(4, 5);
void setup() {
Serial.begin(9600);
if (! aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
Serial.println("AHT10 or AHT20 found");
// put your setup code here, to run once:
// pinMode(trigPin, OUTPUT);
// pinMode(echoPin, INPUT);
display.setBrightness(5);
display.setSegments(AllOn);
delay(800);
display.setSegments(SEG_OFF);
}
void MyDisplay(float i) {
i = i *10;
display.showNumberDecEx(i, 0b11100000, false, 3, 0);
}
void loop() {
int Lvalue = analogRead(light);// read the light
int NewLvalue = map(Lvalue,0,1023,7,0);
Serial.println(NewLvalue);
display.setBrightness(NewLvalue);
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
MyDisplay(temp.temperature);
delay(2000);
MyDisplay(humidity.relative_humidity);
delay(2000);
}