{"id":28475168,"url":"https://github.com/devbd1/pid_controlled_liquid_transfer","last_synced_at":"2026-04-28T17:31:41.569Z","repository":{"id":296397277,"uuid":"993234311","full_name":"DevBD1/PID_Controlled_Liquid_Transfer","owner":"DevBD1","description":"A PID controlled liquid transfer system. Built with an Arduino Uno, an HC-SR04, a 12V pump and an L298N H bridge for PWM control; using Octave (MATLAB .m program).","archived":false,"fork":false,"pushed_at":"2025-06-04T14:03:32.000Z","size":5478,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-30T14:43:30.816Z","etag":null,"topics":["arduino","arduino-uno","matlab","matlab-gui","matlab-script","octave","octave-gui","octave-scripts"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevBD1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-30T12:49:57.000Z","updated_at":"2025-06-04T14:03:34.000Z","dependencies_parsed_at":"2025-05-30T17:54:39.436Z","dependency_job_id":"5be81dde-f1f3-43d2-a7ed-3ece928bab66","html_url":"https://github.com/DevBD1/PID_Controlled_Liquid_Transfer","commit_stats":null,"previous_names":["devbd1/pid_controlled_liquid_transfer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DevBD1/PID_Controlled_Liquid_Transfer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevBD1%2FPID_Controlled_Liquid_Transfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevBD1%2FPID_Controlled_Liquid_Transfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevBD1%2FPID_Controlled_Liquid_Transfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevBD1%2FPID_Controlled_Liquid_Transfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevBD1","download_url":"https://codeload.github.com/DevBD1/PID_Controlled_Liquid_Transfer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevBD1%2FPID_Controlled_Liquid_Transfer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32392289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-uno","matlab","matlab-gui","matlab-script","octave","octave-gui","octave-scripts"],"created_at":"2025-06-07T14:05:35.347Z","updated_at":"2026-04-28T17:31:41.564Z","avatar_url":"https://github.com/DevBD1.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"YouTube Video: https://www.youtube.com/watch?v=1OjPXJKbuPw\n\n# Introduction\n\nThis project involves **two liquid-filled reservoirs**, labeled **A and B**. Reservoir A serves as a supply tank, and its liquid level is not critical. Reservoir B, however, requires a stable liquid level, which is the primary control objective. An ultrasonic distance sensor is mounted vertically above Reservoir B to measure the liquid depth, providing distance readings denoted as x₁. A **peristaltic liquid pump** connects the two reservoirs. The pump's role is to transfer excess liquid from Reservoir B to Reservoir A or to draw liquid from Reservoir A to replenish Reservoir B, depending on the measured liquid level.\n\n# 📐 PID Control\nTo maintain the desired liquid level in Reservoir B, a PID (Proportional-Integral-Derivative) control algorithm is implemented. The controller minimizes the error between the setpoint and the measured value by adjusting the pump's operation. \nThe PID control law is defined as:\n\n```\nu(t) = Kp * e(t) + Ki * ∫e(t)dt + Kd * de(t)/dt\n```\n\n**Where:**\n- ```e(t)``` is the error between the measured and target level (e.g., e(t) = x₁ - target)\n- ```Kp``` is the proportional gain\n- ```Ki``` is the integral gain\n- ```Kd``` is the derivative gain\n- ```u(t)``` is the output used to determine the pump’s direction and speed (via PWM)\n\nThis PID controller ensures that the liquid level in Reservoir B remains stable despite disturbances or changes in system dynamics.\n\n---\n# ✅ Requirements\n\n#### Software\n- [GNU Octave](https://www.gnu.org/software/octave/) (Tested on version 10 (2025-03-25))\n- [Arduino IDE](https://www.arduino.cc/en/software) (Tested on version 1.8.19 (Store 1.8.57.0))\n- USB connection to Arduino board (Uno, Nano, etc.)\n- `instrument-control` package for Octave\n\n#### Hardware\n- Arduino Uno\n- HC-SR04:  Ultrasonic Sound Sensor\n- L298N: H BRIDGE\n- 12V 3x5 PUM: Peristaltic Water Pump\n- 12V ADAPTER: Power Supply for the Pump\n- 9V BATTERY: Power Supply for Arduino\n\n#### Connection Map\nHere is the connection map of the system:\n\nCOMPONENT | DESCRIPTION | COMPONENT PIN | CARD PIN | CARD\n--- | --- | --- | --- | ---\nHC-SR04 | Ultrasonic Sound Sensor | TRIG | D6 | UNO\nHC-SR04 | Ultrasonic Sound Sensor | ECHO | D7 | UNO\nL298N | H BRIDGE | IN1 | D8 | UNO\nL298N | H BRIDGE | IN2 | D9 | UNO\nL298N | H BRIDGE | ENA | D10 (PWM) | UNO\n12V ADAPTER | POWER SUPPLY | + / - | L298N\n12V 3x5 PUMP | Peristaltic Water Pump | + | OUT1 | L298N\n12V 3x5 PUMP | Peristaltic Water Pump | - | OUT2 | L298N\n\n---\n# 🛠️ Installation \nFollow the steps below to set up the environment for PID-controlled liquid transfer.\n\n### 📦 Octave Setup\n\n1. Install the `instrument-control` package:\n\n   ```octave\n   pkg install -forge instrument-control\n   pkg load instrument-control\n   ```\n\n2. Clone this repository or download the source code:\n\n   ```bash\n   git clone https://github.com/DevBD1/PID_Controlled_Liquid_Transfer.git\n   cd PID_Controlled_Liquid_Transfer\n   ```\n\n3. (Optional) If you have `.env` or calibration constants, place them in the root folder.\n\n4. Make sure your Arduino is connected via `COM3` or change the port in the script:\n\n   ```matlab\n   s = serialport(\"COM3\", 9600);\n   ```\n\n### 🔌 Arduino Upload\n\n1. Open [`arduino/transfer_serial.ino`](https://github.com/DevBD1/PID_Controlled_Liquid_Transfer/blob/main/arduino/transfer_serial.ino) in Arduino IDE.\n2. Select your correct board and COM port.\n3. Upload the sketch.\n\n### 🧪 First Start\nTo test the system and determine the standard deviation of sensor inputs:\n1. Run [`matlab/standard_deviation/log_realistic.m`](https://github.com/DevBD1/PID_Controlled_Liquid_Transfer/blob/main/matlab/standard_deviation/log_realistic.m) script\n2. Input the direction of the pump for test\n3. Input the repeat count\n4. Check the generated .csv file \n5. Run [`matlab/standard_deviation/analyse.m`](https://github.com/DevBD1/PID_Controlled_Liquid_Transfer/blob/main/matlab/standard_deviation/analyse.m) script\n6. Read the output, the script will generate a variable at the end\n7. Check the generated `pid_tolerance.mat` file\n\nTo start full PID control:\n1. Run  [`matlab/pid_control_serialport_mapped.m`](https://github.com/DevBD1/PID_Controlled_Liquid_Transfer/blob/main/matlab/pid_control_serialport_mapped.m) script\n\n```octave\npid_control_serialport_mapped.m\n```\n\n---\n\n# ⚙️ Configuration\nYou can modify the PID constants and port settings at the top of the `.m` files:\n\n```matlab\nKp = 40;\nKi = 0.5;\nKd = 20;\n\ns = serialport(\"COM3\", 9600);  % Change if needed\n```\n\nUse log_static.m when the reservoir B is empty. The result is your max. height.\n\n# 🧪 Other Scripts\n\n- ```Fill or Empty``` -\u003e dir: [.../matlab/fill_or_empty.m](https://github.com/DevBD1/PID_Controlled_Liquid_Transfer/blob/main/matlab/fill_or_empty.m)\n- ```Stop``` -\u003e dir: [.../matlab/stop.m](https://github.com/DevBD1/PID_Controlled_Liquid_Transfer/blob/main/matlab/stop.m)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevbd1%2Fpid_controlled_liquid_transfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevbd1%2Fpid_controlled_liquid_transfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevbd1%2Fpid_controlled_liquid_transfer/lists"}