#include <Wire.
h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 15 // Pin connected to DHT11
#define DHTTYPE DHT11 // Define the type of DHT sensor
#define BUTTON_PIN 18 // Pin connected to button
#define LED_PIN 4 // Pin connected to LED (used for alarm in this
case)
#define BUZZER_PIN 5 // Pin connected to Buzzer
#define GREEN_LED_PIN 34 // Pin for Green LED (favorable fishing)
#define BLUE_LED_PIN 35 // Pin for Blue LED (not favorable fishing)
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
LiquidCrystal_I2C lcd(0x27, 16, 2);
float lowerPressureThreshold = 1005; // Lower pressure threshold (hPa)
float upperPressureThreshold = 1018; // Upper pressure threshold (hPa)
float minTempThreshold = 20; // Minimum temperature threshold (°C)
float maxTempThreshold = 28; // Maximum temperature threshold (°C)
float minHumidityThreshold = 50; // Minimum humidity threshold (%)
float maxHumidityThreshold = 70; // Maximum humidity threshold (%)
bool stormWarning = false;
bool detailMode = false; // Tracks whether in detail mode
bool buttonPressed = false; // Tracks button press state
bool showingFishingStatus = false; // Temporarily showing fishing status
// Function forward declarations
bool checkStormConditions(float pressure, float humidity, float temperature);
bool isFishingFavorable(float temperature, float pressure, float humidity);
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(GREEN_LED_PIN, OUTPUT); // Green LED for favorable fishing
pinMode(BLUE_LED_PIN, OUTPUT); // Blue LED for unfavorable fishing
pinMode(LED_PIN, OUTPUT); // Pin connected to LED (used for alarm)
pinMode(BUZZER_PIN, OUTPUT); // Pin for buzzer
Serial.begin(9600);
Wire.begin(21, 22);
dht.begin();
if (!bmp.begin()) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sensor Error");
while (1); // Halt if BMP sensor fails
}
lcd.init();
delay(500);
lcd.init();
lcd.backlight();
void loop() {
// Read sensor data
sensors_event_t event;
bmp.getEvent(&event);
float humidity = dht.readHumidity();
float pressure = event.pressure; // Convert pressure to hPa
float temperature;
bmp.getTemperature(&temperature);
// Check for storm conditions
stormWarning = checkStormConditions(pressure, humidity, temperature);
// Handle button press for mode toggling and fishing status
static unsigned long buttonPressStart = 0;
if (digitalRead(BUTTON_PIN) == LOW) {
if (!buttonPressed) {
buttonPressStart = millis();
buttonPressed = true;
}
} else if (buttonPressed) {
buttonPressed = false;
if (millis() - buttonPressStart < 4000) {
// Short press: Display fishing status with beeping
showingFishingStatus = true;
if (isFishingFavorable(temperature, pressure, humidity)) {
tone(BUZZER_PIN, 2000); // Good for fishing - beep twice
delay(300);
noTone(BUZZER_PIN);
delay(300);
tone(BUZZER_PIN, 2000);
delay(300);
noTone(BUZZER_PIN);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Good for Fishing");
} else {
tone(BUZZER_PIN, 1000); // Not favorable - single beep
delay(500);
noTone(BUZZER_PIN);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Not Favorable");
}
delay(2000); // Display for 2 seconds
showingFishingStatus = false; // Return to normal mode after display
} else {
// Long press: Toggle between normal and detail mode
detailMode = !detailMode;
tone(BUZZER_PIN, 2000); // Beep once when switching modes
delay(300);
noTone(BUZZER_PIN);
}
}
// Handle the display in the respective mode
if (showingFishingStatus) return;
static unsigned long lastSwitchTime = 0;
unsigned long currentTime = millis();
if (currentTime - lastSwitchTime >= 3000) {
lastSwitchTime = currentTime;
if (detailMode) {
// In Detail Mode, cycle through temperature, pressure, humidity, etc.
static int displayState = 0;
displayState = (displayState + 1) % 5; // 5 options in detail mode
switch (displayState) {
case 0:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature, 1);
lcd.print(" C");
break;
case 1:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pressure: ");
lcd.print(pressure, 1);
lcd.print(" hPa");
break;
case 2:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(humidity, 1);
lcd.print(" %");
break;
case 3:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Storm: ");
lcd.print(stormWarning ? "Yes" : "No");
break;
case 4:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(isFishingFavorable(temperature, pressure, humidity) ? "Good for
Fishing" : "Not Favorable");
break;
}
} else {
// In Normal Mode, alternate between Jaldoot, storm condition, and fishing
status
static int displayState = 0;
displayState = (displayState + 1) % 3;
switch (displayState) {
case 0:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Jaldoot");
break;
case 1:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Storm: ");
lcd.print(stormWarning ? "Yes" : "No");
break;
case 2:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(isFishingFavorable(temperature, pressure, humidity) ? "Good for
Fishing" : "Not Favorable");
break;
}
}
}
// Handle LED control based on fishing conditions
if (isFishingFavorable(temperature, pressure, humidity)) {
Serial.println("Favorable Fishing - Green LED ON, Blue LED OFF");
digitalWrite(GREEN_LED_PIN, HIGH); // Turn on Green LED for favorable
conditions
digitalWrite(BLUE_LED_PIN, LOW); // Turn off Blue LED
} else {
Serial.println("Unfavorable Fishing - Blue LED ON, Green LED OFF");
digitalWrite(GREEN_LED_PIN, LOW); // Turn off Green LED
digitalWrite(BLUE_LED_PIN, HIGH); // Turn on Blue LED for unfavorable
conditions
}
}
bool checkStormConditions(float pressure, float humidity, float temperature) {
// Storm warning if pressure drops significantly, humidity is high, and
temperature drops
bool lowPressure = pressure < (upperPressureThreshold - 10); // Reduced
threshold sensitivity
bool highHumidity = humidity > maxHumidityThreshold;
bool temperatureDrop = temperature < (minTempThreshold - 3); // Sudden
temp drop
// Return true only if all storm-related conditions are met
return lowPressure && highHumidity && temperatureDrop;
}
bool isFishingFavorable(float temperature, float pressure, float humidity) {
return (pressure >= lowerPressureThreshold && pressure <=
upperPressureThreshold &&
temperature >= minTempThreshold && temperature <=
maxTempThreshold &&
humidity >= minHumidityThreshold && humidity <=
maxHumidityThreshold);
}