micro controller - n1lby73/industrial-IOT GitHub Wiki


The ESP32 Motor Control System is a microcontroller-based project designed to control a three-phase induction motor using an ESP32 development board. The system allows both physical manipulation of the motor's state via push buttons and remote control through a Flask server using HTTP requests. The system also includes emergency handling functionality to ensure safe operation.

Hardware requirements and connection

Components needed

Name Qty
Esp32 1
Buzzer 1
led 2
jumper wire *
Push button 3
2.2k resistor 3
Breadboard 1
solid state relay 3

GPIO Definition

Esp32 digital pin Custom name Usage
pin 26 stato Three phase induction motor connected via solid state relay
pin 22 emergency Sends the micro-controller to emergency mode
pin 23 R-emergency Breaks the micro-controller out of the emergency state
pin 14 alarm To alert nearby technician of the emergency state
pin 27 motorpb Start and stop the motor physically via push button

Software and Configurable

Server endpoint

Endpoints Method Function Name Usage
*/api/synchardchanges PUT syncHardChanges() Synchronizes local on and off event triggered by the motorpb gpio pin to the flask server
*/api/emergency PUT syncEmergency() Reports the current emergency state to the flask server
*/api/query POST void loop() Constantly retrives the state of the electic motor [stato] from the server

Variable documentation

Global Variables

  • dt_out**:** Delay timer out. Specifies the delay time at the end of the void loop() function.

  • minDt**:** Minimum timer. Specifies the minimum delay time.

  • wifiDt**:** Delay timer for Wi-Fi connection attempts.

  • motor**:** Pin connected to the three-phase induction motor.

  • motorPb**:** Pin connected to the three-phase induction motor push button.

  • emergency**:** Flag indicating the emergency state of the system.

  • emergencybtn**:** Pin connected to the emergency push button.

  • resetEmergencybtn**:** Pin connected to the reset emergency push button.

  • emergencyLed**:** Pin connected to the emergency LED.

  • pbStateOld**:** Previous state of the motor control push button.

  • pbStateNew**:** Current state of the motor control push button.

  • localMotorState**:** Local state of the motor

    Note: In other to synchronize the state of the motor indepndently like a 2 way switching mechanism commonly found in staircase, the below value was given to help keep track of that synchronization

    Value Platform State
    0 Phsyical push button OFF
    1 Phsyical push button ON
    3 Remote button OFF
    2 Remote button ON
  • motorState****:**** State of the motor retrieved from the server.

Wi-Fi Configuration

  • ssid**:** SSID of the Wi-Fi network.
  • password**:** Password of the Wi-Fi network.

Server Configuration

  • serverID**:** Address of the Flask server.

    Note: serverID is obsolete cause at the time of documentation, project was been carried out on HTTP protocol

  • serverIP**:** IP address of the Flask server running locally.

  • serverPort**:** Port number of the Flask server.

Detailed micro-controller function documentation

hardChanges()**:** This function monitors changes in the physical state of the motor control push button (motorPb). It detects when the button is pressed or released and updates the local motor state accordingly.

syncHardChanges()**:** This function sends the local motor state to the server to synchronize it with the remote state. It uses HTTP PUT requests to update the server with the current motor state.

syncEmergency(int emergencyValue)**:** This function reports the current emergency state to the server. It takes an integer parameter (emergencyValue) indicating whether the emergency mode is activated or deactivated with the use of 1 denoting ON and 0 denoting OFF.

setupEmergency()**:** This function handles the activation and deactivation of the emergency mode. It triggers emergency mode when the emergency button (emergencybtn) is pressed and resets it when the reset emergency button (resetEmergencybtn) is pressed.

internetAccess()**:** This function checks for internet connectivity by pinging a known IP address (Google). If the internet is not accessible, it handles the reconnection process if the connected wifi get's out of range or is turned off.

setup()**:** The setup function initializes the GPIO pins, establishes a Wi-Fi connection, and ensures internet access before starting the main loop.

loop()**:** The loop function continuously monitors the state of the emergency button and the motor control push button. It retrieves the motor state from the server, synchronizes it with the local state, and controls the motor accordingly. In case of an emergency, it triggers emergency mode and waits for the reset signal.