This is an old revision of the document!


Motion Detection System

* Student: Zoican Denis-Alexandru

Description

The goal of this project is to alert the system's owner when an object approaches the system. When this happens, a photograph of the object is taken, and the user can view the image from any network-connected device.

Hardware Design

Components

Hardware Schematics

Software Design

The project was developed on 2 different boards: 1. ESP32 board - the code was written using Arduino IDE, where I used the Arduino libraries 2. Raspberry Pi 4 - the code was written in Python, where I used OpenCV and Flask

1. ESP32 board The code is divided in functions for a better understanding of the logic. The following code demonstrates how the boards connect to WiFi in order to communicate with the Raspberry Pi 4. The board's mode will be set to WIFI_STA, the board being able to connect to an WIFI network. The authentication procedure begins with the use of the network's name and password. If the authentication process does not succeed after 20 seconds (WIFI_TIMEOUT), an error message will be shown. Otherwise, a success message will be shown beside the IP address.

void connectToWifi(){
  Serial.println("Connecting.. status: " + String(WiFi.status()));
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_NETWORK,WIFI_PASSWORD);

  unsigned long startAttemptTime = millis();

  while(WiFi.status() != WL_CONNECTED && millis()-startAttemptTime < WIFI_TIMEOUT){
    Serial.print(".");
    delay(100);
  }
  
    if(WiFi.status() != WL_CONNECTED){
    Serial.println("Failed to connect");
  } else {
    Serial.println("Connected");
    Serial.println(WiFi.localIP());
  }

The next function's role is to send a POST request to the raspberry pi board's upload_photo endpoint.

void makeRequest(){
  HTTPClient http;
  Serial.println("Making HTTP request...");

const char* payload = "";
  http.begin(API_URL);
  int httpCode = http.POST(payload);

  if (httpCode > 0) {
    String payload = http.getString();
    Serial.println("Response:");
    Serial.println(payload);
    } else {
    Serial.println("Error making HTTP request");
  }

   http.end();
}
iothings/proiecte/2022sric/motion-detection.1685666830.txt.gz · Last modified: 2023/06/02 03:47 by denis.zoican
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0