0% found this document useful (0 votes)
11 views5 pages

Prototype Improved

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Prototype Improved

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

CODING;

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_BMP280.h>
#include <SoftwareSerial.h>

#define OLED_ADDR 0x3C


#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 8

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


Adafruit_BMP280 bmp;
SoftwareSerial gsmSerial(2, 3); // RX, TX pins for GSM module

// 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);

// Initialize OLED display


display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.setTextColor(WHITE);

// Initialize BMP280 sensor


if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}

// Configure pin modes


pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);

// Turn off LEDs and buzzer


digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, LOW);
digitalWrite(buzzerPin, LOW);
}
Certainly! Here's Part 2 of the code for your storm surge detector:

```cpp
void loop() {
// Read water level from ultrasonic sensor
float waterLevel = getWaterLevel();

// Read atmospheric pressure from BMP280 sensor


float pressure = bmp.readPressure() / 100.0; // Convert Pa to hPa

// Display sensor readings on OLED display


display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(1);
display.println("Water Level: ");
display.print(waterLevel);
display.println(" cm");
display.setTextSize(1);
display.setCursor(0, 20);
display.println("Pressure: ");
display.print(pressure);
display.println(" hPa");
display.display();

// Check for storm surge conditions


if (waterLevel > waterLevelThreshold && pressure < pressureThreshold) {
digitalWrite(redLedPin, HIGH); // Turn on the red LED
digitalWrite(greenLedPin, LOW); // Turn off the green LED
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer

// Send SMS alert


sendSMSAlert();
} else {
digitalWrite(redLedPin, LOW); // Turn off the red LED
digitalWrite(greenLedPin, HIGH); // Turn on the green LED
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
}

delay(500); // Delay for stability


}

float getWaterLevel() {
// Send ultrasonic pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Measure the echo duration


unsigned long echoDuration = pulseIn(echoPin, HIGH);

// Calculate distance in centimeters


float distance = echoDuration * 0.034 / 2;

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.

Step 1: Gather the Components


Collect all the necessary components mentioned earlier:
- Arduino Nano
- JSN-SR-40T waterproof ultrasonic sensor
- BMP280 atmospheric pressure sensor
- OLED display (0.96-inch with SPI interface)
- GSM module SIM800L
- GSM internal circuit board antenna
- Waterproof connectors
- Piezobuzzer
- LEDs
- Resistors
- Breadboard
- Jumper wires
- SIM card (compatible with GSM module)
Step 2: Connect the Ultrasonic Sensor
1. Connect the VCC pin of the JSN-SR-40T sensor to the 5V pin of the Arduino Nano.
2. Connect the GND pin of the JSN-SR-40T sensor to the GND pin of the Arduino Nano.
3. Connect the Trig pin of the JSN-SR-40T sensor to a digital pin (e.g., Pin 7) on
the Arduino Nano.
4. Connect the Echo pin of the JSN-SR-40T sensor to a digital pin (e.g., Pin 6) on
the Arduino Nano.

Step 3: Connect the Atmospheric Pressure Sensor


1. Connect the VCC pin of the BMP280 sensor to the 3.3V pin of the Arduino Nano.
2. Connect the GND pin of the BMP280 sensor to the GND pin of the Arduino Nano.
3. Connect the SDA pin of the BMP280 sensor to the SDA pin (A4) of the Arduino
Nano.
4. Connect the SCL pin of the BMP280 sensor to the SCL pin (A5) of the Arduino
Nano.

Step 4: Connect the OLED Display


1. Connect the VCC pin of the OLED display to the 3.3V pin of the Arduino Nano.
2. Connect the GND pin of the OLED display to the GND pin of the Arduino Nano.
3. Connect the SCK pin of the OLED display to the SCK pin (13) of the Arduino Nano.
4. Connect the MOSI pin of the OLED display to the MOSI pin (11) of the Arduino
Nano.
5. Connect the DC (Data/Command) pin of the OLED display to a digital pin (e.g.,
Pin 9) on the Arduino Nano.
6. Connect the CS (Chip Select) pin of the OLED display to a digital pin (e.g., Pin
10) on the Arduino Nano.
7. Connect the RST (Reset) pin of the OLED display to a digital pin (e.g., Pin 8)
on the Arduino Nano.

Step 5: Connect the GSM Module


1. Connect the VCC pin of the GSM module to the 5V pin of the Arduino Nano.
2. Connect the GND pin of the GSM module to the GND pin of the Arduino Nano.
3. Connect the TX pin of the GSM module to the RX pin (D0) of the Arduino Nano.
4. Connect the RX pin of the GSM module to the TX pin (D1) of the Arduino Nano.

Step 6: Connect the Piezobuzzer and LEDs


1. Connect the positive terminal of the Piezobuzzer to a digital pin (e.g., Pin 2)
of the Arduino Nano.
2. Connect the negative terminal of the Piezobuzzer to the GND pin of the Arduino
Nano.
3. Connect the anode (longer leg) of each LED to a current-limiting resistor (e.g.,
220 ohms).
4. Connect the other end of the resistors to different digital pins on the Arduino
Nano.
5. Connect the cathode (shorter leg) of each LED to the GND pin of the Arduino
Nano.

Step 7: Insert the SIM Card


Insert the compatible SIM card into the SIM card slot of the GSM module.

Step 8: Power the Circuit


Connect the Arduino Nano to a power source, such as a USB cable or a battery, to
power the circuit.

Step 9: Upload the Code


Now, you need to upload the code to the Arduino Nano. The code will include the
necessary libraries and define the logic for reading sensor data, displaying
information on the OLED, and triggering alerts via the buzzer, LEDs, and SMS.
Please note that the code for the storm surge detector is quite extensive and
exceeds the character limit for a single response. Therefore, I will provide the
code in multiple responses. Please follow up with "Continue" after each code
snippet, and I will provide the next part of the code.

You might also like