//Rain drop sensor with led
//Replace rain sensor into potentionometer
//line - 153 (Replacing)
//Line - 29,30,31
// Uncomment whatever type of DHT sensor!
int rain_pin =32;
int LDR_PIN = 25;
int x=0;
float light_intensity = 0;
float rain_value =0;
#include "DHT.h"
#define DHTPIN 27
#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(LDR_PIN, INPUT);
pinMode(rain_pin, INPUT);
}
void loop() {
light_intensity = analogRead(LDR_PIN);
x = map (light_intensity,32,4063,0,100);
rain_value = analogRead(rain_pin);
// Wait a few seconds between measurements.
delay(200);
// 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"));
Serial.println(rain_value);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor (0,5);
display.println("Temp : ");
display.print(t);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor (0,25);
display.println("Humidity : ");
display.print(h);
display.print(" %");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor (0,45);
display.println("Light Intensity : ");
display.print(x);
display.print(" %");
// display.setTextSize(1);
// display.setTextColor(WHITE);
// display.setCursor (90,5);
// display.println("Light ");
// display.print(t);
display.display();
delay (1);
display.clearDisplay();
if(rain_value > 1000) // rain_value == 1
{
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor (30,5);
display.println(" Raining");
//display.print(t);
}
}
// #include "DHT.h"
// #include <SPI.h>
// #include <Wire.h>
// #include <Adafruit_SSD1306.h>
// #define SCREEN_WIDTH 128
// #define SCREEN_HEIGHT 64
// #define OLED_RESET -1
// #define DHTPIN 27
// #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
// DHT dht(DHTPIN, DHTTYPE);
// Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// const int rain_pin = 32;
// const int LDR_PIN = 25;
// int x = 0;
// float light_intensity = 0;
// float rain_value = 0;
// // Define raining icon as a 24x24 bitmap
// const int water_drop_width = 16;
// const int water_drop_height = 16;
// // Define the water drop icon bitmap
// const unsigned char water_drop_bitmap[] PROGMEM = {
// // 16x16 bitmap data for the water drop icon
// B00000000, B00000000,
// B00000000, B00000000,
// B00001100, B00000000,
// B00011110, B00000000,
// B00011110, B00000000,
// B00011110, B00000000,
// B00011110, B00000000,
// B00111111, B00000000,
// B00111111, B00000000,
// B00111111, B00000000,
// B01111111, B10000000,
// B01111111, B10000000,
// B01111111, B10000000,
// B11111111, B11000000,
// B11111111, B11000000,
// B11111111, B11000000,
// };
// void setup() {
// Serial.begin(9600);
// Serial.println(F("DHTxx test!"));
// dht.begin();
// display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// pinMode(33, INPUT);
// pinMode(LDR_PIN, INPUT);
// pinMode(rain_pin, INPUT);
// if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
// Serial.println(F("SSD1306 allocation failed"));
// for (;;);
// }
// display.display();
// delay(2000); // Pause for 2 seconds
// display.clearDisplay();
// }
// void loop() {
// light_intensity = analogRead(LDR_PIN);
// x = map(light_intensity, 32, 4063, 0, 100);
// rain_value = analogRead(rain_pin);
// float h = dht.readHumidity();
// float t = dht.readTemperature();
// float f = dht.readTemperature(true);
// if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println(F("Failed to read from DHT sensor!"));
// return;
// }
// float hif = dht.computeHeatIndex(f, h);
// 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"));
// Serial.println(rain_value);
// display.clearDisplay();
// display.setTextSize(1);
// display.setTextColor(WHITE);
// display.setCursor(0, 5);
// display.println("Temp : ");
// display.print(t);
// display.setTextSize(1);
// display.setTextColor(WHITE);
// display.setCursor(0, 25);
// display.println("Humidity : ");
// display.print(h);
// display.print(" %");
// display.setTextSize(1);
// display.setTextColor(WHITE);
// display.setCursor(0, 45);
// display.println("Light Intensity : ");
// display.print(x);
// display.print(" %");
// if (rain_value > 1000) {
// display.drawBitmap(80, 0, rain_icon, 24, 24, WHITE);
// }
// display.display();
// delay(1000); // Update display every second
// }
// // display.clearDisplay();
// // // Draw the water drop icon at position (0, 0)
// // display.drawBitmap(0, 0, water_drop_bitmap, water_drop_width, water_drop_height, WHITE);
// // display.display();
// // delay(1000); // Pause for 1 second