int switch_pin_in = 26;
// int switch status
int switch_out = 27;
int Switch_status =0;
int buzzer_pin = 14;
#include "DHT.h"
#define DHTPIN 33
#include <SPI.h>
#include <Wire.h>
// #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
#define SCREEN_WIDTH 128
#define SCREEN_HIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display (SCREEN_WIDTH,SCREEN_HIGHT,&Wire,OLED_RESET);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
display.begin(SSD1306_SWITCHCAPVCC,0x3c );
pinMode(33, INPUT);
pinMode(27, INPUT);
pinMode(26, OUTPUT);
}
void loop() {
// Wait a few seconds between measurements.
delay(2);
int Switch_status = analogRead(switch_pin_in);
Serial.println(Switch_status); //This line is for testing only. // You can COMMENT this line
digitalWrite(26, LOW);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor (10,5);
display.println("Temprature : ");
// display.print(t);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor (30,30);
display.println(t);
display.display();
delay (1);
display.clearDisplay();
}