This project, RoboCop, is a real-time distance measurement system for enhancing safety at the workspace. It uses a Nano ESP32 microcontroller based on the Xtensa LX7 processor, HC-SR04 ultrasonic sensor for measuring distance based on the principle of echolocation, and the Modbus protocol to transmit distance readings over Wi-Fi. The system can be integrated with robotics applications and/or monitoring tools.
The system measures the distance of nearby objects using an ultrasonic sensor, calculates the value, and transmits it over a Wi-Fi network using Modbus TCP. Users can access this data using the Python client or any Modbus-compatible software.
- Wi-Fi: Connects to the
AirVandalRobotnetwork with the passwordxxxx. - Static IP Address: The ESP32 is assigned the static IP
129.xx.xx.xx. - Modbus Unsigned Holding Register:
- The measured distance is stored in the unsigned holding register at address 5.
- This value is scaled as an integer (distance in cm multiplied by 100).
-
Power on the Device:
- Connect the ESP32 to a power source using the USB Type C terminal.
- Wait for it to connect to the
AirVandalRobotWi-Fi network.
-
Clone the Repository:
-
git clone https://github.com/UofI-CDACS/RoboCop_Safety_Device.git
-
-
Install project requirements:
-
pip install -r requirements.txt
-
-
Move to Python_Client folder:
-
cd Python_Client/
-
-
Client.py
- Open the client_distance.py file
- Edit the Server_IP
-
Replace with the IP address being displayed in the LCD screen of the RoboCop device you want to read
- Example:
SERVER_IP = "192.102.98.2"
- Example:
-
Leave the port and holding register unchanged
SERVER_PORT = 502
REGISTER_ADDRESS = 5
-
-
Access the Data:
- Use the provided Python client (
Python_Client/client_distance.py) to read the distance value from the Modbus server:python client_distance.py
- Alternatively, use a Modbus-compatible application (e.g., ModScan, QModMaster, Modbus Poll, etc):
- IP Address:
129.xx.xx.xx - Port:
502 - Register:
5(holding register for the distance)- This Register stores 16 bit value of unsigned integers
- IP Address:
- Use the provided Python client (
-
View on LCD:
- The LCD displays the device’s static IP and the measured distance in real time.
-
Testing:
- Place objects in front of the ultrasonic sensor and observe distance changes on the LCD or Python client output.
-
Accurate Distance Measurement:
- Measures distances between 2 cm and 400 cm using an ultrasonic sensor.
-
Modbus TCP Support:
- Transmits real-time distance data over the network.
-
LCD Display:
- Displays the static IP and the measured distance.
-
Python Client:
- Reads and interprets the Modbus data.
-
3D Printable Enclosure:
- Protects the hardware with custom STL files.
- Arduino IDE
- Python 3.x
- Libraries:
pymodbus,rgb_lcd,WiFi,ModbusIP_ESP8266
- ESP32 microcontroller
- HC-SR04 ultrasonic sensor
- LCD display
- Wi-Fi network
Contains the Arduino code (robo.ino) to set up the ESP32 microcontroller, manage Wi-Fi and Modbus connectivity, and interface with the HC-SR04 ultrasonic sensor and LCD.
Contains the distance_reader.py script to fetch distance readings from the ESP32 Modbus server using the Python Modbus library (pymodbus).
Includes STL files for:
- Mounting the ultrasonic sensor.
- Housing the ESP32 and LCD.
Visual documentation:
block_diagram.png: High-level system workflow.wiring_diagram.png: Connection guide for Arduino, sensors, and peripherals.
Additional resources:
- Device datasheets (e.g., HC-SR04, ESP32).
- Project report.
- Connect Components:
- HC-SR04 Ultrasonic Sensor:
- TRIG pin → ESP32 D6
- ECHO pin → ESP32 D7
- LCD Screen:
- Connect via I2C (SDA and SCL pins).
- ESP32:
- Set up on a static IP for Modbus communication.
- HC-SR04 Ultrasonic Sensor:
- 3D Print Mounts:
- Use the STL files in the
3D_Modelsfolder to 3D print the sensor and ESP32 mounts.
- Use the STL files in the
-
Install the following libraries:
rgb_lcdfor LCD.ModbusIP_ESP8266for Modbus communication.WiFi.hfor ESP32 Wi-Fi management.
-
Upload the Arduino code from
Arduino/robo.inoto the ESP32. -
Ensure your Wi-Fi credentials and static IP configuration match your network setup:
const char* ssid = "SSID"; const char* password = "PASSWORD";