Jhonattan Moreno
Published

Early flash flood warn system

This idea aims to provide a solution to generate early warnings that allow timely reaction to disasters due to floods or avalanches.

IntermediateFull instructions provided230
Early flash flood warn system

Things used in this project

Hardware components

SenseCAP K1100 - The Sensor Prototype Kit with LoRa® and AI
Seeed Studio SenseCAP K1100 - The Sensor Prototype Kit with LoRa® and AI
×1

Software apps and online services

roboflow
Blynk
Blynk

Story

Read more

Code

WIO TERMINAR CODE

Arduino
this code counts the warning events from the vision AI module and transmit the data over BLINK platform
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "yourtemplateid"
#define BLYNK_DEVICE_NAME           "yourdevicename"
#define BLYNK_AUTH_TOKEN            "yourauthtoken"
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "your ssid";
char pass[] = "your password";

#include "Seeed_Arduino_GroveAI.h"
#include <Wire.h>
#include "TFT_eSPI.h"
#include <rpcWiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleWioTerminal.h>

TFT_eSPI tft;
GroveAI ai(Wire);

TFT_eSprite spr = TFT_eSprite(&tft); //initialize buffer
uint8_t state = 0;
uint8_t count = 0;
char buf[6];
char auth[] = BLYNK_AUTH_TOKEN;

//BlynkTimer timer;

void setup()
{
  //====================================================================================================
  //TFT
  tft.begin(); //start TFT LCD 
  tft.setRotation(3); //set screen rotation 
  //====================================================================================================
  Wire.begin();
  Serial.begin(115200);
  //====================================================================================================
  Serial.println("begin");
  if (ai.begin(ALGO_OBJECT_DETECTION, MODEL_EXT_INDEX_1)) // Object detection and pre-trained model 1
  {
    Serial.print("Version: ");
    Serial.println(ai.version());
    Serial.print("ID: ");
    Serial.println( ai.id());
    Serial.print("Algo: ");
    Serial.println( ai.algo());
    Serial.print("Model: ");
    Serial.println(ai.model());
    Serial.print("Confidence: ");
    Serial.println(ai.confidence());
    state = 1;
  }
  else
  {
    Serial.println("Algo begin failed.");
  }
  Blynk.begin(auth, ssid, pass);

}

void loop()
{
  tft.fillScreen(TFT_BLACK); //fill background 
  tft.setTextSize(2); //set text size 
  tft.setTextColor(TFT_YELLOW); //set text color 
  tft.drawString("Flood Warn System", 55, 10); //draw text string 
  tft.drawFastHLine(40, 35, 240, TFT_DARKGREY); //draw horizontal line
  tft.setTextColor(TFT_WHITE); 
  tft.drawString("- Warn Count: ", 20, 50);
  tft.drawString("- Warn Conf:  ", 20, 80);
  if (state == 1)
  {
    uint32_t tick = millis();
    if (ai.invoke()) // begin invoke
    {
      while (1) // wait for invoking finished
      {
        CMD_STATE_T ret = ai.state(); 
        if (ret == CMD_STATE_IDLE)
        {
          break;
        }
        delay(20);
      }

     uint8_t len = ai.get_result_len(); // receive how many people detect
     if(len)
     {
       int time1 = millis() - tick; 
       Serial.print("Time consuming: ");
       Serial.println(time1);
       Serial.print("Number of flood detections: ");
       Serial.println(len);
       tft.setTextColor(TFT_RED);
       tft.drawNumber(len, 180,50);
       object_detection_t data;       //get data
       for (int i = 0; i < len; i++)
       {
          Serial.println("result:detected");
          Serial.print("Detecting and calculating: ");
          Serial.println(i+1);
          ai.get_result(i, (uint8_t*)&data, sizeof(object_detection_t)); //get result
  
          Serial.print("confidence:");
          Serial.print(data.confidence);
          tft.setTextColor(TFT_RED);
          tft.drawNumber(data.confidence, 180,80);
          Serial.println();
          Blynk.virtualWrite(V5, data.confidence);
          Blynk.virtualWrite(V4, len);
        }
        if(data.confidence>50)
        {
          count++;
          tft.drawNumber(count, 280,220);
        }
        if(count>=5)
        {
          tft.setTextColor(TFT_CYAN);
          tft.drawString("Send ALARM...", 70, 160);
          Blynk.virtualWrite(V3, 1);
          delay(1000);
        }
     }
     else
     {
       count=0;
       Serial.println("No identification");
       tft.setTextColor(TFT_GREEN);
       tft.drawNumber(0, 180,50);
       tft.drawNumber(0, 180,80);
       tft.drawNumber(count, 280,220);
       Blynk.virtualWrite(V4, 0);
       Blynk.virtualWrite(V5, 0);
       Blynk.virtualWrite(V3, 0);
     }
    }
    else
    {
      delay(1000);
      Serial.println("Invoke Failed.");
      tft.setTextColor(TFT_CYAN); 
      tft.drawString("Inv. Fail!.", 60, 220);
    }
  }
  else
  {
    state == 0;
  }
  delay(500);
}

AI MODEL

training results

Credits

Jhonattan Moreno

Jhonattan Moreno

1 project • 2 followers
Electronic Engineer... with hacking soul!

Comments

Add projectSign up / Login