Siwachanat Saengsuwan
Created June 4, 2023

On street illegal parking detection and warning using AI cam

Detect and warning On street illegal Parking in school area using DFRobot Huskylens AI Camera

184

Things used in this project

Hardware components

Hackster EEDU Kit - Getting Started with AI
DFRobot Hackster EEDU Kit - Getting Started with AI
Every component in this kit is needed for this project
×1
FireBeetle ESP32-E IoT Microcontroller with Header (Supports Wi-Fi & Bluetooth)
DFRobot FireBeetle ESP32-E IoT Microcontroller with Header (Supports Wi-Fi & Bluetooth)
×1
LED, Super Bright
LED, Super Bright
×80

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud
Arduino Web Editor
Arduino Web Editor
Fusion
Autodesk Fusion

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

warning light schematic

Resistor value 300 Ohm and super bright leds.

PCB Light warning

Pcb gerber file.

Code

Warning light code

C/C++
Edit with Arduino IOT cloud
#include <DFRobot_DF1201S.h>

/*
  Sketch generated by the Arduino IoT Cloud Thing 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int activeCount;
  bool commandStat;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <HardwareSerial.h>

#define RelayLight 17
DFRobot_DF1201S DF1201S;
HardwareSerial DF1201SSerial(1);

bool warningActive = false;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(115200);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);
  DF1201SSerial.begin ( 115200, SERIAL_8N1, 3, 1 );
  
  //DF1201SSerial.begin(115200);
  while(!DF1201S.begin(DF1201SSerial)){
    Serial.println("Init failed, please check the wire connection!");
    delay(1000);
  }
  /*Set volume to 20*/
  DF1201S.setVol(/*VOL = */20);
  Serial.print("VOL:");
  /*Get volume*/
  Serial.println(DF1201S.getVol());
  /*Enter music mode*/
  DF1201S.switchFunction(DF1201S.MUSIC);
  /*Wait for the end of the prompt tone */
  delay(2000);
  /*Set playback mode to "repeat all"*/
  DF1201S.setPlayMode(DF1201S.ALLCYCLE);
  Serial.print("PlayMode:");
  /*Get playback mode*/
  Serial.println(DF1201S.getPlayMode());
  

  
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();


  pinMode(RelayLight, OUTPUT);
  pinMode(0, INPUT);
  digitalWrite(0, LOW);

}

void loop() {
  ArduinoCloud.update();
  // Your code here
  if (commandStat == true) {
    digitalWrite(RelayLight, HIGH);
    if(warningActive==false){
      DF1201S.start();
      warningActive = true;
      delay(3000);      
    }
    
    
  } else {
    digitalWrite(RelayLight, LOW);
    if(warningActive==true){
      DF1201S.pause();
      warningActive = false;    
    }    
    
    
  }

}


/*
  Since CommandStat is READ_WRITE variable, onCommandStatChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onCommandStatChange()  {
  // Add your code here to act upon CommandStat change

}

/*
  Since ActiveCount is READ_WRITE variable, onActiveCountChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onActiveCountChange()  {
  // Add your code here to act upon ActiveCount change
}

smart AI Huskylens pole code

C/C++
edit with Arduino IOT cloud
/* 
  Sketch generated by the Arduino IoT Cloud Thing 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int alarmNumber;
  bool commandStat;
  bool detecStatus;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include "HUSKYLENS.h"

HUSKYLENS huskylens;
//HUSKYLENS green line >> SDA; blue line >> SCL
void printResult(HUSKYLENSResult result);
int CARID = 2; 
int timePresent = 0;
int carPresent =0,carUnpresent=0;
void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(115200);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
    Wire.begin(21,22);
      while (!huskylens.begin(Wire))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }
  
  
      // Uncomment one of the following code to switch the algorithm on HUSKYLENS:
    // huskylens.writeAlgorithm(ALGORITHM_FACE_RECOGNITION);
    // huskylens.writeAlgorithm(ALGORITHM_OBJECT_TRACKING);
     huskylens.writeAlgorithm(ALGORITHM_OBJECT_RECOGNITION);
    // huskylens.writeAlgorithm(ALGORITHM_LINE_TRACKING);
    // huskylens.writeAlgorithm(ALGORITHM_COLOR_RECOGNITION);
    // huskylens.writeAlgorithm(ALGORITHM_TAG_RECOGNITION);
  
}

void loop() {
  
  ArduinoCloud.update();
  // Your code here 
  if (huskylens.requestBlocks(CARID)) {
        
        
        //Serial.println(String()+F("Get all blocks. Count:")+huskylens.countBlocks());
        
        if(huskylens.countBlocks() > 0 ){
            HUSKYLENSResult result = huskylens.getBlock(0);
            printResult(result);          
            carPresent++;
            carUnpresent=0;
            if (carPresent > 5){
                detecStatus=true;
                commandStat=true;
            }
            
        }else{
            Serial.print(".");
            carUnpresent++;
            carPresent=0;
            if (carUnpresent > 5){
                detecStatus=false;
                commandStat=false;
            }            
        }
        
        
        //for (int i = 0; i < huskylens.countBlocks(); i++)
        //{
        //    HUSKYLENSResult result = huskylens.getBlock(i);
        //    printResult(result);
        //}
        delay(100);
        
  }
}

void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK){//result is a block
        Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID);
    }
    else if (result.command == COMMAND_RETURN_ARROW){//result is an arrow
        Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID);
    }
    else{//result is unknown.
        Serial.println("Object unknown!");
    }
}

/*
  Since CommandStat is READ_WRITE variable, onCommandStatChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onCommandStatChange()  {
  // Add your code here to act upon CommandStat change
}

/*
  Since DetecStatus is READ_WRITE variable, onDetecStatusChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onDetecStatusChange()  {
  // Add your code here to act upon DetecStatus change
}

/*
  Since AlarmNumber is READ_WRITE variable, onAlarmNumberChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onAlarmNumberChange()  {
  // Add your code here to act upon AlarmNumber change
}

Credits

Siwachanat Saengsuwan

Siwachanat Saengsuwan

3 projects • 0 followers

Comments