Arduino
TM1638
Modulo LED&KEY
Temperatura y humedad
xsetaseta@gmail.com
/* xsetaseta@gmail.com Juan Galaz 4/SEP/2017 */ #include <TM1638.h> //data(I/O) pin 8, clock(CLK) pin 9 , strobe(STB) pin 7 TM1638 module(8, 9, 7); #include <Wire.h> #include <VirtualWire.h> #include "DHT.h" #define DHTPIN 3 // what pin we're connected to //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE); float h,t; int hi,ti; char cadena[20]; void setup() { Serial.begin(9600); dht.begin(); //activa intensidad con nivel 2 module.setupDisplay(1,0); module.setDisplayToString("SENSOR ",0,0); delay(500); } void loop() { h = dht.readHumidity(); t = dht.readTemperature(); if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { hi=h; ti=t*10; Serial.print("Humedad="); Serial.print(hi); Serial.print(" Temperatura="); Serial.println(ti); sprintf(cadena,"H%2d %3d*",hi,ti); if(ti>-100) {module.setDisplayToString(cadena,4,0);} else {module.setDisplayToString(cadena,2,0);} Serial.println(cadena); } delay(1000); } |