লঞ্চ নিরাপত্তা মনিটর — ওজন, কাত আর পানির অ্যালার্মLoad Cell Arduino
দুইটা HC-SR04 gate যাত্রী গোনে, দুইটা HX711 load cell ডেকের বাম আর ডান পাশের ওজন মাপে। water level sensor পানি ঢুকছে কিনা দেখে। Arduino সব বিপদ যোগ করে ০ থেকে ১০০ স্কোর বানায়, আর একটা critical tilt-ও হিসাব করে — ভারী, একপাশে ভরা বা পানি ঢুকা নৌকা কম কাতেই ডুবে যায়, তাই সেন্সরগুলো ২৫ ডিগ্রি থেকে ওই লাইনটা টেনে নামায়। LCD তে মাপা কাতের পাশে "Tc" দেখায়। লাইন পার হলে বা স্কোর ৪৫ পার হলে buzzer আর লাল LED অ্যালার্ম দেয়, আর ESP-01 সব সংখ্যা server এ পাঠায়।
Two HC-SR04 gates count the passengers, two HX711 load cells weigh the left and right side of the deck, and a water level sensor detects flooding. The Arduino adds every risk into one score from 0 to 100, and it also calculates a critical tilt: a loaded, lopsided or leaking boat capsizes at a smaller angle, so the sensors pull that line down from 25 degrees — the LCD shows it as "Tc" next to the measured tilt. Past the line, or past 45 points, the buzzer and the red LED sound the alarm, and an ESP-01 posts the numbers to a monitoring server.
সার্কিট ডায়াগ্রাম · Circuit diagram
যা যা লাগবে · Parts you need
- 1 × Arduino Uno R3 Arduino Uno
- 1 × LCD 16x2 with I2C LCD ১৬x২ (I2C)
- 1 × Motion sensor MPU6050 (GY-521) মোশন সেন্সর MPU6050 (GY-521)
- 1 × Water level sensor পানির লেভেল সেন্সর
- 2 × Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) আল্ট্রাসনিক দূরত্ব সেন্সর (HC-SR04 / JSN-SR04T)
- 1 × Buzzer (5 V) Buzzer (বাঁশি, 5 V)
- 1 × LED (red) LED বাতি
- 1 × Resistor 220Ω Resistor
- 2 × Load cell + HX711 (weight) লোড সেল + HX711 (ওজন)
- 1 × GPS module (NEO-6M) GPS মডিউল (NEO-6M)
- 1 × Logic level converter (bi-directional) লজিক লেভেল কনভার্টার (দুই দিকে চলে)
- 1 × Wi-Fi module ESP-01 (ESP8266) Wi-Fi মডিউল ESP-01 (ESP8266)
- 1 × Breadboard Breadboard
- 1 × Breadboard power supply (3.3 V / 5 V) ব্রেডবোর্ড পাওয়ার সাপ্লাই — ৩.৩ V আর 5 V রেল
- 54 × Jumper wires জাম্পার তার
তার লাগানো · Wiring
| Load cell + HX711 (weight) VCC | → | Arduino Uno R3 5V |
| Load cell + HX711 (weight) GND | → | Arduino Uno R3 GND |
| Load cell + HX711 (weight) DT | → | Arduino Uno R3 D4 |
| Load cell + HX711 (weight) SCK | → | Arduino Uno R3 D5 |
| Load cell + HX711 (weight) VCC | → | Arduino Uno R3 5V |
| Load cell + HX711 (weight) GND | → | Arduino Uno R3 GND |
| Load cell + HX711 (weight) DT | → | Arduino Uno R3 D6 |
| Load cell + HX711 (weight) SCK | → | Arduino Uno R3 D7 |
| Motion sensor MPU6050 (GY-521) VCC | → | Arduino Uno R3 5V |
| Motion sensor MPU6050 (GY-521) GND | → | Arduino Uno R3 GND |
| Motion sensor MPU6050 (GY-521) SDA | → | Arduino Uno R3 A4 |
| Motion sensor MPU6050 (GY-521) SCL | → | Arduino Uno R3 A5 |
| LCD 16x2 with I2C VCC | → | Arduino Uno R3 5V |
| LCD 16x2 with I2C GND | → | Arduino Uno R3 GND |
| LCD 16x2 with I2C SDA | → | Arduino Uno R3 A4 |
| LCD 16x2 with I2C SCL | → | Arduino Uno R3 A5 |
| Water level sensor + | → | Arduino Uno R3 5V |
| Water level sensor - | → | Arduino Uno R3 GND |
| Water level sensor S | → | Arduino Uno R3 A0 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) VCC | → | Breadboard tp5 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) GND | → | Breadboard tn5 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) TRIG | → | Arduino Uno R3 D2 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) ECHO | → | Arduino Uno R3 D3 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) VCC | → | Breadboard tp7 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) GND | → | Breadboard tn7 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) TRIG | → | Arduino Uno R3 A1 |
| Ultrasonic distance sensor (HC-SR04 / JSN-SR04T) ECHO | → | Arduino Uno R3 A2 |
| GPS module (NEO-6M) VCC | → | Arduino Uno R3 5V |
| GPS module (NEO-6M) GND | → | Arduino Uno R3 GND |
| GPS module (NEO-6M) TX | → | Logic level converter (bi-directional) A1 |
| Logic level converter (bi-directional) B1 | → | Arduino Uno R3 D8 |
| Arduino Uno R3 D9 | → | Logic level converter (bi-directional) A2 |
| Logic level converter (bi-directional) B2 | → | GPS module (NEO-6M) RX |
| Wi-Fi module ESP-01 (ESP8266) VCC | → | Breadboard bp5 |
| Wi-Fi module ESP-01 (ESP8266) GND | → | Breadboard bn5 |
| Wi-Fi module ESP-01 (ESP8266) CH_PD | → | Breadboard bp7 |
| Wi-Fi module ESP-01 (ESP8266) TX | → | Logic level converter (bi-directional) A3 |
| Logic level converter (bi-directional) B3 | → | Arduino Uno R3 D10 |
| Arduino Uno R3 D11 | → | Logic level converter (bi-directional) A4 |
| Logic level converter (bi-directional) B4 | → | Wi-Fi module ESP-01 (ESP8266) RX |
| Logic level converter (bi-directional) LV | → | Arduino Uno R3 3V3 |
| Logic level converter (bi-directional) HV | → | Arduino Uno R3 5V |
| Logic level converter (bi-directional) GND | → | Arduino Uno R3 GND.2 |
| Breadboard power supply (3.3 V / 5 V) DC+ | → | Arduino Uno R3 5V |
| Breadboard power supply (3.3 V / 5 V) DC- | → | Arduino Uno R3 GND |
| Breadboard power supply (3.3 V / 5 V) V1 | → | Breadboard tp1 |
| Breadboard power supply (3.3 V / 5 V) GND | → | Breadboard tn1 |
| Breadboard power supply (3.3 V / 5 V) V2 | → | Breadboard bp1 |
| Breadboard tn1 | → | Breadboard bn1 |
| Buzzer (5 V) + | → | Arduino Uno R3 D12 |
| Buzzer (5 V) - | → | Arduino Uno R3 GND.3 |
| Arduino Uno R3 D13 | → | Resistor a |
| Resistor b | → | LED A |
| LED K | → | Arduino Uno R3 GND.3 |
Code (Arduino C++)
#include <Wire.h>
#include <HX711.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <EEPROM.h>
// LaunchGuard: passenger launch (ferry) safety monitor - the Tekko BD kit wired
// up exactly like this. Real launches sink or capsize for plain reasons: too
// many passengers, everybody crowded on one side, the hull tilted too far, or
// water coming in.
//
// TWO alarms, one per failure mode:
// 1. CAPSIZE - the critical tilt is NOT a fixed number. A loaded, lopsided,
// leaking or crowded boat capsizes at a smaller angle, so every sensor
// moves the line: start from 25 deg and take away
// load -8 deg once both decks carry their rated 2x4000 g, then -5 deg
// per extra 100% overload (2 x HX711)
// sway -6 deg at 100% left/right imbalance, growing past 30%
// flood -4 deg once the probe wets (600+), -7 deg at 800+ (probe on A0)
// crowd -2 deg per passenger over the limit, at most -6 (HC-SR04 gates)
// floored at 8 deg. The siren fires the moment the MPU6050 heel reaches
// that calculated line: an empty dry boat must heel the full 25 deg, a
// full wet crowded one is in danger at 14-17. The LCD shows the line as
// "Tc:" next to the measured "T:".
// 2. HAZARD SCORE (0-100, capped) for dangers that do not need a heel:
// tilt 10-19 deg +25, 20 deg or more +55 (MPU6050 on I2C A4/A5)
// water reading 600-799 +15, 800 or more +35 (probe on A0)
// a load point at 80% of its share or more +15, each side (2 x HX711)
// left/right imbalance 30% or more +15
// passengers over capacity +20 (2 x HC-SR04 gates, SRS 3.4)
// Score bands: 0-19 SAFE, 20-44 WARNING, 45-69 HIGH RISK, 70-100 CRITICAL.
// The buzzer and the red LED fire on CAPSIZE or a score of 45+; crossing the
// capsize line shows CRITICAL even when the score alone would not.
//
// Passenger gates (SRS 3.4): a gate counts a person after two consecutive reads
// inside its band (entry 2-15 cm, exit 30-50 cm), then re-arms after 3 clear
// reads with a 1.5 s cooldown, so one person is never counted twice. Count =
// entries - exits, never below zero. The real firmware keeps the count in
// EEPROM across power cuts; the simulator's EEPROM keeps it for one run.
//
// GPS (NEO-6M) shows the vessel's position on the Serial Monitor. A lost fix is
// INFORMATIONAL ONLY - it adds no risk points (SRS 8.3). The ESP-01 joins Wi-Fi
// and POSTs the sensor JSON to /api/sensor-data on the monitoring server.
// DEVICE_KEY below is a placeholder - the real server issues one per device.
//
// Power path of the real kit: a DC adapter feeds the breadboard power supply
// module, whose switch and jumpers make a 5 V and a 3.3 V rail on the
// breadboard; the ESP-01 takes its 3.3 V from that module and the Arduino runs
// from VIN or USB. In the simulator the module is fed 5 V from the board (the
// board's VIN pin is not modelled as a live input here), its 5 V rail powers
// the two passenger gates through the breadboard's power strips, and its
// 3.3 V rail feeds the ESP-01. The level converter joins the 3.3 V-side
// signals to the Uno's 5 V pins through its four A/B channels.
HX711 cellL, cellR;
Adafruit_MPU6050 mpu;
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial gpsSerial(8, 9); // RX D8 <- GPS TX | TX D9 -> GPS RX
SoftwareSerial espSerial(10, 11); // RX D10 <- ESP TX | TX D11 -> ESP RX
TinyGPSPlus gps;
const int WATER_PIN = A0;
const int BUZZ_PIN = 12;
const int LED_PIN = 13;
const int TRIG_IN = 2, ECHO_IN = 3; // entry gate (gangway)
const int TRIG_OUT = A1, ECHO_OUT = A2; // exit gate
const float LOAD_PER_SIDE = 4000.0; // rated load per side, grams (demo scale)
const int MAX_PASSENGERS = 5; // demo capacity - the real build reads the
// vessel's certified passenger limit here
const float BASE_TCRIT = 25.0; // capsize-grade heel (deg) for a light, dry,
// balanced deck - the other sensors pull it down
const float TCRIT_FLOOR = 8.0; // past this the hull is going over regardless
String WIFI_SSID = "TekkoNet";
String WIFI_PASS = "12345678"; // simulator network - any password joins
String DEVICE_KEY = "YOUR_DEVICE_KEY";
int entered = 0, exited = 0, pax = 0;
int inHits = 0, outHits = 0, inClear = 0, outClear = 0;
bool inArmed = true, outArmed = true, wifiUp = false;
unsigned long inCool = 0, outCool = 0, lastGps = 0, lastUp = 0;
int readGate(int trig, int echo) {
digitalWrite(trig, LOW); delayMicroseconds(2);
digitalWrite(trig, HIGH); delayMicroseconds(10);
digitalWrite(trig, LOW);
return pulseIn(echo, HIGH) / 58;
}
bool inBand(int cm, int lo, int hi) { return cm >= lo && cm <= hi; }
// collect ESP-01 AT replies until the needle shows up (or the ms budget runs out)
bool waitFor(String needle, unsigned long ms) {
unsigned long t0 = millis();
String buf = "";
while (millis() - t0 < ms) {
while (espSerial.available()) { char c = espSerial.read(); buf += c; }
if (buf.indexOf(needle) >= 0) return true;
delay(10);
}
return false;
}
// join Wi-Fi (done once in setup) and POST the sensor JSON to the server
void uploadToCloud(int score, float tilt, int water, float loadL, float loadR,
float tcrit, bool capsize) {
if (!wifiUp) return;
String json = "{\"device\":\"launchguard-01\",\"passengers\":" + String(pax);
json += ",\"score\":" + String(score) + ",\"tilt\":" + String(tilt, 0);
json += ",\"tcrit\":" + String(tcrit, 0) + ",\"capsize\":" + (capsize ? 1 : 0);
json += ",\"water\":" + String(water) + ",\"load_l\":" + String(loadL, 0);
json += ",\"load_r\":" + String(loadR, 0) + "}";
String req = "POST /api/sensor-data HTTP/1.1\r\nHost: cloud.tekko.sim\r\n";
req += "X-Device-Key: " + DEVICE_KEY + "\r\n";
req += "Content-Type: application/json\r\nContent-Length: " + String(json.length()) + "\r\nConnection: close\r\n\r\n";
req += json;
espSerial.println("AT+CIPMUX=0");
waitFor("OK", 500);
espSerial.println("AT+CIPSTART=\"TCP\",\"cloud.tekko.sim\",80");
if (!waitFor("CONNECT", 3000)) { Serial.println("Cloud: connect failed"); return; }
espSerial.print("AT+CIPSEND=");
espSerial.println(req.length());
if (!waitFor(">", 2000)) { Serial.println("Cloud: send refused"); return; }
espSerial.print(req);
if (waitFor("SEND OK", 3000)) {
Serial.print("POST /api/sensor-data sent ("); Serial.print(json.length()); Serial.println(" bytes)");
if (waitFor("+IPD", 4000)) Serial.println("Cloud reply received");
} else Serial.println("Cloud: send failed");
}
void setup() {
Serial.begin(9600);
pinMode(BUZZ_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(TRIG_IN, OUTPUT); pinMode(ECHO_IN, INPUT);
pinMode(TRIG_OUT, OUTPUT); pinMode(ECHO_OUT, INPUT);
cellL.begin(4, 5); // left deck: DOUT -> D4, SCK -> D5
cellR.begin(6, 7); // right deck: DOUT -> D6, SCK -> D7
cellL.set_scale(420); // calibration: counts per gram
cellR.set_scale(420);
cellL.tare(); // zero both decks while empty
cellR.tare();
if (!mpu.begin()) { Serial.println("MPU6050 not found"); while (1) delay(10); }
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
lcd.init();
lcd.backlight();
gpsSerial.begin(9600);
EEPROM.get(0, entered); // deck count survives a restart on real hardware
EEPROM.get(2, exited);
if (entered < 0 || entered > 500) entered = 0; // blank EEPROM reads as -1
if (exited < 0 || exited > 500) exited = 0;
espSerial.begin(115200); // ESP-01 AT firmware's factory baud
espSerial.println("AT");
if (waitFor("OK", 800)) Serial.println("ESP-01: ready");
espSerial.println("AT+CWMODE=1");
waitFor("OK", 800);
espSerial.println("AT+CWJAP=\"" + WIFI_SSID + "\",\"" + WIFI_PASS + "\"");
if (waitFor("WIFI GOT IP", 4500)) {
wifiUp = true;
Serial.println("WiFi: joined");
uploadToCloud(0, 0, 0, 0, 0, BASE_TCRIT, false); // boot heartbeat
} else Serial.println("WiFi: join failed (monitoring offline)");
}
void loop() {
int dIn = readGate(TRIG_IN, ECHO_IN);
int dOut = readGate(TRIG_OUT, ECHO_OUT);
// entry gate: 2 in-band reads confirm, 3 clear reads re-arm, 1.5 s cooldown
if (inBand(dIn, 2, 15)) { if (inHits < 2) inHits++; inClear = 0; }
else { inHits = 0; if (inClear < 3) inClear++; if (inClear >= 3) inArmed = true; }
if (inArmed && inHits >= 2 && millis() - inCool > 1500) {
entered++; inArmed = false; inHits = 0; inCool = millis();
EEPROM.put(0, entered);
pax = entered - exited; if (pax < 0) pax = 0;
Serial.print("In! Count: "); Serial.println(pax);
if (pax > MAX_PASSENGERS) { Serial.print("Over capacity! "); Serial.print(pax); Serial.println(" aboard"); }
}
// exit gate: the same machine with its own band and state
if (inBand(dOut, 30, 50)) { if (outHits < 2) outHits++; outClear = 0; }
else { outHits = 0; if (outClear < 3) outClear++; if (outClear >= 3) outArmed = true; }
if (outArmed && outHits >= 2 && millis() - outCool > 1500) {
exited++; outArmed = false; outHits = 0; outCool = millis();
EEPROM.put(2, exited);
pax = entered - exited; if (pax < 0) pax = 0;
Serial.print("Out! Count: "); Serial.println(pax);
}
// GPS: position only, never a risk input (SRS 8.3)
while (gpsSerial.available()) gps.encode(gpsSerial.read());
if (millis() - lastGps > 1500) {
lastGps = millis();
if (gps.location.isValid()) {
Serial.print("GPS fix: "); Serial.print(gps.location.lat(), 4);
Serial.print(" "); Serial.println(gps.location.lng(), 4);
} else Serial.println("GPS: waiting for fix");
}
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
float tilt = fabs(atan2(a.acceleration.x, a.acceleration.z) * 57.2958); // degrees
float loadL = cellL.get_units(1);
float loadR = cellR.get_units(1);
float total = loadL + loadR;
int water = analogRead(WATER_PIN);
int score = 0;
if (tilt >= 20) score += 55; else if (tilt >= 10) score += 25;
if (water >= 800) score += 35; else if (water >= 600) score += 15;
if (loadL >= LOAD_PER_SIDE * 0.8) score += 15;
if (loadR >= LOAD_PER_SIDE * 0.8) score += 15;
float imb = total > 0 ? fabs(loadL - loadR) / total * 100.0 : 0;
if (imb >= 30) score += 15;
if (pax > MAX_PASSENGERS) score += 20;
if (score > 100) score = 100;
// the critical tilt: 25 deg minus what every other sensor takes away
float loadFrac = total / (LOAD_PER_SIDE * 2.0);
float tcrit = BASE_TCRIT;
tcrit -= 8.0 * min(loadFrac, 1.0); // rated load aboard
tcrit -= 5.0 * max(loadFrac - 1.0, 0.0); // overload beyond it
if (imb >= 30) tcrit -= imb / 100.0 * 6.0; // crowded to one side
if (water >= 800) tcrit -= 7.0; else if (water >= 600) tcrit -= 4.0; // flooding
float paxOver = pax > MAX_PASSENGERS ? (pax - MAX_PASSENGERS) * 2.0 : 0.0;
tcrit -= min(paxOver, 6.0); // too many passengers
if (tcrit < TCRIT_FLOOR) tcrit = TCRIT_FLOOR;
if (tcrit > BASE_TCRIT) tcrit = BASE_TCRIT;
bool capsize = tilt >= tcrit;
String status = "SAFE";
if (score >= 70) status = "CRITICAL";
else if (score >= 45) status = "HIGH RISK";
else if (score >= 20) status = "WARNING";
if (capsize) status = "CRITICAL"; // past the line the boat itself set
String statusShort = "SAFE";
if (capsize || score >= 70) statusShort = "CRIT";
else if (score >= 45) statusShort = "HIGH";
else if (score >= 20) statusShort = "WARN";
bool alarm = capsize || score >= 45;
digitalWrite(BUZZ_PIN, alarm ? HIGH : LOW);
digitalWrite(LED_PIN, alarm ? HIGH : LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("P:"); lcd.print(pax);
lcd.print(" Sc:"); lcd.print(score);
lcd.print(" W:"); lcd.print(water);
lcd.setCursor(0, 1);
lcd.print(statusShort);
lcd.print(" T:"); lcd.print(tilt, 0);
lcd.print(" Tc:"); lcd.print(tcrit, 0);
lcd.print(" ");
Serial.print("Score: "); Serial.print(score);
Serial.print(" Tilt: "); Serial.print(tilt, 0);
Serial.print(" Tc: "); Serial.print(tcrit, 0);
Serial.print(" Water: "); Serial.print(water);
Serial.print(" Pax: "); Serial.print(pax);
Serial.print(" L: "); Serial.print(loadL, 0); Serial.print("g");
Serial.print(" R: "); Serial.print(loadR, 0); Serial.print("g");
Serial.print(" Imb: "); Serial.print(imb, 0); Serial.print("%");
Serial.print(" | Status: "); Serial.println(status);
if (capsize) {
Serial.print("CAPSIZE! Tilt "); Serial.print(tilt, 0);
Serial.print(" >= critical tilt "); Serial.println(tcrit, 0);
}
if (wifiUp && millis() - lastUp > 15000) { lastUp = millis(); uploadToCloud(score, tilt, water, loadL, loadR, tcrit, capsize); }
delay(120);
}