Arduino humidity sensor code
unknown
plain_text
a year ago
1.4 kB
11
Indexable
Never
#include "DHT.h" #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // Define pixel width #define SCREEN_HEIGHT 32 // Define pixel height #define SCREEN_ADDRESS 0x3C // define OLED adress Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); #define OLED_RESET 4<br>Adafruit_SSD1306 display(OLED_RESET); #define DHTTYPE DHT11 // DHT11 or DHT22 #define DHTPIN 5 //Pin which is connected to data (middle) on DHT DHT dht(DHTPIN, DHTTYPE); void setup() { display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Define adress once more display.clearDisplay(); dht.begin(); } void loop() { delay(2000); // sensor read only every 2 seconds so its pointless to loop faster float h = dht.readHumidity(); //get humidity value float t = dht.readTemperature(); //get temp. for fahrenheit type true in the brackets float hic = dht.computeHeatIndex(t, h, false); //useless for this aplication but cool to implement for a bigger display display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(0,9); display.clearDisplay(); //display.print(F("Hum: ")); display.print(h,0); display.print(F("% ")); //display.setCursor(0, 10); //display.print("Temp: "); display.print(t,0); //display.print(" "); display.print("C"); display.display(); }