Prototype Improved
Prototype Improved
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_BMP280.h>
#include <SoftwareSerial.h>
// Pin Definitions
const int trigPin = 7; // Ultrasonic sensor Trig pin
const int echoPin = 6; // Ultrasonic sensor Echo pin
const int buzzerPin = 2; // Piezobuzzer pin
const int redLedPin = 4; // Red LED pin
const int greenLedPin = 5; // Green LED pin
// Thresholds
const float waterLevelThreshold = 100.0; // Adjust this value according to your
setup
const float pressureThreshold = 1000.0; // Adjust this value according to your
setup
void setup() {
// Initialize serial communication
Serial.begin(9600);
gsmSerial.begin(9600);
```cpp
void loop() {
// Read water level from ultrasonic sensor
float waterLevel = getWaterLevel();
float getWaterLevel() {
// Send ultrasonic pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
return distance;
}
void sendSMSAlert() {
// Send AT commands to GSM module
gsmSerial.println("AT");
delay(100);
gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
delay(100);
gsmSerial.print("AT+CMGS=\"+1234567890\""); // Replace with recipient's phone
number
delay(100);
gsmSerial.print("Storm surge detected!"); // SMS message
delay(100);
gsmSerial.write(26); // End message
delay(1000); // Wait for SMS to be sent
}
Please make sure to copy this code below Part 1 in your Arduino IDE. Remember to
replace `+1234567890` with the recipient's phone number in the `sendSMSAlert()`
function.
Once you have uploaded the code to your Arduino Nano, the storm surge detector
should start working. It will continuously measure the water level and atmospheric
pressure, display the readings on the OLED display, trigger alerts (buzzer and
LEDs) if storm surge conditions are detected, and send an SMS alert.
Please note that this code serves as a basic framework and may require further
customization and refinement based on your specific requirements and hardware
setup.
COMPONENTS;
INSTRUCTION
Note: This guide assumes that you have basic knowledge of Arduino programming and
wiring. If you are unfamiliar with these concepts, it's recommended to review some
Arduino tutorials before proceeding.